2013 Mar 05 4:24 PM
Hey everyone,
as you can read in the heading, I have a few problems with the Simple Transformation feature.
My task is to import the following (simplified) XML-File with a Simple Transformation:
<?xml version="1.0" encoding="UTF-8"?>
<Fees BOOK_CLIENT_ABBR="2000" PAY_CLIENT="Gruppe">
<ACC_REC_TOTAMNT ACC_DATE="2012-10-18" ACC_REC_KEY="680">
<TOTVATAMT TOTAMNT_GROSS="27.35" TOTAMNT_NET="25.56"/>
<ACC_RECORD ACC_NUM_COMP="236001" AGREEMENT_TYPE="0000502274 - 000 - B"/>
<ACC_RECORD ACC_NUM_COMP="236001" AGREEMENT_TYPE="0000502274 - 000 - B"/>
</ACC_REC_TOTAMNT>
<ACC_REC_TOTAMNT ACC_DATE="2012-10-18" ACC_REC_KEY="680">
<TOTVATAMT TOTAMNT_GROSS="27.35" TOTAMNT_NET="25.56"/>
<ACC_RECORD ACC_NUM_COMP="236001" AGREEMENT_TYPE="0000502274 - 000 - B"/>
<ACC_RECORD ACC_NUM_COMP="236001" AGREEMENT_TYPE="0000502274 - 000 - B"/>
</ACC_REC_TOTAMNT>
</Fees>
I tried to solve the problem with the graphic tool, but I can't figure out why its not running.
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:ddic="http://www.sap.com/abapxml/types/dictionary" xmlns:def="http://www.sap.com/abapxml/types/defined">
<tt:root name="Fees" type="ddic:ZJJZS_FEES"/>
<tt:template>
<Fees>
<tt:attribute name="BOOK_CLIENT_ABBR" value-ref=".Fees.BOOK_CLIENT_ABBR"/>
<tt:attribute name="PAY_CLIENT" value-ref=".Fees.PAY_CLIENT"/>
<ACC_REC_TOTAMNT>
<tt:loop ref=".FEES.ACC_REC_TOTAMNT">
<ZJJZS_ACC_REC_TOTAMNT>
<tt:attribute name="ACC_DATE" value-ref="ACC_DATE"/>
<tt:attribute name="ACC_REC_KEY" value-ref="ACC_REC_KEY"/>
<TOTVATAMT>
<tt:attribute name="PAY_CLIENT" value-ref="TOTVATAMT.PAY_CLIENT"/>
<tt:attribute name="TOTAMNT_NET" value-ref="TOTVATAMT.TOTAMNT_NET"/>
</TOTVATAMT>
<ACC_RECORD>
<tt:loop ref="ACC_RECORD">
<ZJJZS_ACC_RECORD>
<tt:attribute name="ACC_NUM_COMP" value-ref="ACC_NUM_COMP"/>
<tt:attribute name="AGREEMENT_TYPE" value-ref="AGREEMENT_TYPE"/>
</ZJJZS_ACC_RECORD>
</tt:loop>
</ACC_RECORD>
</ZJJZS_ACC_REC_TOTAMNT>
</tt:loop>
</ACC_REC_TOTAMNT>
</Fees>
</tt:template>
</tt:transform>
It would be really nice if somebody could help me.
Thank you and have a nice day. Kevin Kellenberger
2013 Mar 06 8:17 AM
2013 Mar 06 8:20 AM
Hi,
If you want to read data from the xml file into your ztable
then look at this
http://wiki.sdn.sap.com/wiki/display/ABAP/XML+XSLT+with+ABAP
2013 Mar 06 10:36 AM
Hey Fariha Ali,
first of all i want to thank you for your reply.
The problem with the XSLT is, you need an XSD, which i dont have (I have just a DTD).
And I dont want to creat an XML, I have the XML (which is given and cant be changed) and want to import this file.
As far as I understood the simple transformation works both ways XML->ABAP and ABAP->XML.
2013 Mar 06 11:04 AM
2013 Mar 06 11:37 AM
You have to go by following steps:
1. Create xslt program in se80 or xslt_tool
2. write your xslt code using commands such as
if there is one to may tags like ACC_REC_TOTAMNT
<xsl:for-each select="Fees/ACC_REC_TOTAMNT">
<ABAPfield><xsl:value-of select=" fees/@BOOK_CLIENT_ABBR" /></ABAPfield>
</xsl:for-each>
refer this below link for XSLT
http://wiki.sdn.sap.com/wiki/display/Snippets/XSLT+sample+to+encode%2C+decode+XML+file
3. create a zprogram and types and data to store result of transformation ,In your program call the transformation created as in 2 using
APIS provided
refer this for your z program
http://wiki.sdn.sap.com/wiki/display/Snippets/Read+data+from+XML+file+via+XSLT+program
in the lin above the following will call your transformation
TRY.
CALL TRANSFORMATION ZFI_AIRPLUS_XSLT
SOURCE xml l_xml_x1
RESULT xml_output = it_airplus
.
* catch any error, very helpful if the XSLT isn't correct
CATCH cx_xslt_exception INTO xslt_err.
err_string = xslt_err->get_text( ).
WRITE: / 'Transformation error: ', err_string.
EXIT.
ENDTRY.* setting a breakpoint to watch the workarea