on 11-14-2006 8:04 AM
Could I do this mapping? We have a complex remark field, it includes 2 or more data. And we want to separate it to several subelements. The subelements are separated by semicolon.
<b>Source:</b>
<header>
<order>A12345</order>
<customer>XXX</customer>
<remark>TESTA/1;TESTB/2;TESTC/3</remark>
</header>
<b>Target:</b>
<header>
<order>A12345</order>
<customer>XXX</customer>
<detail>
<field1>TESTA</field1>
<field2>1</field2>
</detail>
<detail>
<field1>TESTB</field1>
<field2>2</field2>
</detail>
<detail>
<field1>TESTC</field1>
<field2>3</field2>
</detail>
</header>
I try to study SplitByValue and useOneAsMany, but it seems not for it.
Hi,
This would actually be possible even without using a Global Variable.
Use an Advanced User Defined Function. Adavnced user Defined Functions can return Multiple values.
<u><b>UDF1:</b></u>
1.Takes renmark as input.
2.Does the split on the basis of ;
3. Splits each split of step 2 on the basis of /
4. Add the output of step 3 to the resultlist with a context change.
u]<b>UDF2:</b></u>
1.Takes renmark as input.
2.Does the split on the basis of ;
3. Splits each split of step 2 on the basis of /
4. Add the output of step 3 to the resultlist with a context change.
For Advanced UDF's,
http://help.sap.com/saphelp_nw04/helpdata/en/f8/2857cbc374da48993c8eb7d3c8c87a/content.htm
Regards,
Bhavesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I use result.addValue("XXX"); and I can add multi values now like this
<header>
<order>A12345</order>
<customer>XXX</customer>
<detail>TESTA<detail>
<detail>TESTB<detail>
<detail>TESTC<detail>
</header>
But I want some subelements, so, I try another test, this is my source code:
result.addValue("TESTA");
result.addValue("1");
result.addContextChange();
result.addValue("TESTB");
result.addValue("2");
result.addContextChange();
result.addValue("TESTC");
result.addValue("3");
The result is
<detail>
<field1>TESTA</field1>
<field2>TESTA</field2>
</detail>
<detail>
<field1>TESTB</field1>
<field2>TESTB</field2>
</detail>
<detail>
<field1>TESTC</field1>
<field2>TESTC</field2>
</detail>
I think the result is not correct, I checked the methods of ResultList objects, but I only found addValue(), addContextChange() and addSuppress()
http://help.sap.com/saphelp_nw04/helpdata/en/b1/83a09f668320419dbe00a741e0fe6a/content.htm
Hi Dennys,
You can tru this piece of code in your mapping...
You need 3 UDFs each for <detail>, <field1>,<field2>
<b>UDF1: For <detail></b>
String arr[] = a[0].split(";");
for (int i=0;i<arr.length;i++)
result.addValue(arr<i>);
<b>UDF2: For <field1></b>
String str = a[0];
String str1 = null;
String sarr1[] = str.split(";");
for (int i=0; i<sarr1.length;i++)
{
str1 = sarr1<i>;
String sarr2[] = str1.split("/");
for (int j=0; j<sarr2.length;j++){
result.addValue(sarr2[j]);
j++;
}
result.addContextChange();
}
<b>UDF2: For <field2></b>
String str = a[0];
String str1 = null;
String sarr1[] = str.split(";");
for (int i=0; i<sarr1.length;i++)
{
str1 = sarr1<i>;
String sarr2[] = str1.split("/");
for (int j=0; j<sarr2.length;j++){
j++;
result.addValue(sarr2[j]);
}
result.addContextChange();
}
All these functions requires one input <remark>
Regards,
Jai Shankar.
It works, I just modify some syntax and the 2nd loop is not necessary.
Great thanks.
// main
String arr[] = remark[0].split(";");
for (int i=0; i<arr.length; i++)
result.addValue(arr<i>);
// 1st field
String str = remark[0];
String str1 = null;
String sarr1[] = str.split(";");
for (int i=0; i<sarr1.length; i++)
{
str1 = sarr1<i>;
String sarr2[] = str1.split("/");
result.addValue(sarr2[0]);
result.addContextChange();
}
// 2nd field
String str = remark[0];
String str1 = null;
String sarr1[] = str.split(";");
for (int i=0; i<sarr1.length; i++)
{
str1 = sarr1<i>;
String sarr2[] = str1.split("/");
result.addValue(sarr2[1]);
result.addContextChange();
}
Hi,
Possible using UDF's.
You would need 2 UDF's + Global variables of Java Section to achieve this.
<u><b>Logic :</b></u>
Declare 2 Global variables in the Java section and inititliaze them to 1 in the Initlization section.
Now, write an UDF, that will read take REMARK as its input. Check the value if tghe Global variable and extract only that portion from the String and then increment the global variable by 1.
Regards,
Bhavesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dennys,
If the <remark> node ahs fixed length contents for each field say field1- length5 and field2 - length 1, then you can use the <b>substring</b> function to do this easily...
Regards,
Jai Shankar.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
> If the <remark> node ahs fixed length contents for
> each field say field1- length5 and field2 - length
> 1, then you can use the <b>substring</b> function to
> do this easily...
Sorry, not fixed length, they are separated by semicolon and slash.
And the item count is not fixed too, maybe 3 or 6 or 9 items.
I checked some documents for UDF, most of them generate "only one" target element,
how to generate a new subelement in UDF? Is there any sample ?
btw, should I write a UDF between source's <remark> and target's <detail> ?
Thanks all of you, I ever wrote Java before, but I never write UDF, I'll try it.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.