Skip to Content
author's profile photo Former Member
Former Member

PI Mapping : Generating multiple nodes by one node

Hi,

I'm looking for the solution how to generate two nodes by one node in source messages. In the following sample messages, two nodes in source are expected to generate 4 nodes in output.

Source Structure

<item>

<id>

<name>

</item>

Target structure

<article>

<flag>

<id>

<name>

</article>

Source message instance

<item>

<id>1</id>

<name>ABC</name>

</item>

<item>

<id>2</id>

<name>XYZ</name>

</item>

Expected output message

<article>

<flag>QD</flag>

<id>1</id>

<name>ABC</name>

</article>

<article>

<flag>QI</flag>

<id>1</id>

<name>ABC</name>

</article>

<article>

<flag>QD</flag>

<id>2</id>

<name>XYZ</name>

</article>

<article>

<flag>QI</flag>

<id>2</id>

<name>XYZ</name>

</article>

In output message, two node of article 1 should be together.

Thanks in advance!

Victor

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Dec 09, 2010 at 06:27 PM

    Well I think for this you have to write UDF but before that you can try below solution and if doesn't help then go for UDF creation..

    To get your desired restuls you have to duplicate the target structure once.

    Right clik on <article> node and select "Duplicate Subtree". Now in first <article>-flag map constant "QD" and in in second map "QI", and map source <id> & <name> to target <id > & <name> nodes in both <article> nodes.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hey thanks to all that contributed to the solution of this.

      I'm a newby to message mapping of SAP PI.

      But in my learning process I found out that the solution proposed in :

      http://help.sap.com/saphelp_nw04/helpdata/en/26/d22366565be0449d7b3cc26b1bab10/content.htm

      using the copyvalue function

      is not working for the case where you have 2 partnernodes in the partnermsg. In this case the proposed solution is putting the street,city and zipcode of the first partnernode in both the targetnodes created in the mapping.

      After some thinking about how to solve it I came up with the solution :

      I created 3 UDF's ( getstreet ,getcity and getzipcode) :

      public void getstreet(String[] var1, ResultList result, Container container) throws StreamTransformationException{

      for (int i = 0; i < var1.length; i++) {

      if ( (i%3) == 0) {

      result.addValue(var1<i>);

      }

      }

      }

      public void getcity(String[] var1, ResultList result, Container container) throws StreamTransformationException{

      for (int i = 0; i < var1.length; i++) {

      if ( (i%3) == 1) {

      result.addValue(var1<i>);

      }

      }

      }

      public void getzipcode(String[] var1, ResultList result, Container container) throws StreamTransformationException{

      for (int i = 0; i < var1.length; i++) {

      if ( (i%3) == 2) {

      result.addValue(var1<i>);

      }

      }

      }

      the mapping for the target field street :

      street = splitbyvalue ( getstreet(removecontext(addrdat)) "each value")

      similar mappings need to be set for city and zipcode.

      other mappings are :

      customermsg = partnermsg

      customer = createif(exists(partner)))

      name = name

      this solves the issue for the 2 partnernodes without using the copyvalue function

  • Posted on Dec 09, 2010 at 06:42 PM

    Hi,

    Just Duplicate the target node "article" and then use copyValue function(JUST GIVE A TRY)

    like: for first article:

    id copyvalue(0)-id(target)

    namecopyvalue(0)name(target)

    similarly do it for the other "article" node:

    id copyvalue(1)-id(target)

    namecopyvalue(1)name(target)

    Note: it would be better if u go for UDF.

    Thanks

    Amit

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.