Technical Articles
Integration Advisor: Conditional mapping in MAG to pass one value from the multiple occurrence of an element, based on other element’s value
Introduction: This document describes, how to pass one value from the multiple occurrence of an element at source payload, based on other element’s value in MAG.
Let’s take an example of Order confirmation IDOC to EDI 855
ORDERS05 IDOC is the source payload and EDI 855 is the target payload
Following XML is the part of source payload (ORDERS05 Idoc)
<E1EDK02 SEGMENT=”1″>
<QUALF>001</QUALF>
<BELNR>141231</BELNR>
<DATUM>20231125</DATUM>
</E1EDK02>
<E1EDK02 SEGMENT=”1″>
<QUALF>002</QUALF>
<BELNR>985483</BELNR>
<DATUM>20231125</DATUM>
</E1EDK02>
Now, the order ID will be picked up from BELNR where QUALF=001 and pass it to target structure’s element.
Let’s create a MAG for ORDERS05 and EDI 855
I am not explaining entire mapping here, just focusing on element where conditional mapping is required.
Drag and drop down both /ORDERS05/IDOC/E1EDK02/QUALF and /ORDERS05/IDOC/E1EDK02/BELNR elements from source structure to /855/BAK/324 element of target structure.
Go to function tab of that element and write XSLT code
<xsl:variable name="vqlf" select="$nodes_in/QUALF"/> <xsl:variable name="vblr" select="$nodes_in/BELNR"/> <xsl:for-each select="$nodes_in/QUALF"> <xsl:variable name="pos" select="position()" /> <xsl:if test="$vqlf[$pos] = 001"> <xsl:value-of select="$vblr[$pos]"/> </xsl:if> </xsl:for-each>
Let me explain each statement
<xsl:variable name=”vqlf” select=”$nodes_in/QUALF”/>
//Variable “vqlf” will have data of all occurrences of QUALF
<xsl:variable name=”vblr” select=”$nodes_in/BELNR”/>
//Variable “vqlf” will have data of all occurrences of BELNR
<xsl:for-each select=”$nodes_in/QUALF”>
// This loop will run for the all occurrences of QUALF
<xsl:variable name=”pos” select=”position()” />
//pos will keep the position value of current occurrence
<xsl:if test=”$vqlf[$pos] = 001″>
// Checking QUALF value is 001 or not for current position
<xsl:value-of select=”$vblr[$pos]”/>
// If above statement is true then sending current value of BELNR
</xsl:if>
</xsl:for-each>
//End loop
Test it using simulation feature
Upload source payload
Here we can see that Order ID which has QUALF value 001 has passed to target element.
Conclusion: This document explained that how to read one value from an element which has multiple occurrence using XSLT Code.




Thanks for the blog Dharam Verma. Wish SAP had stick to its PO style mapping tool rather than custom XSLT.
Hi Dharam Verma, I'm updating my previous comment. Your code is perfectly right and working!
Just to add another solution: Especially if you have a group with several child fields to map with the same condition, you could use the "conditional mapping" feature (see e.g. in the blog of Fatih Pense here: https://blogs.sap.com/2022/01/23/integration-advisor-conditional-mapping-feature). Like this, you don't have to use the XSLT snippet on every child/leaf node - because it's a bit cumbersome to maintain the condition on every field.
In your case, it should be possible to map both the group node E1EDK02 and the key field QUALF to the target group node BAK. However, and that's what I struggled with before, the target group node must not have cardinality 1..1, but a higher one, e.g. 1..2 (otherwise, all child nodes values are available (and concatenated) in the target nodes for processing, instead only the ones that match the condition - which according to SAP is a feature to be able to sum up values). So you would need to modify your target MIG and change cardinality of BAK to 1..2.
Then, in the mapping of the target group node, simply enter the condition as Xpath as shown in the mentioned blog. In your case it would be:
Then, all leaf fields (below that group node) can be mapped without inserting any condition!
Each target group node below the top group node (the one with the higher cardinality) has to be mapped with the same conditional mapping/XPath code too, but not the single fields. See screenshot with another mapping as example:
Best regards,
Philippe