cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping: Many to One ?

Former Member
0 Kudos

Hey everyone!

I have a mapping task where I need to get all the values of a multiple occuring field in the source interface, then pass the values to a single field in the target interface.

eg. name >>>mapped to>>> names

SOURCE:

<Set>

<name>john</name>

</Set>

<Set>

<name>harry</name>

</Set>

<Set>

<name>mike</name>

</Set>

<Set>

<name>james</name>

</Set>

DESIRED RESULT:

<target>

<names>john harry mike james</names>

</target>

Do I need to create a queue UDF for this?

Kind regards,

Glenn

Accepted Solutions (1)

Accepted Solutions (1)

Shabarish_Nair
Active Contributor
0 Kudos

yes create a Queued UDF.

loop through the input queue and concat to a result string.

psedocode;

String resultstring = "";
for (int a; a< input.length(); a++)
{
resultstring = resultstring + input[a];
}

Former Member
0 Kudos

Hi Shabarish,

Thanks for your reply.

I'm getting a syntax error with your code. Could you be more precise?

regards,

Glenn

Shabarish_Nair
Active Contributor
0 Kudos

When you create the UDF make sure your input parameter is renamed to input (by default it is a of type string)

String resultstring = "";
for (int a; a< input.length(); a++)
{
resultstring = resultstring + input[a];
}
result.addValue(resultstring);

if you still get an error, please let me know what is the description of the same.

Former Member
0 Kudos

Hey Shabarish!

I'm getting the ff exception with your new code:

Source code has syntax error: /usr/sap/PID/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map95c6474006f411de92ea0003ba710785/source/com/sap/xi/tf/_DFS_CHNG_ERP_MM_.java:3629: cannot resolve symbol symbol : method length () location: class java.lang.String[] for (int a; a< input.length(); a++) ^ 1 error

Glenn

Former Member
0 Kudos

Hi Glenn,

Initialise a And define "input" as the parameter while creating the function(UDF).

Give the loop condition as,

for (int a=0; a< input.length(); a++)

..

..

Regrads,

Swetha.

Shabarish_Nair
Active Contributor
0 Kudos

my mistake. Try this

String resultstring = "";
for (int a; a< input.length; a++)
{
resultstring = resultstring + input[a];
}
result.addValue(resultstring);

change length() to length

Former Member
0 Kudos

Hi

Method should be length not length()

For string method ===> length()

For Array ====> length

bit java

srini

Former Member
0 Kudos

Thanks Swetha and Shabarish!

I initialized "a" then I removed "()" from the length.

It works!

Thanks!

Glenn

Answers (3)

Answers (3)

markangelo_dihiansan
Active Contributor
0 Kudos

Hi,

Alternatively, you may use this mapping:

Set --> removeContext --> UDF --> targetNode

UDF type is of Context, argument is input

StringBuffer e = new StringBuffer();String b = null;

for (int i=0;i<input.length;i++){e = e.append(input<i> + " ");}

b = e.toString();

result.addValue(b);

StringBuffer would use less memory, same with queue as compared to context.

Hope this helps,

Former Member
0 Kudos

Hi,

U need to change the context of "name" to its root node..then only it will give expected output.

Regards,

Manisha

Former Member
0 Kudos

Hi

you can use, concat function..if it is only as mentioned above

Regards

Vishnu