Skip to Content
avatar image
Former Member

Mapping for split a field to several subelements

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Nov 14, 2006 at 08:38 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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();

      }

  • avatar image
    Former Member
    Nov 14, 2006 at 08:08 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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.

  • Nov 14, 2006 at 08:20 AM

    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

    Add comment
    10|10000 characters needed characters exceeded