Hi experts,
I have a Requirement where in I need to map the field names from Source structure to the target structure...
For Example:
My Source structure:
<field1>123</field1>
<field2>XYZ</field2>
Expected Target structure:
<Node>
<Fieldname>field1</Fieldname>
<Fieldvalue>123</Fieldvalue>
</Node>
<Node>
<Fieldname>field2</Fieldname>
<Fieldvalue>XYZ</Fieldvalue>
</Node>
Can you please advise how to achieve this in Graphical Mapping of SAP PI (and maybe with an UDF)?
Best regards,
John
Request clarification before answering.
Hi John,
An XSLT like the following would handle that mapping requirement (assuming a root node named root) -
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="root">
<xsl:copy>
<xsl:for-each select="*">
<Node>
<Fieldname><xsl:value-of select="local-name()"/></Fieldname>
<Fieldvalue><xsl:value-of select="."/></Fieldvalue>
</Node>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Regards,
Ryan Crosby
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
pi.consultant1 I'm sure it can be done with graphical mapping but it's not worth the effort. The XSLT option took mere minutes, but using graphical mapping requires that you know the field names at build time and they may never change. The XSLT would work if the field names were changed to Field1, Field2 or MyField1, MyField2, but graphical mapping would break immediately.
pi.consultant1 I'm now with an organization that does not have a PI/PO system and the graphical mapping tool in CPI leaves much to be desired. That said, XSLT is far more powerful and flexible IMO than the trusty old graphical mappings.
Hello John,
For UDF + graphical mapping alternative you can refer to this blog: https://blogs.sap.com/2012/11/05/message-mapping-play-around-with-target-structure/.
However I would go with XSLT option here which Ryan suggested.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you Filip.
This is a useful blog, however my usecase is exactly the other way around. So the source looks like this:
<Items>
<CompanyA>abc corp</CompanyA>
<CompanyB>xyz info</CompanyB>
</Items>
And the target like this:
<Rows>
<Key>CompanyA</Key>
<Value>abc corp</Value>
</Rows>
<Rows>
<Key>CompanyB</Key>
<Value>xyz info</Value>
</Rows>
…
It would be great to know exactly what to do if its the other way around...
I also will look at the XSLT option.
Regards,
John
To get it other way around you need to find method that reads structure of the input. You can check this documentation: https://help.sap.com/doc/javadocs_nw75_sps04/7.5.4/en-US/PI/overview-summary.html for existing packages. You should find something in com.sap.aii.mappingtool.tf7.rt and com.sap.aii.mapping.api packages.
As an alternative you can use "Return as XML" option and parse it in udf using javax.xml.parser. Example of reading xml node names: https://stackoverflow.com/questions/10784036/retrieving-xml-node-names.
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.