Converting an XML file with many hierarchy levels to ABAP format


In this part of the code  

Z_XML_IDOC should be created in XSLT Editor and write code for that as follows:-

We can go there by double clicking on Z_XML_IDOC.Create it and after copying this code activate it.  

XSLT is a language is used to convert XML from one format to another format.  

Copy paste the following code in XSLT editor :-  

Some rules which were applied for conversion to XSLT are:-

IDOC_GET is used to get the data from IDOC.In the XML file the main node is IDOC which has E1MARAM and EDIDC_40 which in turn contains MSGFN,MATNR and E1MAKTM and EDIDC_40 contains MSGFN and DOCNUM respectively.  

The same type of structure which is used in our program needs to be filled.In our program EDIDC_40 is used as ZEDIDC40 and E1MARAM is used as ZE1MARAM_TEST1.  

The basic template is already filled when we enter the XSLT editor.

We use IDOC_GET to use the IDOC data.We should use the tags to be filled in the hierarchy structure as we declared it in the program.To use the values we need to use the structures in the XML file.Use the corresponding path to access the values.  

After transformation the gt_zeu_matmas03 is filled which can be used for displaying.  

<xsl:transform xmlns:xsl="" version="1.0">
  <xsl:output encoding="iso-8859-1" indent="yes" method="xml" version="1.0"/>
  <xsl:strip-space elements="*"/>
  <xsl:template match="/">
    <asx:abap xmlns:asx="" version="1.0">
          <xsl:apply-templates select="//IDOC"/>
  <xsl:template match="IDOC">
         <MESTYP><xsl:value-of select="EDI_DC40/MESTYP"/></MESTYP>
         <DOCNUM><xsl:value-of select="EDI_DC40/DOCNUM"/></DOCNUM>
          <MSGFN><xsl:value-of select="E1MARAM/MSGFN"/></MSGFN>
          <MATNR><xsl:value-of select="E1MARAM/MATNR"/></MATNR>
           <MSGFN><xsl:value-of select="E1MARAM/E1MAKTM/MSGFN"/></MSGFN>
           <SPRAS><xsl:value-of select="E1MARAM/E1MAKTM/SPRAS"/></SPRAS>
           <MAKTX><xsl:value-of select="E1MARAM/E1MAKTM/MAKTX"/></MAKTX>
           <SPRAS_ISO><xsl:value-of select="E1MARAM/E1MAKTM/SPRAS_ISO"/></SPRAS_ISO>

*Come back to ABAP editor and copy this code for error handling.

  CATCH cx_root INTO gs_rif_ex.

    gs_var_text = gs_rif_ex->get_text( ).
MESSAGE gs_var_text TYPE 'E'.


*Display the file contents on screen.
 sy-subrc = 0.
LOOP at gt_zeu_matmas03 INTO gs_zeu_matmas03.
WRITE:  gs_zeu_matmas03-idoc-zedidc40-docnum, “document no
          / gs_zeu_matmas03-idoc-zedidc40-mestyp, “message type
          / gs_zeu_matmas03-idoc-ze1maram_test1-msgfn,”message function
          / gs_zeu_matmas03-idoc-ze1maram_test1-matnr,”material no

*all fields of E1MAKTM segment
          / gs_zeu_matmas03-idoc-ze1maram_test1-e1maktm-msgfn,
          / gs_zeu_matmas03-idoc-ze1maram_test1-e1maktm-spras,
          / gs_zeu_matmas03-idoc-ze1maram_test1-e1maktm-maktx,
          / gs_zeu_matmas03-idoc-ze1maram_test1-e1maktm-spras_iso.

We can see the values filled in the heirarchy structure of IDOC as follows:-


Execute the ABAP program and we get the file contents displayed as below.So we have converted the given XML File to a structure and display the contents.

Final output of the program is:-

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image