on 02-16-2007 7:12 AM
Hi,
I would like to map an Element with maxOccurs=unbounded to an Element with maxOccurs=1. So, instead of making a new target node for each occurrence of the source node I want to merge all occuring source node values to only one target node and put semicolons between them.
Basically I want to create a target node with CSV from a re-occurring source node.
Is this possible in message mapping?
Solutions that work will be highly rewarded!
Thanks,
Mattias
Hi,
This is easily possible. You need to write a UDF.
Create a User defined function of type "queue".
input: a
String value = "";
for(int j=0; j<a.length - 1; j++){
value += a[j] + ",";
}
value += a[a.length - 1];
result.addValue(value);
This will do the required thing.
Regards,
P.Venkat
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Venkat,
I have problems with your code during activation:
Activation of the change list canceled Check result for Message Mapping WMS_Articles3_MM | urn:eldorado.ru:wms:Articles: Starting compilation Source code has syntax error: D:/usr/sap/EXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapb14cbc80bd9311dbbb9f0030053fd998/source/com/sap/xi/tf/_WMS_Articles3_MM_.java:84: cannot resolve symbol symbol : variable length location: class java.lang.String for(int j=0; j<a.length; a++){ ^ D:/usr/sap/EXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapb14cbc80bd9311dbbb9f0030053fd998/source/com/sap/xi/tf/_WMS_Articles3_MM_.java:84: operator ++ cannot be applied to java.lang.String for(int j=0; j<a.length; a++){ ^ D:/usr/sap/EXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapb14cbc80bd9311dbbb9f0030053fd998/source/com/sap/xi/tf/_WMS_Articles3_MM_.java:85: array required, but java.lang.String found value += a[j]; ^ D:/usr/sap/EXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapb14cbc80bd9311dbbb9f0030053fd998/source/com/sap/xi/tf/_WMS_Articles3_MM_.java:87: cannot resolve symbol symbol : variable result location: class com.sap.xi.tf._WMS_Articles3_MM_ result.addValue(value); ^ 4 errors
What could be wrong?
Thx,
Mattias
it seems that you have not correctly put in the code.
D:/usr/sap/EXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapb14cbc80bd9311dbbb9f0030053fd998/source/com/sap/xi/tf/_WMS_Articles3_MM_.java:84: operator ++ cannot be applied to java.lang.String for(int j=0; <b>j><a.length</b>; a++){ ^ D:/usr/sap/EXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapb14cbc80bd9311dbbb9f0030053fd998/source/com/sap/xi/tf/_WMS_Articles3_MM_.java:85: array required, but java.lang.String found <b>value += </b>a[j]; ^
Can you tell us which code you r currently using ??
Hi Mattias,
when creating the UDF, use option of Context.......then you will get argument as String a() ........see you have to use an input argument of string array.......
Instead of <i>result.addValue(value)</i>; write resultlist.addValue(value);
Then your query may be solved.
Thanks,
Rajeev Gupta
when u create the UDF just put this part of the code only
String comp_string = a[0];
for (int j = 1; i<=a.length; j++)
{
comp_string = cop_string.concat(",").concat(a[j]);
}
result.addValue(comp_string);
To learn more abt UDF's do go thru this link - http://help.sap.com/saphelp_nw04/helpdata/en/22/e127f28b572243b4324879c6bf05a0/content.htm
Yes you can. You will have to write a small UDF for the same.
use this sample code and it should help you get the results
public void generateCompleteString(String[] a,ResultList result,Container container){
String comp_string = a[0];
for (int j = 1; i<=a.length; j++)
{
comp_string = cop_string.concat(",").concat(a[j]);
}
result.addValue(comp_string);
}
Also note that make the context of the source node (input) for the UDF as the root node.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vijay,
I also had some problems with your code during activation:
Activation of the change list canceled Check result for Message Mapping WMS_Articles3_MM | urn:eldorado.ru:wms:Articles: Starting compilation Source code has syntax error: D:/usr/sap/EXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map514e3be0bd9511dbc8e00030053fd998/source/com/sap/xi/tf/_WMS_Articles3_MM_.java:61: illegal start of expression public void generateCompleteString(String[] a,ResultList result,Container container){ ^ D:/usr/sap/EXD/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map514e3be0bd9511dbc8e00030053fd998/source/com/sap/xi/tf/_WMS_Articles3_MM_.java:69: ';' expected ^ 2 errors
Am I missing something?
Thx,
Mattias
Hi ,
To create a UDF ->
Go to UDF tab and create a UDF( user defined function)
It will popup a window for filling the code . You will have to options to write a function . select the function is with context then add a variable a and paste the code and use this UDf in the mapping between source and target nodes.
Nanda
User | Count |
---|---|
95 | |
11 | |
11 | |
10 | |
9 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.