avatar image
Former Member

Mapping: How to map XPath nodes based on attribute values in SAP PI

Hello all,

I am new to SAP PI and have the following sender message structure as follows:

<ItemData>
<Attribute name="VENDOR_ACCOUNT_NUMBER">
<Value>12345678</Value>
</Attribute>
<Attribute name="VENDOR_ACCOUNT_GROUP">
<Value>XYZ</Value>
</Attribute>
<Attribute name="LEGAL_ENTITY">
<Value>12345</Value>
</Attribute>
<Attribute name="NAME1">
<Value>XYZ COMPANY</Value>
</Attribute>
</ItemData>

And the following receiver target structure

<CREMAS05>
<E1LFA1M>
<LIFNR/>
<NAME1/>
<KTOKK/>
</E1LFA1M>
</CREMAS05>

Question: I would like to do the following mappings

Item/Attribute[@name="VENDOR_ACCOUNT_NUMBER"]/Value --> CREMAS05/E1LFA1M/LIFNR

and so on.

What is the best approach to do the above mappings? Is the above doable using Graphical mapping. If not what are the other alternatives to achieve the desired target values.

Thanks and Regards,

Mustafa

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Mar 28, 2017 at 04:30 PM

    Hi am suggesting to use XSLT. For such a small message the graphical tool will work, too. But I could imagine that you also want to fill the E1LFB1M segment, etc. And then it will become soon very complex.

    above example would be:

    <xsl:template match="/">
    <CREMAS05>
    <xsl:apply-templates select="//ItemData"/>
    </CREMAS05>
    </xsl:template>

    <xsl:template match="ItemData">
    <E1LFA1M Segment="1">
    <LIFNR><xsl:value-of select="Attribute[name='VENDOR_ACCOUNT_NUMBER']/Value"/><LIFNR>
    ...
    </E1LFA1M>
    </xsl:template>

    you see, it's very easy to write down, much easier than the graphical playground.

    Regards

    Helmut

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Thank you the sample XSLT, Helmut. The message I provided was only a snippet of the actual message.

      In reality, the source message has a lot of fields and everything is represented as a key/value pair, where Attribute element is the field name and Value element is the value for that field.

      This helps a lot!!!

      Regards,

      Mustafa

  • Mar 23, 2017 at 11:25 PM

    Hi,

    You can map this structure in graphical mapping with standard functions.

    e.g.

    name --> mapwith default --> equals ("VENDOR_ACCOUNT_NUMBER") --> If without else--> Map value

    regarsd,

    Harish

    Add comment
    10|10000 characters needed characters exceeded

Skip to Content