2012 Apr 13 3:15 PM
Hi Gurus,
I need help about STRANS functionality of ABAP.
I have a internal table and i show this table in ALV list. I want to send my alv list to legacy systems.
Normally i can create a xml document with concat fields in abap. But i want to use STRANS.
How can I transform itab to deep structure xml. Thanks a lot. I dont want to use string concat or xml classes.. I just want to use XSLT.
Thanks a lot
Volkan
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<ITAB>
<item>
<VBELN>0060000004</VBELN>
<KUNNR>0000000051</KUNNR>
<POSNR>000001</POSNR>
<MATNR>H1</MATNR>
</item>
<item>
<VBELN>0060000004</VBELN>
<KUNNR>0000000051</KUNNR>
<POSNR>000002</POSNR>
<MATNR>H2</MATNR>
</item>
<item>
<VBELN>0060000005</VBELN>
<KUNNR>0000000051</KUNNR>
<POSNR>000001</POSNR>
<MATNR>H1</MATNR>
</item>
</ITAB>
</asx:values>
</asx:abap>
Destination XML Must be like this
<?xml version="1.0" encoding="UTF-16"?>
<ROOT>
<ORDER>
<VBELN>0060000004</VBELN>
<KUNNR>0000000051</KUNNR>
<ORDERLINES>
<ORDERLINE>
<POSNR>000001</POSNR>
<MATNR>H1</MATNR>
</ORDERLINE>
<ORDERLINE>
<POSNR>000002</POSNR>
<MATNR>H2</MATNR>
</ORDERLINE>
</ORDERLINES>
</ORDER>
<ORDER>
<VBELN>0060000005</VBELN>
<KUNNR>0000000051</KUNNR>
<ORDERLINES>
<ORDERLINE>
<POSNR>000001</POSNR>
<MATNR>H1</MATNR>
</ORDERLINE>
</ORDERLINES>
</ORDER>
</ROOT>
2012 Apr 13 7:48 PM
Try this:
<?xml version='1.0' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:asx="http://www.sap.com/abapxml">
<xsl:key name="ByDoc" use="VBELN" match="item"/>
<xsl:key name="ItemsByDoc" use="concat(concat(VBELN, '|'), POSNR)" match="item"/>
<xsl:template match="/">
<xsl:variable name="var_msg" select="asx:abap/asx:values/ITAB"/>
<xsl:for-each select="$var_msg">
<ROOT>
<xsl:for-each select="$var_msg/item[count(. | key('ByDoc', VBELN)[1]) = 1]">
<xsl:sort select="VBELN" data-type="number"></xsl:sort>
<ORDER>
<VBELN><xsl:value-of select="VBELN"/></VBELN>
<KUNNR><xsl:value-of select="string(KUNNR)"/></KUNNR>
<ORDERLINES>
<xsl:for-each select="key('ByDoc', VBELN)[count(. | key('ItemsByDoc', concat(concat(VBELN, '|'), POSNR))[1]) = 1]">
<xsl:sort select="POSNR" data-type="number"></xsl:sort>
<ORDERLINE>
<POSNR><xsl:value-of select="string(POSNR)"/></POSNR>
<MATNR><xsl:value-of select="string(MATNR)"/></MATNR>
</ORDERLINE>
</xsl:for-each>
</ORDERLINES>
</ORDER>
</xsl:for-each>
</ROOT>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>