Integration Advisor: Conditional mapping in MAG to pass one value from the multiple occurrence of an element, based on other element’s value
2023-11-28 23:36:3 Author: blogs.sap.com(查看原文) 阅读量:6 收藏

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.


文章来源: https://blogs.sap.com/2023/11/28/integration-advisor-conditional-mapping-to-pass-one-value-from-the-multiple-occurrence-of-an-element-based-on-other-elements-value/
如有侵权请联系:admin#unsafe.sh