Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Reading XML file to ABAP internal table

Former Member
0 Kudos

Hi all,

Iam trying to convert a XLM file into abap internal table , am using XSLT transformation to parse the XML file and i am using "CALL METHOD cl_gui_frontend_services=>gui_upload" for reading the XML file.

below is the XML file.

===========================================================================

- <PIXBridge version="2.2" timestamp="2003-04-09T15:27:00">

- <PIX>

<TransactionType>605</TransactionType>

<TransactionCode>98</TransactionCode>

<TransactionNumber>6888965</TransactionNumber>

<SequenceNumber>40001</SequenceNumber>

- <SKUDefinition>

<Company>GZL</Company>

<Division>BMD</Division>

<Season />

<SeasonYear />

<Style>ORT002A</Style>

<StyleSuffix />

<Color>K13</Color>

<ColorSuffix />

<SecDimension />

<Quality />

<SizeRangeCode />

<SizeDesc>M</SizeDesc>

<SkuID>200140577</SkuID>

</SKUDefinition>

</PIX>

</PIXBridge>

=================================================================

and my Transformation code is as below

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 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="http://www.sap.com/abapxml" version="1.0">

<asx:values>

<IPIX>

<xsl:apply-templates select="//PIX"/>

</IPIX>

</asx:values>

</asx:abap>

</xsl:template>

<xsl:template match="PIX">

<item>

<TRANSACTIONTYPE>

<xsl:value-of select="TransactionType"/>

</TRANSACTIONTYPE>

<TRANSACTIONCODE>

<xsl:value-of select="TransactionCode"/>

</TRANSACTIONCODE>

<TRANSACTIONNUMBER>

<xsl:value-of select="TransactionNumber"/>

</TRANSACTIONNUMBER>

<SEQUENCENUMBER>

<xsl:value-of select="SequenceNumber"/>

</SEQUENCENUMBER>

<SKUDEFINITION>

<COMPANY>

<xsl:value-of select="Company"/>

</COMPANY>

<DIVISION>

<xsl:value-of select="Division"/>

</DIVISION>

<SEASON/>

<SEASONYEAR/>

<STYLE>

<xsl:value-of select="Style"/>

</STYLE>

<STYLESUFFIX/>

<COLOR>

<xsl:value-of select="Color"/>

</COLOR>

<COLORSUFFIX/>

<SECDIMENSION/>

<QUANTITY/>

<SIZERANGECODE/>

<SIZEDESC>

<xsl:value-of select="SizeDesc"/>

</SIZEDESC>

<SKUID>

<xsl:value-of select="SkuID"/>

</SKUID>

</SKUDEFINITION>

</item>

</xsl:template>

When i run my program i am getting the values only till the sequence number part and im not getting any values that is read in between <SKUDEFINITION> ..... </SKUDEFINITION>

I need help to sort this , kindly help me in this.

regs,

raja

1 ACCEPTED SOLUTION

uwe_schieferstein
Active Contributor
0 Kudos

Hello Raja

You need to "point" the XML parser to the SKUDefinition node.


<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 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="http://www.sap.com/abapxml" version="1.0">
      <asx:values>
        <IPIX>
          <xsl:apply-templates select="//PIX"/>
        </IPIX>
      </asx:values>

    </asx:abap>
  </xsl:template>

  <xsl:template match="PIX">
    <item>
      <TRANSACTIONTYPE>
        <xsl:value-of select="TransactionType"/>
      </TRANSACTIONTYPE>

      <TRANSACTIONCODE>
        <xsl:value-of select="TransactionCode"/>
      </TRANSACTIONCODE>

      <TRANSACTIONNUMBER>
        <xsl:value-of select="TransactionNumber"/>
      </TRANSACTIONNUMBER>

      <SEQUENCENUMBER>
        <xsl:value-of select="SequenceNumber"/>
      </SEQUENCENUMBER>

      <!-- NOTE: this FOR-EACH point to the SKUDefinition node -->
      <xsl:for-each select="SKUDefinition">
        <SKUDEFINITION>
          <COMPANY>
            <xsl:value-of select="Company"/>
          </COMPANY>
          <DIVISION>
            <xsl:value-of select="Division"/>
          </DIVISION>
          <SEASON/>
          <SEASONYEAR/>
          <STYLE>
            <xsl:value-of select="Style"/>
          </STYLE>
          <STYLESUFFIX/>
          <COLOR>
            <xsl:value-of select="Color"/>
          </COLOR>
          <COLORSUFFIX/>
          <SECDIMENSION/>
          <QUANTITY/>
          <SIZERANGECODE/>
          <SIZEDESC>
            <xsl:value-of select="SizeDesc"/>
          </SIZEDESC>
          <SKUID>
            <xsl:value-of select="SkuID"/>
          </SKUID>
        </SKUDEFINITION>
      </xsl:for-each>


    </item>
  </xsl:template>


</xsl:transform>

Regards
  Uwe

5 REPLIES 5

uwe_schieferstein
Active Contributor
0 Kudos

Hello Raja

You need to "point" the XML parser to the SKUDefinition node.


<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 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="http://www.sap.com/abapxml" version="1.0">
      <asx:values>
        <IPIX>
          <xsl:apply-templates select="//PIX"/>
        </IPIX>
      </asx:values>

    </asx:abap>
  </xsl:template>

  <xsl:template match="PIX">
    <item>
      <TRANSACTIONTYPE>
        <xsl:value-of select="TransactionType"/>
      </TRANSACTIONTYPE>

      <TRANSACTIONCODE>
        <xsl:value-of select="TransactionCode"/>
      </TRANSACTIONCODE>

      <TRANSACTIONNUMBER>
        <xsl:value-of select="TransactionNumber"/>
      </TRANSACTIONNUMBER>

      <SEQUENCENUMBER>
        <xsl:value-of select="SequenceNumber"/>
      </SEQUENCENUMBER>

      <!-- NOTE: this FOR-EACH point to the SKUDefinition node -->
      <xsl:for-each select="SKUDefinition">
        <SKUDEFINITION>
          <COMPANY>
            <xsl:value-of select="Company"/>
          </COMPANY>
          <DIVISION>
            <xsl:value-of select="Division"/>
          </DIVISION>
          <SEASON/>
          <SEASONYEAR/>
          <STYLE>
            <xsl:value-of select="Style"/>
          </STYLE>
          <STYLESUFFIX/>
          <COLOR>
            <xsl:value-of select="Color"/>
          </COLOR>
          <COLORSUFFIX/>
          <SECDIMENSION/>
          <QUANTITY/>
          <SIZERANGECODE/>
          <SIZEDESC>
            <xsl:value-of select="SizeDesc"/>
          </SIZEDESC>
          <SKUID>
            <xsl:value-of select="SkuID"/>
          </SKUID>
        </SKUDEFINITION>
      </xsl:for-each>


    </item>
  </xsl:template>


</xsl:transform>

Regards
  Uwe

0 Kudos

Hi Uwe,

thanks for the solution, i tried this, i did debug and found the values but , the values of the Company....field values are not getting written on to the output file.

below is the coding in the calling program

TYPES: BEGIN OF ty_text,

TransactionType(3) type n,

TransactionCode(2) type n,

TransactionNumber(7) type n,

SequenceNumber(5) type n,

Company(3) type c,

Division(3) type c,

Season(3) type c,

SeasonYear(4) type c,

Style(8) type c,

Color(3) type c,

SecDimension(3) type c,

Quality(3) type n,

SizeRangeCode(2) type c,

SizeDesc(1) type c,

SkuID(10) type c,

END OF ty_text.

DATA: gt_person TYPE STANDARD TABLE OF ty_text,

gs_person TYPE ty_text.

  • Result table that contains references

  • of the internal tables to be filled

DATA: gt_result_xml TYPE abap_trans_resbind_tab,

gs_result_xml TYPE abap_trans_resbind.

GET REFERENCE OF gt_person INTO gs_result_xml-value.

gs_result_xml-name = 'IPIX'.

APPEND gs_result_xml TO gt_result_xml.

CALL TRANSFORMATION ZAUM_MANH_SYNC_RPT

SOURCE XML gt_itab

RESULT (gt_result_xml).

LOOP AT gt_person INTO gs_person.

WRITE: / 'Transaction Type:', gs_person-TransactionType.

WRITE: / 'Transaction Code :', gs_person-TransactionCode.

WRITE: / 'Transaction Number :', gs_person-TransactionNumber.

WRITE: / 'SequenceNumber :', gs_person-SequenceNumber.

WRITE: / 'Company : ', gs_person-Company.

WRITE : /.

ENDLOOP. "gt_person.

After doing the changes in the transformation, do we have to do any change in the main program.

suggest me.

Points assured.

regs,

raja

0 Kudos

Hello Raja

The transformation XML -> ABAP is somewhat tricky. If the XML does not perfectly match the requirements for the transformation into ABAP it will fail.

Please have a look at the posting of Durairaj in

I would use the following approach:

1) Fill your ABAP structure with data and make the transformation ABAP -> XML (standard)

2) Use this output XML as target for your own XML -> XML transformation

As soon as your own XLST transformation matches the "standard" XML output you should be able to make the transformation XML -> ABAP.

Regards

Uwe

0 Kudos

I am not able to get a clue out of that, can Get Durairaj Athavan Raja in to loop for sorting this out.

I made changes to my transformation program , but still not getting the output of the components inside the

<SKUDefinition> , but when i debug the transformation i can able to see the output values for those components but when i get the values in the result table im not getting values of those components.

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 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="http://www.sap.com/abapxml" version="1.0">

<asx:values>

<IPIX>

<xsl:apply-templates select="//PIX"/>

</IPIX>

</asx:values>

</asx:abap>

</xsl:template>

<xsl:template match="PIX">

<item>

<TRANSACTIONTYPE>

<xsl:value-of select="TransactionType"/>

</TRANSACTIONTYPE>

<TRANSACTIONCODE>

<xsl:value-of select="TransactionCode"/>

</TRANSACTIONCODE>

<TRANSACTIONNUMBER>

<xsl:value-of select="TransactionNumber"/>

</TRANSACTIONNUMBER>

<SEQUENCENUMBER>

<xsl:value-of select="SequenceNumber"/>

</SEQUENCENUMBER>

<xsl:for-each select="SKUDefinition">

<SKUDEFINITION>

<COMPANY>

<xsl:value-of select="Company"/>

</COMPANY>

<DIVISION>

<xsl:value-of select="Division"/>

</DIVISION>

<SEASON/>

<SEASONYEAR/>

<STYLE>

<xsl:value-of select="Style"/>

</STYLE>

<STYLESUFFIX/>

<COLOR>

<xsl:value-of select="Color"/>

</COLOR>

<COLORSUFFIX/>

<SECDIMENSION/>

<QUANTITY/>

<SIZERANGECODE/>

<SIZEDESC>

<xsl:value-of select="SizeDesc"/>

</SIZEDESC>

<SKUID>

<xsl:value-of select="SkuID"/>

</SKUID>

</SKUDEFINITION>

</xsl:for-each>

</item>

</xsl:template>

</xsl:transform>

==================

Below is my main program

===================

TYPE-POOLS abap.

CONSTANTS gs_file TYPE string VALUE 'C:\XMLABAP1.xml'.

  • This is the structure for the data from the XML file

TYPES: BEGIN OF ty_text,

TransactionType(3) type n,

TransactionCode(2) type n,

TransactionNumber(7) type n,

SequenceNumber(5) type n,

Company(3) type c,

Division(3) type c,

Season(3) type c,

SeasonYear(4) type c,

Style(8) type c,

Color(3) type c,

SecDimension(3) type c,

Quality(3) type n,

SizeRangeCode(2) type c,

SizeDesc(1) type c,

SkuID(10) type c,

END OF ty_text.

  • Table for the XML content

DATA: gt_itab TYPE STANDARD TABLE OF char2048.

data: xmlstr TYPE XSTRING.

  • Table and work ares for the data from the XML file

DATA: gt_person TYPE STANDARD TABLE OF ty_text,

gs_person TYPE ty_text.

  • Result table that contains references

  • of the internal tables to be filled

DATA: gt_result_xml TYPE abap_trans_resbind_tab,

gs_result_xml TYPE abap_trans_resbind.

  • For error handling

DATA: gs_rif_ex TYPE REF TO cx_root,

gs_var_text TYPE string.

  • Get the XML file from your client

CALL METHOD cl_gui_frontend_services=>gui_upload

EXPORTING

filename = gs_file

CHANGING

data_tab = gt_itab

EXCEPTIONS

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

invalid_type = 5

no_authority = 6

unknown_error = 7

bad_data_format = 8

header_not_allowed = 9

separator_not_allowed = 10

header_too_long = 11

unknown_dp_error = 12

access_denied = 13

dp_out_of_memory = 14

disk_full = 15

dp_timeout = 16

not_supported_by_gui = 17

error_no_gui = 18

OTHERS = 19.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

  • Fill the result table with a reference to the data table.

  • Within the XSLT stylesheet, the data table can be accessed with

  • "IPERSON".

GET REFERENCE OF gt_person INTO gs_result_xml-value.

gs_result_xml-name = 'IPIX'.

APPEND gs_result_xml TO gt_result_xml.

*

    • Perform the XSLT stylesheet

TRY.

CALL TRANSFORMATION ZAUM_MANH_SYNC_RPT

SOURCE XML XMLSTR

RESULT (gt_result_xml).

CATCH cx_root INTO gs_rif_ex.

gs_var_text = gs_rif_ex->get_text( ).

MESSAGE gs_var_text TYPE 'E'.

ENDTRY.

*

    • Now let's see what we got from the file

*

LOOP AT gt_person INTO gs_person.

WRITE: / 'Transaction Type:', gs_person-TransactionType.

WRITE: / 'Transaction Code :', gs_person-TransactionCode.

WRITE: / 'Transaction Number :', gs_person-TransactionNumber.

WRITE: / 'SequenceNumber :', gs_person-SequenceNumber.

WRITE: / 'Company : ', gs_person-Company.

WRITE : /.

ENDLOOP. "gt_person.

0 Kudos

slight change, pls read "call transformation" as

TRY.

CALL TRANSFORMATION ZAUM_MANH_SYNC_RPT

SOURCE XML gt_itab

RESULT (gt_result_xml).

CATCH cx_root INTO gs_rif_ex.

gs_var_text = gs_rif_ex->get_text( ).

MESSAGE gs_var_text TYPE 'E'.

ENDTRY.

regs,

raja