/scripts/ahub.form.attachments.js
0

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

Mar 23, 2017 at 10:21 PM

159

avatar image
Former Member

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Helmut Skolaut Mar 28, 2017 at 04:30 PM
0

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

Show 2 Share
10 |10000 characters needed characters left characters exceeded

And much easier to modify in case of source structure change or growing up. :-)

Regards, Evgeniy.

0
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

0
Harish Mistri Mar 23, 2017 at 11:25 PM
0

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

Show 3 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Thank you for the response, Harish

Though the above did not work, atleast it gave me the idea. The below graphical mapping worked for me:

Feel free to provide feedback if you think there may be other possibilities.

Regards,

Mustafa

0

Hi Mustafa,

Please change the context of name and value field to one level up. and please provide the display queue and test tab screenshot if it doesn't work.

regards,

Harish

0
Former Member

Hi Harish,

I did change the context to one level up and got the expected output. Thanks for the inputs.

Regards,

Mustafa

0
Skip to Content