Skip to Content
avatar image
Former Member

Context change problem

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

8 Answers

  • Best Answer
    avatar image
    Former Member
    Feb 05, 2009 at 10:58 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 04, 2009 at 11:52 AM

    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

    Inserting a new line after each tag of an xml

    hope this helps,

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 04, 2009 at 11:55 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 04, 2009 at 12:00 PM

    Hi Vasani,

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

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 04, 2009 at 01:55 PM

    Hi Shanthi,

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

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

    Br,

    Madan Agrawal

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 04, 2009 at 02:28 PM

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

    MRKN1 --> StringTokeniser --> Package

    Mapping for identifier

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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 04, 2009 at 02:39 PM

    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 😔

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 04, 2009 at 09:53 AM

    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

    Add comment
    10|10000 characters needed characters exceeded