cancel
Showing results for 
Search instead for 
Did you mean: 

Context change problem

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

former_member267355
Active Participant
0 Kudos

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

Answers (7)

Answers (7)

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

Mapping for Package...provided that occurrence of Package is unbounded

MRKN1 --> StringTokeniser --> Package

Mapping for identifier

MRKN1 --> StringTokeniser > SpliByValue(each value)->identifier

madanmohan_agrawal
Contributor
0 Kudos

Hi Shanthi,

Ur UDF is right. Use the following in Graphical mapping.

MRKN1 --> StringTokeniser --> Split By Value(Each Value) --> identifier

Br,

Madan Agrawal

Former Member
0 Kudos

Hi Vasani,

I did added result.addContextChange after result.addValue(x<i>), but it didnt work

Former Member
0 Kudos

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

markangelo_dihiansan
Active Contributor
0 Kudos

Hi,

This can be resolved by using XSLT mapping. My colleague had the same issue and he was able to solve it via XSLT. You can search on how to code XSLT in SDN.

XSLT Mapping

hope this helps,