Skip to Content
avatar image
Former Member

XI IDoc complex mapping problem - help needed!

Hi all,

I am mapping WPUBON IDoc (sent as IDoc XML file) to WPUBON IDoc in R/3. However, I have a complex mapping requirement that I am trying to use the graphical tool for.

Source segment structure is such that we have:

E1WPB01 (header) has one or many E1WPB02 (items) and E1WPB05 (coupons).

E1WPB02 (items) have one or many E1WPB03 (item conditions).

So for each IDoc, we can have many items (E1WPB02), each item can have many conditions (E1WPB03) and each IDoc can have many coupons (E1WPB05).

For each E1WPB05 received, we need to take the value and divide it proportionately in order to add an extra E1WPB03 discount condition segment to each E1WPB02 item (we are a retailer and this will allow us to break down customer coupon discounts across each item in the basket). For example, if we have 2 E1WPB02 items with values $2 and $3 and the coupon is worth $1, item 1 needs a new E1WPB03 segment with a value of $0.40 and item 2 needs one with a value of $0.60.

This process needs to occur for each E1WPB05 segment (customers could have more than one coupon). No E1WPB05 segments are required in the target IDoc.

I have tried a few things but really am a bit stuck on where to start.... any ideas anyone?

Thankyou.

Stuart Richards

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • Best Answer
    avatar image
    Former Member
    Jul 10, 2006 at 10:21 PM

    Hi Stuart,

    for your problem you would need to change the mapping for node E1WPB03. In your case I suggest to add another user defined function copyContent (using Context as Cache and with 2 input parameters a and b):

     for (int i = 0; i < b.length; i++){
        for (int j = 0; j < a.length; j++) result.addValue(b[i ]);
        result.addContextChange();
     }

    Just remove the blank in b[i ] (I cannot print this since the system thinks I want to start writing in italics).

    Then change the mapping for node E1WPB03 as follows (the mapping becomes quite large, therefore I need to break it into separate pieces).

    a) The end portion of the mapping looks as follows:

                                               E1WPB03 -->
                  E1WPB05 -->                              addContent --> E1WPB03
                              copyContent --> createIf -->
    and --> removeContext --> 

    b) The first input for the function <b>and</b> looks as follows (checking for the negative sign in E1WPB02):

     VORZEICHEN -->
                    equalS --> 
    Constant[-] -->

    c) The second input for the function <b>and</b> looks as follows (checking for the existence of a segment E1WPB03 with KONDITION = PN10):

         KONDITION -->
                       equalS         -->
    Constant[PN10] -->                    ifWithoutElse -->
                       Constant[true] -->

    Regards,

    Claus

    Add comment
    10|10000 characters needed characters exceeded

  • Jul 03, 2006 at 02:13 PM

    Could you post the source xml and the requested target xml?

    Highlight the envloved values.

    Regards

    Stefan

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Stefan,

      Here's some sample source XML:

      <?xml version="1.0" encoding="UTF-8"?>

      <WPUBON01>

      <IDOC>

      <EDI_DC40>

      <TABNAM>EDI_DC40</TABNAM>

      <MANDT>104</MANDT>

      <DOCNUM/>

      <DOCREL>620</DOCREL>

      <DIRECT>2</DIRECT>

      <IDOCTYP>WPUBON01</IDOCTYP>

      <MESTYP>WPUBON</MESTYP>

      <MESCOD>ST6</MESCOD>

      <SNDPOR>WPUX</SNDPOR>

      <SNDPRT>KU</SNDPRT>

      <SNDPRN>0799</SNDPRN>

      <RCVPOR>SAPRD1</RCVPOR>

      <RCVPRT>KU</RCVPRT>

      <RCVPRN>0799</RCVPRN>

      <REFINT>00000000000016</REFINT>

      </EDI_DC40>

      <E1WPB01 SEGMENT="1">

      <POSKREIS>0001</POSKREIS>

      <KASSID>1</KASSID>

      <VORGDATUM>20060107</VORGDATUM>

      <VORGZEIT>134512</VORGZEIT>

      <BONNUMMER>120572</BONNUMMER>

      <KASSIERER>4400</KASSIERER>

      <CSHNAME> </CSHNAME>

      <BELEGWAERS>GBP</BELEGWAERS>

      <E1WPB02 SEGMENT="2">

      <VORGANGART/>

      <QUALARTNR>ARTN</QUALARTNR>

      <ARTNR>000005034394436881</ARTNR>

      <VORZEICHEN>-</VORZEICHEN>

      <MENGE>1</MENGE>

      <REFBONNR> </REFBONNR>

      <E1WPB03 SEGMENT="3">

      <VORZEICHEN/>

      <KONDITION>PN10</KONDITION>

      <KONDVALUE>10.00</KONDVALUE>

      <CONDID/>

      <QUALCONDID/>

      </E1WPB03>

      </E1WPB02>

      <E1WPB02 SEGMENT="5">

      <VORGANGART/>

      <QUALARTNR>ARTN</QUALARTNR>

      <ARTNR>000005034394471158</ARTNR>

      <VORZEICHEN>-</VORZEICHEN>

      <MENGE>1</MENGE>

      <REFBONNR> </REFBONNR>

      <E1WPB03 SEGMENT="6">

      <VORZEICHEN/>

      <KONDITION>PN10</KONDITION>

      <KONDVALUE>20.00</KONDVALUE>

      <CONDID/>

      <QUALCONDID/>

      </E1WPB03>

      </E1WPB02>

      <E1WPB02 SEGMENT="8">

      <VORGANGART/>

      <QUALARTNR>ARTN</QUALARTNR>

      <ARTNR>000005034394469131</ARTNR>

      <VORZEICHEN>-</VORZEICHEN>

      <MENGE>1</MENGE>

      <REFBONNR> </REFBONNR>

      <E1WPB03 SEGMENT="9">

      <VORZEICHEN/>

      <KONDITION>PN10</KONDITION>

      <KONDVALUE>30.00</KONDVALUE>

      <CONDID/>

      <QUALCONDID/>

      </E1WPB03>

      </E1WPB02>

      <E1WPB05 SEGMENT="11">

      <VORZEICHEN>+</VORZEICHEN>

      <RABATTART>PTCS</RABATTART>

      <RABVALUE>6.00</RABVALUE>

      </E1WPB05>

      <E1WPB06 SEGMENT="11">

      <VORZEICHEN>+</VORZEICHEN>

      <ZAHLART>PTCS</ZAHLART>

      <SUMME>10.00</SUMME>

      <KARTENNR/>

      <ZUONR>120572</ZUONR>

      </E1WPB06>

      </E1WPB01>

      </IDOC>

      </WPUBON01>

      So we have one coupon worth $6.00. We have 3 items in the basket worth $10, $20 and $30 respectively. The additional E1WPB03 for each will need to contain $1, $2 and $3 respectively to give:

      <?xml version="1.0" encoding="UTF-8"?>

      <WPUBON01>

      <IDOC>

      <EDI_DC40>

      <TABNAM>EDI_DC40</TABNAM>

      <MANDT>104</MANDT>

      <DOCNUM/>

      <DOCREL>620</DOCREL>

      <DIRECT>2</DIRECT>

      <IDOCTYP>WPUBON01</IDOCTYP>

      <MESTYP>WPUBON</MESTYP>

      <MESCOD>ST6</MESCOD>

      <SNDPOR>WPUX</SNDPOR>

      <SNDPRT>KU</SNDPRT>

      <SNDPRN>0799</SNDPRN>

      <RCVPOR>SAPRD1</RCVPOR>

      <RCVPRT>KU</RCVPRT>

      <RCVPRN>0799</RCVPRN>

      <REFINT>00000000000016</REFINT>

      </EDI_DC40>

      <E1WPB01 SEGMENT="1">

      <POSKREIS>0001</POSKREIS>

      <KASSID>1</KASSID>

      <VORGDATUM>20060107</VORGDATUM>

      <VORGZEIT>134512</VORGZEIT>

      <BONNUMMER>120572</BONNUMMER>

      <KASSIERER>4400</KASSIERER>

      <CSHNAME> </CSHNAME>

      <BELEGWAERS>GBP</BELEGWAERS>

      <E1WPB02 SEGMENT="2">

      <VORGANGART/>

      <QUALARTNR>ARTN</QUALARTNR>

      <ARTNR>000005034394436881</ARTNR>

      <VORZEICHEN>-</VORZEICHEN>

      <MENGE>1</MENGE>

      <REFBONNR> </REFBONNR>

      <E1WPB03 SEGMENT="3">

      <VORZEICHEN/>

      <KONDITION>PN10</KONDITION>

      <KONDVALUE>10.00</KONDVALUE>

      <CONDID/>

      <QUALCONDID/>

      </E1WPB03>

      <b> <E1WPB03 SEGMENT="9">

      <VORZEICHEN/>

      <KONDITION>PN10</KONDITION>

      <KONDVALUE>1.00</KONDVALUE>

      <CONDID/>

      <QUALCONDID/>

      </E1WPB03></b>

      </E1WPB02>

      <E1WPB02 SEGMENT="5">

      <VORGANGART/>

      <QUALARTNR>ARTN</QUALARTNR>

      <ARTNR>000005034394471158</ARTNR>

      <VORZEICHEN>-</VORZEICHEN>

      <MENGE>1</MENGE>

      <REFBONNR> </REFBONNR>

      <E1WPB03 SEGMENT="6">

      <VORZEICHEN/>

      <KONDITION>PN10</KONDITION>

      <KONDVALUE>20.00</KONDVALUE>

      <CONDID/>

      <QUALCONDID/>

      </E1WPB03>

      <b> <E1WPB03 SEGMENT="9">

      <VORZEICHEN/>

      <KONDITION>PN10</KONDITION>

      <KONDVALUE>2.00</KONDVALUE>

      <CONDID/>

      <QUALCONDID/>

      </E1WPB03></b>

      </E1WPB02>

      <E1WPB02 SEGMENT="8">

      <VORGANGART/>

      <QUALARTNR>ARTN</QUALARTNR>

      <ARTNR>000005034394469131</ARTNR>

      <VORZEICHEN>-</VORZEICHEN>

      <MENGE>1</MENGE>

      <REFBONNR> </REFBONNR>

      <E1WPB03 SEGMENT="9">

      <VORZEICHEN/>

      <KONDITION>PN10</KONDITION>

      <KONDVALUE>30.00</KONDVALUE>

      <CONDID/>

      <QUALCONDID/>

      </E1WPB03>

      <b> <E1WPB03 SEGMENT="9">

      <VORZEICHEN/>

      <KONDITION>PN10</KONDITION>

      <KONDVALUE>3.00</KONDVALUE>

      <CONDID/>

      <QUALCONDID/>

      </E1WPB03></b>

      </E1WPB02>

      <E1WPB06 SEGMENT="11">

      <VORZEICHEN>+</VORZEICHEN>

      <ZAHLART>PTCS</ZAHLART>

      <SUMME>10.00</SUMME>

      <KARTENNR/>

      <ZUONR>120572</ZUONR>

      </E1WPB06>

      </E1WPB01>

      </IDOC>

      </WPUBON01>

      The 3 new segments required are highlighted in bold. Note that coupon segment can be repeating but is not required in the target message.

      Cheers

  • avatar image
    Former Member
    Jul 03, 2006 at 02:27 PM

    Hi Stuart,

    Please confirm if I have followed correctly:-

    Coupon1 -> $10

    Coupon2 -> $20

    Item1 -> $5

    Item2 -> $2

    Condition1 for item1 -> 10/5=$2

    Condition2 for item1 -> 20/5=$4

    Condition1 for item2 -> 10/2=$5

    Condition2 for item2 -> 20/2=$10

    Regards,

    Sushumna

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Stuart,

      Although I haven't tried this out, just check if this is working:-

      1. Initially, just check the occurences part, i.e just check if you are able to get the required number of conditions under each item corresponding to the number of coupons

      2. Calculate the sum of the item values in a java code so that u can use it every time u need to divide.

      3. create another java function again so that u send one item value, 1 coupon value and the 1st java fn's result and inturn get the required result [(item value/1stjava value)*coupon value].

      Although you can achieve these results with the help of using the simple arithmetic functions that are already provided, but with the help of the java function, you will be able to reuse it instead of dragging and dropping everytime!

      I think you'll face the most trouble with the occurences.

      Also, just check if there are chances of having no coupons..is it a mandatory field?

      I think you'l be able to solve this with some amount of trial and error.

      Regards,

      Sushumna

  • avatar image
    Former Member
    Jul 04, 2006 at 07:12 AM

    Hi Stuart,

    you can do the following:

    1. Write two short user defined functions (both using Context as Cache and both having two input parameters a and b):

    a) Function duplicateContent with the following coding:

     for (int i = 0; i < b.length; i++){
        for (int j = 0; j < a.length; j++) result.addValue(a[j]);
       result.addContextChange();
     }

    b) Function addContent with the following coding:

     for (int j = 0; j < a.length; j++) result.addValue(a[j]);
     for (int j = 0; j < b.length; j++) result.addValue(b[j]);

    2. The mapping for your node E1WPB03 should look like:

                         E1WPB03 -->
    E1WPB05 -->                      addContent --> E1WPB03
                duplicateContent -->
    <i>E1WPB03</i> -->

    Change the content for <i>E1WPB03</i> (the one in italics) to E1WPB01.

    3. The mapping for your node KONDVALUE (as an example) can look like:

                        <i>KONDVALUE</i> -->
    <i>RABVALUE</i> -->                       addContent --> SplitByValue --> KONDVALUE
                 duplicateContent -->
     <i>E1WPB03</i> -->

    The content for each item in italics need to be set one level up.

    This mapping doesn't give you the calculation yet, but it should give you the idea how to do that.

    Regards,

    Claus

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 04, 2006 at 07:39 AM

    Hi Stuart,

    one correction to my solution above (somehow the system didn't let me correct my previous reply):

    As input for the function duplicateContent replace E1WPB03 with E1WPB02. Then you also don't need to change the context.

    Regards,

    Claus

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Stefan - appreciate your views but I really want to push on to try and make this work....

      Claus,

      Your solution is excellent and works really well - I like the way the E1WPB03 segment is duplicated from itself as many times as is necessary. Thankyou for that.

      Of course, it gets a bit more complex; I only want to apportion a coupon amount against line items where the E1WPB02-VORZEICHEN field is '-' and the E1WPB03-KONDITION is 'PN10'. For my E1WPB03 mapping therefore, I have included an If..Else so that the duplication should only occur for any item if these conditions exist.

      This shouldn't be difficult. However, XI mapping If statements seem to evaluate the Then part before the If expression is even tested; if you Display Queue on the If statement, the first parameter (in0) is the Then part; this is where the duplication occurs, so for 3 items, there are 6 entries in the queue. However, the second parameter (in1) is the If part; as we start with only 3 E1WPB02/03 items, this is only done 3 times. So the queues have 6 entries and then 3 entries. No additional E1WPB03 segments are therefore created.

      <b>What I want:</b> if conditions are met, duplicate the E1WPB03 segment

      <b>What I'm getting:</b> there's only 3 expressions to test, so only 3 will be output despite the duplication performed in the Then clause....

      How can I get around this?

      Thanks,

      Stuart

  • Jul 07, 2006 at 12:28 PM

    Hi Stuart,

    In my opinion this is application functionality which should not done in mapping.

    It is not possible to use standard functions. You run into rounding and zero value issues. Let's have foolwing example:

    Coupon 1$, item values: 3$, 994$, 3$.

    The result is: 0,00$, 0,99$, 0,00$

    What do you want to do with the missing 0,01$?

    Another example:

    Coupon 1$, item values: 6$, 988$, 6$.

    The result is: 0,01$, 0,99$, 0,01$

    When you write a UDF, you have to deal with these issues, but in opinion the sender or receiver application should handle this.

    Regards

    Stefan

    Add comment
    10|10000 characters needed characters exceeded