cancel
Showing results for 
Search instead for 
Did you mean: 

mapping question: n recordsets with m fields into one string

Former Member
0 Kudos

Hi,

My input message will look like

<customer>

<name>name</name>

</customer>

<row1>

<customer>name</customer>

<field11>111</field11>

<field12>122</field12>

</row1>

<row2>

<customer>name</customer>

<field21>211</field21>

<field22>222</field22>

</row2>

....

....

<rown>

<customer>name</customer>

<fieldn1>n11</fieldn1>

<fieldn2>n22</fieldn2>

</row1>

and i need an output like

<customer>

<name>name</name>

</customer>

<rowx>

<fieldx>111222211222.........n11n22</fieldx>

</rowx>

in short all fields from row1 to rowx need to be concatened in one big string.

What is the best way to do this?

Kr

Robert

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

have a UDF with input as two fields........change their context to root...........then in UDF in a for loop concat all these values to get the large string and output this UDF value to target field..............

Former Member
0 Kudos

Hi Rajeev,

I've tried to create the code for the UDF but so far i only worked some small UDF with single string as input

I suppose my UDF will have as execution type: all value of a queue

public void concatenate(String[] a, ResultList result, Container container) throws StreamTransformationException{

//what is my code?

}

So i need to know what the code is inside. Please provide some code or at least some good pointers as to how to create it.

THX

kr

Robert

Former Member
0 Kudos

Hi Robert,

Concat the field1 and field2 using standard concat function in graphical mapping.Change the context of the field1 and field2 to higher node.

mapp the target of concat to a UDF which will concat all the value in its context to a string and return that string.

UDF details :

Execution type="All values from a context"


public void myUDF(String var1[], ResultList result,Container container) throws StreamTransformationException
{
int i=0;
String resp="";
while(i<var1.length)
{
     resp=resp+var1<i>;
     i++;
}
result.addValue(resp);
}

map the output of the UDF to ur target field.

Hope it helps,

Anand

Former Member
0 Kudos

Hi Anand,

Thx. This works now.

Even though i used a for loop instead of a while.

KR

Robert

Former Member
0 Kudos

Hi,

One more addition:

My solution goes like this


field 1  \
             > concatenate  > remove context > UDF > output
field 2  /

Kr

Robert

Edited by: R. den Hoedt on Mar 9, 2011 2:02 PM

Answers (1)

Answers (1)

Former Member
0 Kudos

Surely Using UDF/ Java Mapping it is easy .

What version are u working on .

IF 7.1 , try Using Global Variable ( Graphical variable ) on receiver side.

Lets see if it worked.

try Like this

field11 -> Concat -> Graphical Variable

Graphical Variable ->

I am expecting every time value of field11 will be conactinated with previously store Graphical Variable .

Similarly for all other fields .

and in last Concate them all fields to One Output Final String.

Check this link . If you want to know the working of Graphical variable .

SAP PI 7.1 Mapping Enhancements Series: Graphical Variables.

/people/william.li/blog/2008/02/13/sap-pi-71-mapping-enhancements-series-using-graphical-variable

Regards

PS

Former Member
0 Kudos

Version is 7.11

Former Member
0 Kudos

Hi Prabhatxi,

Your suggestion was interesting to point me to the existence of the graphical variable.

However i didnt get that to work completely as it still didnt solve my N:1 problem.

And i didn't see clear examples of that either.

Thx anyway

Robert