
{
"Product":"TIRE002",
"ProductType":"FERT",
"BaseUnit":"PC",
"to_Description": {
"results": [
{
"Product": "TIRE002",
"Language": "EN",
"ProductDescription": "Tire"
},
{
"Product": "TIRE002",
"Language": "DE",
"ProductDescription": "Reifen"
},
{
"Product": "TIRE002",
"Language": "ES",
"ProductDescription": "Neumatico"
}
]
}
}
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
def messageLog = messageLogFactory.getMessageLog(message);
def bodyAsString = message.getBody(String.class);
messageLog.addAttachmentAsString("Payload after Mapping", bodyAsString, "text/xml");
return message;
}
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
<soapenv:Header/>
<soapenv:Body>
<Z1MATMAS05>
<IDOC BEGIN="1">
<EDI_DC40 SEGMENT="1">
</EDI_DC40>
<E1MARAM SEGMENT="1">
<MATNR>TIRE003</MATNR>
<MTART>FERT</MTART>
<MEINS>PC</MEINS>
<E1MAKTM SEGMENT="1">
<MAKTX>Reifen</MAKTX>
<SPRAS_ISO>DE</SPRAS_ISO>
</E1MAKTM>
<E1MAKTM SEGMENT="1">
<MAKTX>Tire</MAKTX>
<SPRAS_ISO>EN</SPRAS_ISO>
</E1MAKTM>
<E1MAKTM SEGMENT="1">
<MAKTX>Neumatico</MAKTX>
<SPRAS_ISO>ES</SPRAS_ISO>
</E1MAKTM>
</E1MARAM>
</IDOC>
</Z1MATMAS05>
</soapenv:Body>
</soapenv:Envelope>
import com.sap.gateway.ip.core.customdev.util.Message
import groovy.xml.MarkupBuilder
Message processData(Message message) {
// Access message body and properties
Reader reader = message.getBody(Reader)
// Define XML parser and builder
def Z1MATMAS05 = new XmlSlurper().parse(reader)
def writer = new StringWriter()
def builder = new MarkupBuilder(writer)
// Define target payload mapping
builder.A_Product {
'A_ProductType' {
'Product'(Z1MATMAS05.IDOC.E1MARAM.MATNR)
'ProductType'(Z1MATMAS05.IDOC.E1MARAM.MTART)
'BaseUnit' (Z1MATMAS05.IDOC.E1MARAM.MEINS)
'to_Description'{
Z1MATMAS05.IDOC.E1MARAM.E1MAKTM.each {item->
'A_ProductDescriptionType'{
'Product' (Z1MATMAS05.IDOC.E1MARAM.MATNR)
'Language' (item.SPRAS_ISO)
'ProductDescription' (item.MAKTX)
}
}
}
}
}
// Generate output
message.setBody(writer.toString())
return message
}
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<!-- TODO: Auto-generated template -->
<xsl:for-each select="/Z1MATMAS05/IDOC">
<A_Product>
<A_ProductType>
<Product> <xsl:value-of select="./E1MARAM/MATNR"/> </Product>
<ProductType> <xsl:value-of select="./E1MARAM/MTART"/> </ProductType>
<BaseUnit> <xsl:value-of select="./E1MARAM/MEINS"/></BaseUnit>
<to_Description>
<xsl:for-each select="./E1MARAM/E1MAKTM">
<A_ProductDescriptionType>
<Product> <xsl:value-of select="/Z1MATMAS05/IDOC/E1MARAM/MATNR"/> </Product>
<Language> <xsl:value-of select="./SPRAS_ISO"/> </Language>
<ProductDescription> <xsl:value-of select="./MAKTX"/> </ProductDescription>
</A_ProductDescriptionType>
</xsl:for-each>
</to_Description>
</A_ProductType>
</A_Product>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
<A_Product>
<A_ProductType>
<Product>TIRE003</Product>
<ProductType>FERT</ProductType>
<BaseUnit>PC</BaseUnit>
<to_Description>
<A_ProductDescriptionType>
<Product>TIRE003</Product>
<Language>DE</Language>
<ProductDescription>Reifen</ProductDescription>
</A_ProductDescriptionType>
<A_ProductDescriptionType>
<Product>TIRE003</Product>
<Language>EN</Language>
<ProductDescription>Tire</ProductDescription>
</A_ProductDescriptionType>
<A_ProductDescriptionType>
<Product>TIRE003</Product>
<Language>ES</Language>
<ProductDescription>Neumatico</ProductDescription>
</A_ProductDescriptionType>
</to_Description>
</A_ProductType>
</A_Product>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
23 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 |