on 02-04-2009 11:33 AM
Team,
I have a problem with context change in a peculiar mapping requirement.
Scenario is IDOC --> XML
There's an idoc field MRKN1 which carries all shipment unit numbers seperated by spaces.
MRKN1 : 50325 50326 50329 50321 50215
This field should be mapped to target XML as below:
<Package> <identifier>50325</identifier>
</Package>
<Package> <identifier>50326</identifier>
</Package>
<Package> <identifier>50329</identifier>
</Package>
<Package> <identifier>50321</identifier>
</Package>
<Package> <identifier>50215</identifier>
</Package>
I created a USD StringTokenizer to extract the values from MRKN1 & to populate it in the identier field:
import java.lang.*;
public void StringTokenizer(String[] input,ResultList result,Container container){
String x[] = new String[input.length];
for(int j=0; j<input.length;j++) {
x = input[j].split(" ");
}
for(int i=1;i<x.length;i++) {
result.addValue(x<i>);
}
and mapped liked below:
MRKN1 --> StringTokeniser --> identifier
But the output xml looks like this:
<Package> <identifier>50325</identifier> <identifier>50326</identifier> <identifier>50329</identifier> <identifier>50321</identifier>
<identifier>50215</identifier>
</Package>
Please help me how to create new Package tag for every new identifier tag.
I already tried adding result.addContextChange() just by returning empty value to the above code & mapped it to Package node. But it throws error.
Any immediate help is appreciated.
Thanks in advance,
Shanthi
Hi,
Modify your udf with below code
public void StringTokenizer(String[] input,ResultList result,Container container){
String[] x = {};
for(int j=0; j<input.length; j++)
{
x = input[j].split(" ");
for(int i =0; i < x.length ; i++){
result.addValue(x<i>);
result.addContextChange();
}
}
}
Then map
MRKN1 --> StringTokenizer -> RemoveContexts -> Package
MRKN1 --> StringTokenizer -> identifier
Then you will get the required output.
Regards,
Sakthi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi all,
I had manage to create a new program which loops for every tokens and also used result.addContextChange() and it worked.
Note: If you want the parent+child item to appear n number of times, make sure your parent item is also mapped acccordingly.
Thanks for all your answers.
Regards,
Shanthi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The above logic works quite different. The complete XML looks like this
Given 3 items & 2 values in MRKN1
<GoodsItem..1>
.
.
<Packaging>
<marksNumber>503124</marksNumber>
<PackagesCollection>
<Package>
<identifier>50216</identifier>
</Package>
</PackagesCollection>
<packageType>PK</packageType>
</Packaging>
.
.
</GoodsItem..1>
<GoodsItem..2>
.
.
<Packaging>
<marksNumber>503124</marksNumber>
<PackagesCollection>
<Package>
<identifier>50215</identifier>
</Package>
</PackagesCollection>
<packageType>PK</packageType>
</Packaging>
.
.
</GoodsItem..2>
<GoodsItem..3>
.
.
<Packaging>
<marksNumber>503124</marksNumber>
<PackagesCollection/>
<packageType>PK</packageType>
</Packaging>
.
.
</GoodsItem..3>
But the customer requirement is quite different
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Mapping for Package...provided that occurrence of Package is unbounded
MRKN1 --> StringTokeniser --> Package
Mapping for identifier
MRKN1 --> StringTokeniser > SpliByValue(each value)->identifier
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Shanthi,
Ur UDF is right. Use the following in Graphical mapping.
MRKN1 --> StringTokeniser --> Split By Value(Each Value) --> identifier
Br,
Madan Agrawal
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vasani,
I did added result.addContextChange after result.addValue(x<i>), but it didnt work
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Shanthi,
You have done right
You just need to add this line after result.addValue(x) statement inside loop:
result.addContextChange();
Let me know if you require more help on this.
Thanks,
Divyesh Vasani
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.