cancel
Showing results for 
Search instead for 
Did you mean: 

SAP CPI: Help needed with XSLT code !

das_sappo
Participant
0 Kudos

Hi Experts,

Could you please help me with the below condition ?

If E1EDK01[QUALF=012]/BELNR is nill then map E1EDK01[QUALF=002]/BELNR with target.

Regards,

Arvik

Ryan-Crosby
Active Contributor
0 Kudos

How are your BELNR nodes represented on the target field when you view the input parameters?

Bais
Participant
0 Kudos

>If E1EDK01[QUALF=012]/BELNR is nill then map E1EDK01[QUALF=002]/BELNR with target.

loop your nodes:

<xsl:copy-of select="yournode/* except BELNR"/>

<BELNR><xsl:value-of select="if ( E1EDK01[QUALF=012]/BELNR) then E1EDK01[QUALF=012]/BELNR else E1EDK01[QUALF=002]/BELNR"/></BELNR>

das_sappo
Participant
0 Kudos

Hi Ryan/Fed,

If I simply map the nodes/fields without additional code the the simulation result looks like below.

In the target REF-02 getting both the values when I only need E1EDK02[012]/BELNR if available/non Null. If E1EDK02[002] is NULL/not available then E1EDK02[002]/BELNR

das_sappo
Participant
0 Kudos

Please suggest suitable XSL code for the above requirement . I have used different codes but none of them giving correct output.

das_sappo
Participant
0 Kudos

Hi Ryan/Federico,

If I use following XSLT then getting values from both the fields. Please suggest how can I correct it so if both the QUALF is available then only //E1EDK02[012]/BELNR should be copied and if //E1EDK02[012]/BELNR = NOT AVAILABLE then //E1EDK02[002]/BELNR

<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:choose>
<xsl:when test="$vqlf[$pos] = 012">
<xsl:value-of select="$vblr[$pos]"/>
</xsl:when>
<xsl:otherwise>
  <xsl:value-of select="$vblr[$pos]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>

Ryan-Crosby
Active Contributor
0 Kudos

das.sappo before doing any code I would suggest renaming the two BELNR nodes, and doing so would allow you to remove the QUALF nodes entirely... e.g. BELNR_002 & BELNR_012. Such a tact simplifies the necessary approach for the solution.

das_sappo
Participant
0 Kudos

ryan.crosby , Thanks for your valuable suggestion. But I can't see any option in MIG to rename the BELNR in the IDOC structure.

Ryan-Crosby
Active Contributor
0 Kudos

das.sappo you don't rename the BELNR in the IDoc structure... you rename the parameters in the mapping function for the target field (the clickable links for $nodes_in/BELNR - it can be done because I have used it before).

das_sappo
Participant
0 Kudos

Thanks !

so much helpful 🙂

Able to do it now.

Accepted Solutions (1)

Accepted Solutions (1)

Ryan-Crosby
Active Contributor
0 Kudos

Hi Arvik,

This solution presupposes the renaming that I have mentioned in my comment.

<xsl:choose>
<xsl:when test=“exists($nodes_in/BELNR_012)”><xsl:value-of select="$nodes_in/BELNR_012“/></xsl:when>
<xsl:otherwise><xsl:value-of select="$nodes_in/BELNR_002”/></xsl:otherwise>
</xsl:choose>

Regards,

Ryan Crosby

Answers (1)

Answers (1)

YayatiEkbote
Contributor
0 Kudos

Try this one -

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="/">
		<xsl:choose>
			<xsl:when test="//E1EDK01[QUALF=012]/BELNR">
				<S_REF>
					<D_128><xsl:value-of select="'Qulifier'"/></D_128>
					<D_127><xsl:value-of select="//E1EDK01[QUALF=012]/BELNR"/></D_127>
				</S_REF>
			</xsl:when>
			<xsl:otherwise>
				<S_REF>
					<D_128><xsl:value-of select="'Qulifier'"/></D_128>
					<D_127><xsl:value-of select="//E1EDK01[QUALF=002]/BELNR"/></D_127>
				</S_REF>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>

Regards,

Yayati

das_sappo
Participant
0 Kudos

Hi Yayati,

Thanks for your reply.

Not able to simulate MAG with this code as giving error on XSLT.