Application Development and Automation 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: 
Read only

problem converting data in XML file to internal table data

Former Member
0 Likes
3,416

Hi all,

I have a requirement. I need to convert an XML file to internal table data and based on that data do Goods Receipt in SAP.

With the help of this blog /people/r.eijpe/blog/2005/11/10/xml-dom-processing-in-abap-part-i--convert-an-abap-table-into-xml-file-using-sap-dom-approach

I am able to convert the XML file to data in SAP. But this blog will display the output on screen as ELELEMNT = nodename VALUE= value of that node.

But I donu2019t want in that way, I want to store all the data in XML file in an internal table so that I can make use of those values and do Goods Recipt in SAP.

Can some one suggest how should I read the data in an internal table.

Here is my code..what changes should I make?

&----


*& Report z_xit_xml_check

&----


REPORT z_xit_xml_check.

TYPE-POOLS: ixml.

TYPES: BEGIN OF t_xml_line,

data(256) TYPE x,

END OF t_xml_line.

DATA: l_ixml TYPE REF TO if_ixml,

l_streamfactory TYPE REF TO if_ixml_stream_factory,

l_parser TYPE REF TO if_ixml_parser,

l_istream TYPE REF TO if_ixml_istream,

l_document TYPE REF TO if_ixml_document,

l_node TYPE REF TO if_ixml_node,

l_xmldata TYPE string.

DATA: l_elem TYPE REF TO if_ixml_element,

l_root_node TYPE REF TO if_ixml_node,

l_next_node TYPE REF TO if_ixml_node,

l_name TYPE string,

l_iterator TYPE REF TO if_ixml_node_iterator.

DATA: l_xml_table TYPE TABLE OF t_xml_line,

l_xml_line TYPE t_xml_line,

l_xml_table_size TYPE i.

DATA: l_filename TYPE string.

PARAMETERS: pa_file TYPE char1024 DEFAULT 'c:\temp\orders_dtd.xml'.

  • Validation of XML file: Only DTD included in xml document is supported

PARAMETERS: pa_val TYPE char1 AS CHECKBOX.

START-OF-SELECTION.

  • Creating the main iXML factory

l_ixml = cl_ixml=>create( ).

  • Creating a stream factory

l_streamfactory = l_ixml->create_stream_factory( ).

PERFORM get_xml_table CHANGING l_xml_table_size l_xml_table.

  • wrap the table containing the file into a stream

l_istream = l_streamfactory->create_istream_itable( table = l_xml_table

size = l_xml_table_size ).

  • Creating a document

l_document = l_ixml->create_document( ).

  • Create a Parser

l_parser = l_ixml->create_parser( stream_factory = l_streamfactory

istream = l_istream

document = l_document ).

  • Validate a document

IF pa_val EQ 'X'.

l_parser->set_validating( mode = if_ixml_parser=>co_validate ).

ENDIF.

  • Parse the stream

IF l_parser->parse( ) NE 0.

IF l_parser->num_errors( ) NE 0.

DATA: parseerror TYPE REF TO if_ixml_parse_error,

str TYPE string,

i TYPE i,

count TYPE i,

index TYPE i.

count = l_parser->num_errors( ).

WRITE: count, ' parse errors have occured:'.

index = 0.

WHILE index < count.

parseerror = l_parser->get_error( index = index ).

i = parseerror->get_line( ).

WRITE: 'line: ', i.

i = parseerror->get_column( ).

WRITE: 'column: ', i.

str = parseerror->get_reason( ).

WRITE: str.

index = index + 1.

ENDWHILE.

ENDIF.

ENDIF.

  • Process the document

IF l_parser->is_dom_generating( ) EQ 'X'.

PERFORM process_dom USING l_document.

ENDIF.

&----


*& Form get_xml_table

&----


FORM get_xml_table CHANGING l_xml_table_size TYPE i

l_xml_table TYPE STANDARD TABLE.

  • Local variable declaration

DATA: l_len TYPE i,

l_len2 TYPE i,

l_tab TYPE tsfixml,

l_content TYPE string,

l_str1 TYPE string,

c_conv TYPE REF TO cl_abap_conv_in_ce,

l_itab TYPE TABLE OF string.

l_filename = pa_file.

  • upload a file from the client's workstation

CALL METHOD cl_gui_frontend_services=>gui_upload

EXPORTING

filename = l_filename

filetype = 'BIN'

IMPORTING

filelength = l_xml_table_size

CHANGING

data_tab = l_xml_table

EXCEPTIONS

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.

  • Writing the XML document to the screen

CLEAR l_str1.

LOOP AT l_xml_table INTO l_xml_line.

c_conv = cl_abap_conv_in_ce=>create( input = l_xml_line-data replacement = space ).

c_conv->read( IMPORTING data = l_content len = l_len ).

CONCATENATE l_str1 l_content INTO l_str1.

ENDLOOP.

l_str1 = l_str1+0(l_xml_table_size).

SPLIT l_str1 AT cl_abap_char_utilities=>cr_lf INTO TABLE l_itab.

WRITE: /.

WRITE: /' XML File'.

WRITE: /.

LOOP AT l_itab INTO l_str1.

REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>horizontal_tab IN

l_str1 WITH space.

WRITE: / l_str1.

ENDLOOP.

WRITE: /.

ENDFORM. "get_xml_table

&----


*& Form process_dom

&----


FORM process_dom USING document TYPE REF TO if_ixml_document.

DATA: node TYPE REF TO if_ixml_node,

iterator TYPE REF TO if_ixml_node_iterator,

nodemap TYPE REF TO if_ixml_named_node_map,

attr TYPE REF TO if_ixml_node,

name TYPE string,

prefix TYPE string,

value TYPE string,

indent TYPE i,

count TYPE i,

index TYPE i.

node ?= document.

CHECK NOT node IS INITIAL.

ULINE.

WRITE: /.

WRITE: /' DOM-TREE'.

WRITE: /.

IF node IS INITIAL. EXIT. ENDIF.

  • create a node iterator

iterator = node->create_iterator( ).

  • get current node

node = iterator->get_next( ).

  • loop over all nodes

WHILE NOT node IS INITIAL.

indent = node->get_height( ) * 2.

indent = indent + 20.

CASE node->get_type( ).

WHEN if_ixml_node=>co_node_element.

  • element node

name = node->get_name( ).

nodemap = node->get_attributes( ).

WRITE: / 'ELEMENT :'.

WRITE: AT indent name COLOR COL_POSITIVE INVERSE.

IF NOT nodemap IS INITIAL.

  • attributes

count = nodemap->get_length( ).

DO count TIMES.

index = sy-index - 1.

attr = nodemap->get_item( index ).

name = attr->get_name( ).

prefix = attr->get_namespace_prefix( ).

value = attr->get_value( ).

WRITE: / 'ATTRIBUTE:'.

WRITE: AT indent name COLOR COL_HEADING INVERSE, '=',

value COLOR COL_TOTAL INVERSE.

ENDDO.

ENDIF.

WHEN if_ixml_node=>co_node_text OR

if_ixml_node=>co_node_cdata_section.

  • text node

value = node->get_value( ).

WRITE: / 'VALUE :'.

WRITE: AT indent value COLOR COL_GROUP INVERSE.

ENDCASE.

  • advance to next node

node = iterator->get_next( ).

ENDWHILE.

ENDFORM. "process_dom

Any help would be highly apperciated.

regards,

Jessica Sam

12 REPLIES 12
Read only

Former Member
0 Likes
1,677

Hi,

Hope the below link help you out....

https://www.sdn.sap.com/irj/scn/advancedsearch?cat=sdn_all&query=xmlfileintointernaltable+++++&adv=false&sortby=cm_rnd_rankvalue

Pooja

Read only

0 Likes
1,677

Hey pooja,

In all the links that you provided..they all are similar to thomas blog and suggest the code to convert XML data and write it on screen as "Element" and "Value".

My requirement is not to write these values to screen..i need to collect them in an internal table and make use of those values to do Goods reciept in SAP.

If anybody has any clues on converting XML to internal table please suggest.

My XML file is very complex with many parent and child nodes and the child nodes keep occuring more than once and vary from file to file. i need to write a generic code..

Regards,

Jessica Sam

Read only

Former Member
0 Likes
1,677

Hi Jessica,

Though with my minimal knowledge on XML conversion, I would suggest a to use once the below code.

No harm in trying as this is a small piece of code.

TRY.

CALL TRANSFORMATION ('ID')

SOURCE XML v_xmlupl

RESULT tab = i_xml[].

CONDENSE v_xmlupl.

CATCH cx_transformation_error.

  • Write your error message.

ENDTRY.

Here v_xmlupl is your XML string and I_XML is the internal table of the type of data you are expecting in the XML string.

If this does not work then you might have to create your own transformation.

Read only

0 Likes
1,677

Amit,

You want me to inlcude this code in addition to my code?

i am unable to understand, can you please be more clear?

Read only

0 Likes
1,677

Hi Jessica,

I had similar problem with too complex XML file. I do not know if_ixml etc so I cannot help you with your code, but I can write anything about my solution:

(1) I have to write XSLT transformation program - describing structure of XML data, see to my example and you can adjust it to your XML definition. Let's create XSLT program with name ZFI_AVIZA_XXX

<xsl:transform version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- used by progs: Y1T_PV_XMLTEST, ZFI_AVIZA -->

<!-- <xsl:template match="/">
    <xsl:apply-templates />
</xsl:template>
-->

<xsl:template match="statement">
    <xsl:apply-templates select="merchants/merchant"/>
</xsl:template>

<xsl:template match="merchant">
  <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0"><asx:values>
    <AVIZA>
    <xsl:apply-templates select="branches/branch"/>
    </AVIZA>
  </asx:values></asx:abap>
</xsl:template>

<!-- add/del 12.5.2008 -->
<!--
<xsl:template match="branches">
  <xsl:apply-templates select="branch"/>
</xsl:template>
-->
<!-- add 12.5.2008 end -->

<xsl:template match="branch">
  <xsl:apply-templates select="terminals/terminal"/>
</xsl:template>

<xsl:template match="terminal">
  <xsl:variable name="xwaers">
    <xsl:value-of select="currency" />
  </xsl:variable>
  <xsl:variable name="termid">
    <xsl:value-of select="IDs/primaryID" />
  </xsl:variable>

  <xsl:apply-templates select="transactions">
    <xsl:with-param name="xwaers" select="$xwaers" />
    <xsl:with-param name="termid" select="$termid" />
  </xsl:apply-templates>
</xsl:template>

<xsl:template match="transactions">
  <xsl:param name="xwaers"/>
  <xsl:param name="termid"/>
  <xsl:apply-templates select="reportingDay">
    <xsl:with-param name="xwaers" select="$xwaers" />
    <xsl:with-param name="termid" select="$termid" />
  </xsl:apply-templates>
</xsl:template>

<xsl:template match="reportingDay">
    <xsl:param name="xwaers" />
    <xsl:param name="termid" />
    <xsl:variable name="reported">
  <xsl:value-of select="@day" />
    </xsl:variable>
    <xsl:apply-templates select="transaction">
      <xsl:with-param name="xwaers" select="$xwaers" />
      <xsl:with-param name="termid" select="$termid" />
      <xsl:with-param name="xrep" select="$reported" />
    </xsl:apply-templates>
</xsl:template>


<xsl:template match="transaction">
    <xsl:param name="xwaers" />
    <xsl:param name="termid" />
    <xsl:param name="xrep" />
    <item>
      <TERMINAL><xsl:value-of select="$termid" /></TERMINAL>
      <REPORTED><xsl:value-of select="$xrep" /></REPORTED>
      <WAERS><xsl:value-of select="$xwaers" /></WAERS>
      <DTOPEA><xsl:value-of select="DTOPEA" /></DTOPEA>
      <MTTDVO><xsl:value-of select="MTTDVO" /></MTTDVO>
      <MTDVCO><xsl:value-of select="MTDVCO" /></MTDVCO>
      <FEEACC><xsl:value-of select="FEEACC" /></FEEACC>
    </item>
</xsl:template>


</xsl:transform>

Now look to acording ABAP code parts:

At first some declarations:

TYPES: BEGIN OF tt_avizapkuc,
         terminal(20) TYPE c,
         reported(10) TYPE c, " yyyy-mm-dd
         waers TYPE waers,
         dtopea(21) TYPE c,   " yyyy-mm-ddThh:mm:ss
         mttdvo(15) TYPE c,   " brutto value
         mtdvco(15) TYPE c,   " netto value
         feeacc(15) TYPE c,   " fee
       END OF tt_avizapkuc.

DATA: gt_uc_data TYPE STANDARD TABLE OF tt_avizapkuc.
FIELD-SYMBOLS: <fs_ucr> TYPE tt_avizapkuc.

This code extracts required fields from XML data into ABAP internal table. Internal table gt_file contains XML data.

FORM xmltoabap.

  DATA: lt_result_xml TYPE abap_trans_resbind_tab.

  FIELD-SYMBOLS: <lfs_xml> TYPE abap_trans_resbind.

  APPEND INITIAL LINE TO lt_result_xml ASSIGNING <lfs_xml>.
  GET REFERENCE OF gt_uc_data INTO <lfs_xml>-value.
  <lfs_xml>-name = 'AVIZA'.

  CALL TRANSFORMATION zfi_aviza_xxx
     SOURCE XML gt_file
     RESULT (lt_result_xml).

ENDFORM.                    " xmltoabap

Well, it is simple, isn't it?

Prerequisitions:

To know XSLT and ABAP languages

Check your system if last support packages and kernel are applied - it works with packages from 03/2008 and newer

Regards,

Pavel

Read only

0 Likes
1,677

Pavel,

Thanks a lot. Can you show me your XML file so that i can correlate better. my XML file is very complex and will not be constant as the child nodes with in a parent node might be occuring more than once or might occur only once and i need to write a very very generic code.

Can you post your XML file so that i can correlate the XSLT and ABAP pgm and write my pgm for my XML file.

Thanks a lot for ur help.. will be waiting for ur reply

Regards,

JEsssica SAm

Read only

0 Likes
1,677

Hi Jessica,

sorry, I cannot show you XML file, it contains private data. But I think I can create similar one, but please wait ... it's midnight now and I am going to refresh (myself, not internal table). But the base of XML file is DTD description, I'll find it and send it with data file.

Regards,

Pavel

Read only

0 Likes
1,677

Sorry about that..i respect your privacy...i will try to understand the XML file based on ur prgm...

Thanks a lot for your reply.

Jessica Sam

Read only

0 Likes
1,677

Hi Jessica,

look to data file. This file has been edited by hand so I hope it will not be crippled. Note that XSLT can work with XML data with missing subtrees, when a subtree with required value is misssing, transformation simply do not put affected line to abap internal table.

Regards,

Pavel

<?xml version="1.0" encoding="UTF-8"?>
<statement dist-email="email-at-domain.sk"
           fname-prefix="20080124_100035_1775_"
           generated-on="2008-01-25T05:37:26" institution-id="UNB"
           period-end="2008-01-24" period-start="2008-01-24"
           xmlns:zzz="http://firstdata.sk/tol/posman/statement/1.0"
           xmlns:ns="http://firstdata.sk/tol/posman/statement/1.0">
  <merchants>
    <merchant>
      <IDs>
        <primaryID>100035</primaryID>
      </IDs>
      <name>Customer, GMBH</name>
      <merchantNationalID>36621427</merchantNationalID>
      <address type="residence">
        <line1>Customer, GMBH</line1>
        <street>Street 19</street>
        <city>Big City</city>
        <zip>11111</zip>
        <country>SK</country>
      </address>
      <branches>
        <branch>
          <IDs>
            <primaryID>1000351</primaryID>
          </IDs>
          <name>Customer</name>
          <addresses>
            <address type="residence">
              <line1>Customer</line1>
              <street>Another street</street>
              <line3>OC Max</line3>
              <city>Small City</city>
              <zip>01010</zip>
              <country>SK</country>
            </address>
            <address type="statements">
              <line1>Customer</line1>
              <street>Street 007</street>
              <line3>OC Max</line3>
              <city>Small City</city>
              <zip>01010</zip>
              <country>SK</country>
            </address>
          </addresses>
          <terminals>
            <terminal>
              <IDs>
                <primaryID>SN100035101</primaryID>
              </IDs>
              <timMerchantId>21000000517251</timMerchantId>
              <name>Customer</name>
              <account>
                <accountID>0000006618072123</accountID>
                <bankID>1100</bankID>
              </account>
              <currency>EUR</currency>
              <transactions>
                <reportingDay day="2008-01-24">
                  <transaction>
                    <CDRES>1</CDRES>
                    <CETYK>120</CETYK>
                    <DTOPEA>2008-01-24T10:05:10</DTOPEA>
                    <NUISOM>676191******5709</NUISOM>
                    <MTTDVO>473.00</MTTDVO>
                    <MTDVCO>466.85</MTDVCO>
                    <CESMT>1</CESMT>
                    <FEEACC>6.15</FEEACC>
                    <DETYP>1</DETYP>
                    <TXCIP>1.30</TXCIP>
                    <NUAUTO>890963</NUAUTO>
                  </transaction>
                  <transaction>
                    <CDRES>1</CDRES>
                    <CETYK>125</CETYK>
                    <DTOPEA>2008-01-24T10:41:32</DTOPEA>
                    <NUISOM>541597******2975</NUISOM>
                    <MTTDVO>697.00</MTTDVO>
                    <MTDVCO>687.94</MTDVCO>
                    <CESMT>1</CESMT>
                    <FEEACC>9.06</FEEACC>
                    <DETYP>1</DETYP>
                    <TXCIP>1.30</TXCIP>
                    <NUAUTO>509847</NUAUTO>
                  </transaction>
                  <transaction>
                    <CDRES>1</CDRES>
                    <CETYK>120</CETYK>
                    <DTOPEA>2008-01-24T20:57:46</DTOPEA>
                    <NUISOM>676115******2018</NUISOM>
                    <MTTDVO>599.00</MTTDVO>
                    <MTDVCO>591.21</MTDVCO>
                    <CESMT>1</CESMT>
                    <FEEACC>7.79</FEEACC>
                    <DETYP>1</DETYP>
                    <TXCIP>1.30</TXCIP>
                    <NUAUTO>423635</NUAUTO>
                  </transaction>
                </reportingDay>
              </transactions>
            </terminal>
          </terminals>
        </branch>
      </branches>
    </merchant>
  </merchants>
</statement>

Read only

0 Likes
1,677

Pavel Vera,

With your example i tries doing the following .....

I tried to convert the data of XML file to internal table data. I am collecting the data in internal table to do goos recipt with that data.

Please find my XML file, ABAP pgm and XSLT pgm . I donu2019t know what I am missing I am not getting any output. I donu2019t know what is wrong please help me with this

Below is my XML file, My code and XSLT Program. In the below XML file I need to collect Vendor Number, Order Number, and Date tags which occur only once for one XML file.

I also need to collect the following tags from <Shipmentdetail>

<Shipmentdetail> has following child nodes and I need to collect them

TrackingNumber

Freight

Weight

ShipmentDate

ShipmentMethod

Need to collect to collect the following tags from <ProductInformation>

<ProductInformation> has following child nodes and I need to collect them

LineNumber

SKUNumber

OrderedQuantity

ShippedQuantity

UOM

The <Shipmentdetail> and <ProductInformation> are child nodes of <OrderShipment>

The <Shipmentdetail> occurs only ones but the <ProductInformation> can occur once or many times and will be dynamic and differs depening on the input file.

My XML file is as follows

 
 <?xml version="1.0" encoding="iso-8859-1" ?> 
- <ShipmentHeader>
  <AccountID /> 
- <OrderShipment>
      <VendorNumber>1000</VendorNumber> 
      <OrderNumber>P00009238</OrderNumber> 
      <OrderType>Stock</OrderType> 
      <Company /> 
      <Division /> 
     <Department /> 
     <Date>20061120</Date> 
     <CartonCount>2</CartonCount> 
     <ShipAllProducts>No</ShipAllProducts> 
-             <ShipmentDetail>
                  <TrackingNumber>1ZR3W891PG47477811</TrackingNumber> 
                  <Freight>000000010000</Freight> 
                  <ShipmentDate>20061120</ShipmentDate> 
                  <ShipmentMethod>UPS1PS</ShipmentMethod> 
             </ShipmentDetail>
-            <ProductInformation>
                 <LineNumber>000000001</LineNumber> 
                 <SKUNumber>110FR</SKUNumber> 
                 <AdvSKUNumber>003 4518</AdvSKUNumber> 
                 <SKUID /> 
                 <OrderedQuantity>00000001000000</OrderedQuantity> 
                 <ShippedQuantity>00000001000000</ShippedQuantity> 
                 <UOM>EA</UOM> 
                 <Factor>1</Factor> 
            </ProductInformation>
-           <ProductInformation>
                <LineNumber>000000002</LineNumber> 
                <SKUNumber>938EN</SKUNumber> 
                <AdvSKUNumber>001 7294</AdvSKUNumber> 
                <SKUID /> 
                <OrderedQuantity>00000000450000</OrderedQuantity> 
                <ShippedQuantity>00000000450000</ShippedQuantity> 
                <UOM>EA</UOM> 
                <Factor>1</Factor> 
            </ProductInformation>
-           <CaseInformation>
               <LineNumber>000000001</LineNumber> 
               <SKUNumber>110FR</SKUNumber> 
               <AdvSKUNumber>003 4518</AdvSKUNumber> 
               <SKUID /> 
               <SSCCNumber>00000001668000002487</SSCCNumber> 
               <CaseQuantity>00000001000000</CaseQuantity> 
               <UOM>EA</UOM> 
               <Factor>1</Factor> 
             </CaseInformation>
             <CaseInformation>
               <LineNumber>000000001</LineNumber> 
               <SKUNumber>110FR</SKUNumber> 
               <AdvSKUNumber>003 4518</AdvSKUNumber> 
               <SKUID /> 
               <SSCCNumber>00000001668000002487</SSCCNumber> 
               <CaseQuantity>00000001000000</CaseQuantity> 
               <UOM>EA</UOM> 
               <Factor>1</Factor> 
             </CaseInformation>
-  </OrderShipment>
  </ShipmentHeader> 

My Program


TYPE-POOLS abap.

CONSTANTS gs_file TYPE string VALUE 'C:\temp\test.xml'.

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

TYPES: BEGIN OF ts_shipment,
         VendorNumber(10)     TYPE n,
         OrderNumber(20)      TYPE n,
         OrderType(8)         TYPE c,
         Date(8)              TYPE c,

       END OF ts_shipment.

TYPES: BEGIN OF ts_shipmentdetail,
         TrackingNumber(30)     TYPE n,
         Freight(12)            TYPE n,
         Weight(14)             TYPE n,
         ShipmentDate(8)        TYPE c,
         ShipmentMethod(8)      TYPE c,

         END OF ts_shipmentdetail.

TYPES: BEGIN OF ts_productinformation,
         LineNumber(9)          TYPE n,
         SKUNumber(20)          TYPE c,
         OrderedQuantity(14)    TYPE n,
         ShippedQuantity(14)    TYPE n,
         UOM(4)                 TYPE c,

         END OF ts_productinformation.

* Table for the XML content

DATA: gt_itab       TYPE STANDARD TABLE OF char2048.

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

DATA: gt_shipment               TYPE STANDARD TABLE OF ts_shipment,
      gs_shipment               TYPE ts_shipment.

DATA: gt_shipmentdetail         TYPE STANDARD TABLE OF ts_shipmentdetail,
      gs_shipmentdetail         TYPE ts_shipmentdetail.

DATA: gt_productinformation     TYPE STANDARD TABLE OF ts_productinformation,
      gs_productinformation     TYPE ts_productinformation.


* 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
* "ISHIPMENT".

GET REFERENCE OF gt_shipment INTO gs_result_xml-value.
gs_result_xml-name = 'ISHIPMENT'.
APPEND gs_result_xml TO gt_result_xml.

* Fill the result table with a reference to the data table.
* Within the XSLT stylesheet, the data table can be accessed with
* "ISHIPDET".

GET REFERENCE OF gt_shipmentdetail INTO gs_result_xml-value.
gs_result_xml-name = 'ISHIPDET'.
APPEND gs_result_xml TO gt_result_xml.

* Fill the result table with a reference to the data table.
* Within the XSLT stylesheet, the data table can be accessed with
* "IPRODDET".

GET REFERENCE OF gt_productinformation  INTO gs_result_xml-value.
gs_result_xml-name = 'IPRODDET'.
APPEND gs_result_xml TO gt_result_xml.

* Perform the XSLT stylesheet

TRY.

    CALL TRANSFORMATION z_xml_to_abap3
    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.

* Writing the data from file for gt_shipment
*Collecting the Shipping Data from the XML file to internal table gt_shipment
*and writing the data to the screen

LOOP AT gt_shipment INTO gs_shipment.
  WRITE: / 'VendorNumber:', gs_shipment-VendorNumber.
  WRITE: / 'OrderNumber :', gs_shipment-OrderNumber.
  WRITE: / 'OrderType  :', gs_shipment-OrderType.
  WRITE: / 'Date  :',      gs_shipment-Date.

  WRITE : /.
ENDLOOP. "gt_shipment.



LOOP AT gt_shipmentdetail INTO gs_shipmentdetail.
  WRITE: / 'TrackingNumber:',     gs_shipmentdetail-TrackingNumber.
  WRITE: / 'Freight :',           gs_shipmentdetail-Freight.
  WRITE: / 'Weight  :',           gs_shipmentdetail-Weight.
  WRITE: / 'ShipmentDate  :',     gs_shipmentdetail-ShipmentDate.
* WRITE: / 'ShipmentMethod  :'    gs_shipmentdetail-ShipmentMethod

  WRITE : /.
ENDLOOP. "gt_shipmentdetail.



LOOP AT gt_productinformation INTO gs_productinformation.
  WRITE: / 'LineNumber:',         gs_productinformation-LineNumber.
  WRITE: / 'SKUNumber :',         gs_productinformation-SKUNumber.
  WRITE: / 'OrderedQuantity  :',  gs_productinformation-OrderedQuantity.
  WRITE: / 'ShippedQuantity  :',  gs_productinformation-ShippedQuantity.
  WRITE: / 'UOM  :',              gs_productinformation-UOM.
  WRITE : /.
ENDLOOP. "gt_productinformation.

XSLT Program

.



 
 <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>
        <ISHIPMENT>
          <xsl:apply-templates select="//OrderShipment"/>
        </ISHIPMENT>
      </asx:values>
    </asx:abap>
  </xsl:template>

  <xsl:template match="OrderShipment">
    <item>
      <VENDORNUMBER>
        <xsl:value-of select="VendorNumber"/>
      </VENDORNUMBER>
      <ORDERNUMBER>
        <xsl:value-of select="OrderNumber"/>
      </ORDERNUMBER>
      <ORDERTYPE>
        <xsl:value-of select="OrderType"/>
      </ORDERTYPE>
      <DATE>
        <xsl:value-of select="Date"/>
      </DATE>

    </item>
  </xsl:template>

  <xsl:template match="/">
    <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
      <asx:values>
        <ISHIPDET>
          <xsl:apply-templates select="//OrderShipment/ShipmentDetail"/>
        </ISHIPDET>
      </asx:values>
    </asx:abap>
  </xsl:template>

  <xsl:template match="ShipmentDetail">
    <item>
      <TRACKINGNUMBER>
        <xsl:value-of select="TrackingNumber"/>
      </TRACKINGNUMBER>
      <FREIGHT>
        <xsl:value-of select="Freight"/>
      </FREIGHT>
      <SHIPMENTDATE>
        <xsl:value-of select="ShipmentDate"/>
      </SHIPMENTDATE>
      <SHIPMENTMETHOD>
        <xsl:value-of select="ShipmentMethod"/>
      </SHIPMENTMETHOD>

    </item>
  </xsl:template>



</xsl:transform> .

Any help is highly appreciated. If anyone encountered this situation before please let me know where i am going wrong in my XSLT transformation.

Any Help will be highly apppreciated. Thanks in advance

Regards,

Jessica Sam

Read only

Former Member
0 Likes
1,677

Hi,

Try FM BAPI_ALV_XML_LOAD.

Also try the Function Modules in the Function Group CRM_BSP_DESIGNER_XML.

Hope this helps

Regards,

Anki Reddy

Read only

Former Member
0 Likes
1,677

Hi,

Also Check the below Thread

/people/r.eijpe/blog/2005/11/21/xml-dom-processing-in-abap-part-ii--convert-an-xml-file-into-an-abap-table-using-sap-dom-approach

Regards,

Anki Reddy