cancel
Showing results for 
Search instead for 
Did you mean: 

Input XML to CSV in Mapping

Former Member
0 Kudos

Hi,

I have a requirement to convert the below:

Source Message:

<Message>
<Segment> ..............................0..unbounded
<Field1>Value1</Field1>
<Field2>Value2</Field2>
.
.
<Field20>Value20</Field20>
</Segment>
<Segment> ..............................0..unbounded
<Field1>value1</Field1>
<Field2>value2</Field2>
.
.
<Field20>Value20</Field20>
</Segment>
</Message>

Target Message should be:

<TargetMsg>
<Node>Value1,Value2,Value3,.........,Value20
value1,value2,value3,........,value20</Node>
</TargetMsg

How to do this using only Message mapping?

Thank you,

Pankaj.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Pankaj,

As per your Requirement, you need to do content conversion on your receiver file adapter.

Check for the Receiver content conversion parameters from below link:

http://help.sap.com/saphelp_srm40/helpdata/en/d2/bab440c97f3716e10000000a155106/content.htm

Thanks,

justin_santhanam
Active Contributor
0 Kudos

Pankaj,

Do you need new line after each Value1 to Value 20?

raj.

Former Member
0 Kudos

Hi,

Yes, the client wants that after first instance of value1 to value20 the next should come on a new line.

Value1,Value2.....Value20

Value1,Value2.....Value20

Value1,Value2.....Value20

Value1,Value2.....Value20

Thank you,

Pankaj.

rajasekhar_reddy14
Active Contributor
0 Kudos

Hi Pankaj,

You want CSV file as a output?? if yes then do file content conversion in Receiver file adapter,it is very simple

specify record structure then add field separator , and end separator nl

Regards,

Raj

Former Member
0 Kudos

Hi,

I am not using FILE adapter.

Also after converting the format to CSV I have to perform some other functions on the message.

It is actually a CSV embedded inside a XML.

Source Structure:
<Message>
<Data>
<ID>IND123</ID>
<Segment> ..............................0..unbounded
<Field1>Value1</Field1>
<Field2>Value2</Field2>
.
<Field20>Value20</Field20>
</Segment>
</Data>
<Data>
<ID>IND321</ID>
<Segment> ..............................0..unbounded
<Field1>value1</Field1>
<Field2>value2</Field2>
.
<Field20>Value20</Field20>
</Segment>
</Data>
</Message>

Target Message should be:

<TargetMsg>
<Node>ID: IND123
Value1,Value2,Value3,.........,Value20
ID:IND321
value1,value2,value3,........,value20</Node>
</TargetMsg>

Thank you,

Pankaj.

Former Member
0 Kudos

Hi Pankaj,

I understand you would like to achieve the requirement in Message Mapping.

Yes, we can do it in Message Mapping.

Take the First field "Value1" concat with "," and then concat with Next field and so on.....

So, finally your uotput will be Value1,Value2,Value3..............

Hope this help you to fix the issue.

Thanks,

Former Member
0 Kudos

Hi,

It will be very difficult to manage using Standard Functions. You are saying that I concat 20 fields using Concat function. What if the field number increases (suppose 50)? Moreover how to have these details on a newline?

I think this can be achieved using UDF, but I am not sure what code is required.

Thank you,

Pankaj.

Former Member
0 Kudos

Hi Pankaj,

Yes, by doing the suggested the mapping looks big, but it is pretty simple to achieve it.

Even though the number of fields increases, you can add those fields at the end, I hope it would not be difficult to concat the fields.

Yes, this can be achieved by writing a UDF.

Thanks,

Former Member
0 Kudos

Hi,

Use this UDF:

Execution type: All values of a context

Var1, var2 type string

String a="";

String b="";

for(int i=0;i<var1.length;i++)

{

a = var1<i> +"," + var2<i> + "\n";

b= b+ a ;

}

int len1 = b.length();

String str= b.substring(0 , len1-1);

result.addValue(str);

Mapping will be:

Field1---RemoveContext

-


UDF------Node

Field2---RemoveContext

Note:This UDF is prepared only for 2 inputs(u can add remaining fileds and modify this according to ur req).

Thanks

Amit

Former Member
0 Kudos

Hi,

I will test the UDF logic and update the thread accordingly.

Thank you,

Pankaj.

Former Member
0 Kudos

Hi,

I think the requirement is better to be achieved using a JAVA mapping. I have taken the help of a JAVA developer and most probably we will develop a JAVA mapping for this.

Thank you,

Pankaj.