Xml string  to internal table = change  utf-8 to utf-16

Hello Experts,
I have a requirement to convert XML String to abap intrnal table .
I have to get an xml file from application server using opendataset as
?<?xml version="1.0" encoding="utf-16" standalone=
"yes"?><WPUBON01>## <IDOC BEGIN="1">## <EDI_DC
40 SEGMENT="1">##
while I am getting as
<?xml version="1.0" standalone="yes"?>
<WPUBON01>
<IDOC BEGIN="1">
Please advice how I can change the encoding to UTF-16 .
sun

Hello Experts,
I have a requirement to convert XML String to abap intrnal table .
I have to get an xml file from application server using opendataset as
?<?xml version="1.0" encoding="utf-16" standalone=
"yes"?><WPUBON01>## <IDOC BEGIN="1">## <EDI_DC
40 SEGMENT="1">##
while I am getting as
<?xml version="1.0" standalone="yes"?>
<WPUBON01>
<IDOC BEGIN="1">
Please advice how I can change the encoding to UTF-16 .
sun

Similar Messages

  • Converting XML string to internal table

    Hello everyone,
    I am trying to convert an XML string to an internal table. The format of the XML string is as follows:
    <node label="Compressors" NODE_ID="783" checked="1" expandStatus="false">
       <node label="Nail guns" NODE_ID="78543" checked="1" expandStatus="false"/>
       <node label="Spray guns" NODE_ID="855" checked="0" expandStatus="false"/>
       <node label="Cleaning equipment" NODE_ID="9" checked="1" expandStatus="false"/>
    </node>
    What I need is an internal table with the fields NODE_ID and checked filled. The hierarchy here doesn't matter, so I just need an internal table of a structure with 2 fields. The whole XML is hierarchical and contains only the <node> tag, which can be self-closing or not with the attributes within the tag.
    What is the best way to accomplish this?
    Performance here is quite important too, as this XML can contain over 100,000 nodes.
    Should it be done with an xpath expression, with a regex, with the iXML parser, an XSLT call transformation?
    Any help is greatly appreciated!
    Best regards,
    Vincent

    Use this FM to get into internal table
                CALL FUNCTION 'ECATT_CONV_XSTRING_TO_STRING'
                  EXPORTING
                    im_xstring = zl_attcntx
                  IMPORTING
                    ex_string  = zl_attcont.
       SPLIT zl_attcont AT cl_abap_char_utilities=>newline INTO TABLE zit_legacy.

  • Create XML file from internal table and vise a versa

    Hi Friends,
    I have requirement to create an XML string from internal table data and also read XML string data to internal table.
    Can anybody tell are there any Function Modules or methods existing for this?
    Thanks.
    Krishna Yerram.

    1. Write XSLT program. T.code XSLT . e.g. XSLT name "ZTRANS".
    2. Write ABAP program
    Which includes declaration of internal tables
    that you need "IT_DATA".
    Upload XML data to an internal table "IT_XML "
    use below statement to convert XML to internal table.
    Call transformation ZTRANS
    source XML IT_XML
    result IT_DATA.

  • Problem converting data in XML file to internal table data

    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

    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

  • To convert XML to ABAP internal table can we do it with DOM or we need XSLT

    I have a requirement where I need to collect the data from XML file into an internal table.
    I need to collect this data into an internal table as I should make use of this data and do Goods Receipt in SAP.
    My XML file is very very complex and the child nodes in my XML file may occur ones or 10 times and change dynamically.
    I want to know if XML to ABAP internal table is possible with DOM or does it need XSLT too.
    I used the blog of Robert which uses DOM, but it I am unable to collect the data in internal table. The blog explains only how to wtite the out put to screen as element and value.
    I want to know if XML to ABAP internal table is possible with DOM or do I need XSLT too? I am confused please help.
    Any help will be highly appreciated.
    Regards,
    Jessica Sam

    Hello Jessica
    Why not using the DOM itself for processing?
    Below you see the post-processing coding which I use to add the interchange control number (ICN) into an EDI message (which at this stage is still an XML-EDI stream). This is done on SAP-XI yet on the ABAP stack so you could use this approach on your R/3 system as well.
    method POSTPROCESSING.
    * Post-Processing of outbound EDI invoices & dispatch advices
      me->map_icn( ).
    endmethod.
    method MAP_ICN.
    * define local data
      DATA: lo_node       TYPE REF TO if_ixml_node,
            ld_name       TYPE string,
            ld_value      TYPE string,
            ld_error_code type MPG_ERRCODE,
    **        ld_control_number   TYPE char13,
            ld_rc         TYPE i,
            ld_msg        TYPE string.  " bapi_msg.
      DATA: ld_interface  TYPE string.
      DATA: incode TYPE REF TO if_ixml_node_collection.
      LOG-POINT ID zedi
        SUBKEY mc_subkey_method_trace.
      ld_error_code = md_clsname.
    * Get next interchange control number (ICN)
      me->md_next_number = me->get_next_number(
          id_nrobj  = me->md_nrobj   " Object (SNRO)
          id_nrnr   = me->md_nrnr ). " Number Range
      CALL METHOD zcl_edi_uk_counter=>calculate_modulo_n09
        EXPORTING
          id_input  = me->md_next_number
        receiving
          rd_output = me->md_next_number.
    * Build ICN according to naming conventions agreed with EDI customer
      me->md_icn = me->generate_icn( me->md_next_number ).
      ld_value = me->md_icn.  " type conversion to string
      CLEAR: incode,
             lo_node.
      incode  = me->mo_document->get_elements_by_tag_name( mc_d_0020 ).
      lo_node = incode->get_item( index = 0 ).
      CALL METHOD lo_node->set_value
        EXPORTING
          value = ld_value
        RECEIVING
          rval  = ld_rc.
      IF ( ld_rc NE 0 ).
        CONCATENATE 'Error [' mc_d_0020
                    ']: Method SET_VALUE (IF_IXML_NODE)'
                    INTO ld_msg.
        CONDENSE ld_msg.
        me->mif_trace->trace2( message = ld_msg ).
        RAISE EXCEPTION TYPE cx_mapping_fault
          EXPORTING
    *        textid =
    *        previous =
            error_code = ld_error_code
            error_text = ld_msg.
    **    MESSAGE ld_msg TYPE 'A'.
      ENDIF.
      CLEAR: incode,
             lo_node.
      incode  = me->mo_document->get_elements_by_tag_name( mc_d_0020_2 ).  " element for ICN
      lo_node = incode->get_item( index = 0 ).
      CALL METHOD lo_node->set_value
        EXPORTING
          value = ld_value
        RECEIVING
          rval  = ld_rc.
      IF ( ld_rc NE 0 ).
        CONCATENATE 'Error [' mc_d_0020_2
                    ']: Method SET_VALUE (IF_IXML_NODE)'
                    INTO ld_msg.
        CONDENSE ld_msg.
        me->mif_trace->trace2( message = ld_msg ).
        RAISE EXCEPTION TYPE cx_mapping_fault
          EXPORTING
    *        textid =
    *        previous =
            error_code = ld_error_code
            error_text = ld_msg.
    **    MESSAGE ld_msg TYPE 'A'.
      ENDIF.
    * define local data
      DATA: ls_record       TYPE mpp_dynamic.
      CLEAR: ls_record.
      ls_record-namespace = mc_dynamic_namespace.
      ls_record-name      = mc_icn.
      ls_record-value     = ld_value.
      mif_dynamic->add_record( ls_record ).
    endmethod.
    In your case you would need to do a DO...ENDDO loop until you parsed all required nodes.
    NOTE: ME->MO_DOCUMENT is of TYPE REF TO IF_IXML_DOCUMENT.
    Regards
       Uwe

  • Convert XML values to internal table

    Hi Experts
    How can i convert XML values to internal table . i am getting all the values into the string.
    this is my example
    <?xml version="1.0" encoding="UTF-8"?><TEST><ZTEST><DEPTNO>HEADOFFICE</DEPTNO><DNAME>IT</DNAME><LOC>HYD</LOC><MANDT>003</MANDT></ZTEST></TEST>
    i did create internal table with 4 fields.
    Please help.

    XML DOM Processing in ABAP part I -  Convert an ABAP table into XML file using SAP DOM Approach.

  • How to convert xml file into internal table in ABAP Mapping.

    Hi All,
    I am trying with ABAP mapping. I have one scenario in which I'm using below xml file as a sender from my FTP server.
    <?xml version="1.0" encoding="UTF-8" ?>
    - <ns0:MTO_ABAP_MAPPING xmlns:ns0="http://Capgemini/Mumbai/sarsingh">
      <BookingCode>2KY34R</BookingCode>
    - <Passenger>
      <Name>SARVESH</Name>
      <Address>THANE</Address>
      </Passenger>
    - <Passenger>
      <Name>RAJESH</Name>
      <Address>POWAI</Address>
      </Passenger>
    - <Passenger>
      <Name>CARRON</Name>
      <Address>JUHU</Address>
      </Passenger>
    - <Flight>
      <Date>03/03/07</Date>
      <AirlineID>UA</AirlineID>
      <FlightNumber>125</FlightNumber>
      <From>LAS</From>
      <To>SFO</To>
      </Flight>
      </ns0:MTO_ABAP_MAPPING>
    AT the receiver side I wnat to concatenate the NAME & ADDRESS.
    I tried Robert Eijpe's weblog (/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)
    but couldnt succeed to convert the xml file into internal table perfectly.
    Can anybody help on this. 
    Thanks in advance!!
    Sarvesh

    Hi Sarvesh,
    The pdf has details of ABAP mapping. The example given almost matches the xml file you want to be converted.
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/xi/3.0/how to use abap-mapping in xi 3.0.pdf
    Just in case you have not seen this
    regards
    Vijaya

  • How to Download XML File to internal table

    Hi Friends,
    This is my urgent requirement. How to download XML File to Internal table.
    regards
    pauldharma

    Hai,
    Please check this Link
    http://www.sap-img.com/abap/upload-direct-excel.htm
    PARAMETERS: filename LIKE rlgrap-filename MEMORY ID M01,
                begcol TYPE i DEFAULT 1 NO-DISPLAY,
                begrow TYPE i DEFAULT 1 NO-DISPLAY,
                endcol TYPE i DEFAULT 100 NO-DISPLAY,
                endrow TYPE i DEFAULT 32000 NO-DISPLAY.
    * Tick don't append header
    PARAMETERS: kzheader AS CHECKBOX.
    DATA: BEGIN OF intern OCCURS 0.
            INCLUDE STRUCTURE  alsmex_tabline.
    DATA: END OF intern.
    DATA: BEGIN OF intern1 OCCURS 0.
            INCLUDE STRUCTURE  alsmex_tabline.
    DATA: END OF intern1.
    DATA: BEGIN OF t_col OCCURS 0,
           col LIKE alsmex_tabline-col,
           size TYPE i.
    DATA: END OF t_col.
    DATA: zwlen TYPE i,
          zwlines TYPE i.
    DATA: BEGIN OF fieldnames OCCURS 3,
            title(60),
            table(6),
            field(10),
            kz(1),
          END OF fieldnames.
    * No of columns
    DATA: BEGIN OF data_tab OCCURS 0,
           value_0001(50),
           value_0002(50),
           value_0003(50),
           value_0004(50),
           value_0005(50),
           value_0006(50),
           value_0007(50),
           value_0008(50),
           value_0009(50),
           value_0010(50),
           value_0011(50),
           value_0012(50),
           value_0013(50),
           value_0014(50),
           value_0015(50),
           value_0016(50),
           value_0017(50),
           value_0018(50),
           value_0019(50),
           value_0020(50),
           value_0021(50),
           value_0022(50),
           value_0023(50),
           value_0024(50),
           value_0025(50),
           value_0026(50),
           value_0027(50),
           value_0028(50),
           value_0029(50),
           value_0030(50),
           value_0031(50),
           value_0032(50),
           value_0033(50),
           value_0034(50),
           value_0035(50),
           value_0036(50),
           value_0037(50),
           value_0038(50),
           value_0039(50),
           value_0040(50),
           value_0041(50),
           value_0042(50),
           value_0043(50),
           value_0044(50),
           value_0045(50),
           value_0046(50),
           value_0047(50),
           value_0048(50),
           value_0049(50),
           value_0050(50),
           value_0051(50),
           value_0052(50),
           value_0053(50),
           value_0054(50),
           value_0055(50),
           value_0056(50),
           value_0057(50),
           value_0058(50),
           value_0059(50),
           value_0060(50),
           value_0061(50),
           value_0062(50),
           value_0063(50),
           value_0064(50),
           value_0065(50),
           value_0066(50),
           value_0067(50),
           value_0068(50),
           value_0069(50),
           value_0070(50),
           value_0071(50),
           value_0072(50),
           value_0073(50),
           value_0074(50),
           value_0075(50),
           value_0076(50),
           value_0077(50),
           value_0078(50),
           value_0079(50),
           value_0080(50),
           value_0081(50),
           value_0082(50),
           value_0083(50),
           value_0084(50),
           value_0085(50),
           value_0086(50),
           value_0087(50),
           value_0088(50),
           value_0089(50),
           value_0090(50),
           value_0091(50),
           value_0092(50),
           value_0093(50),
           value_0094(50),
           value_0095(50),
           value_0096(50),
           value_0097(50),
           value_0098(50),
           value_0099(50),
           value_0100(50).
    DATA: END OF data_tab.
    DATA: tind(4) TYPE n.
    DATA: zwfeld(19).
    FIELD-SYMBOLS: <fs1>.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR filename.
      CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
           EXPORTING
                mask      = '*.xls'
                static    = 'X'
           CHANGING
                file_name = filename.
    START-OF-SELECTION.
      CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
           EXPORTING
                filename                = filename
                i_begin_col             = begcol
                i_begin_row             = begrow
                i_end_col               = endcol
                i_end_row               = endrow
           TABLES
                intern                  = intern
           EXCEPTIONS
                inconsistent_parameters = 1
                upload_ole              = 2
                OTHERS                  = 3.
      IF sy-subrc <> 0.
        WRITE:/ 'Upload Error ', SY-SUBRC.
      ENDIF.
    END-OF-SELECTION.
      LOOP AT intern.
        intern1 = intern.
        CLEAR intern1-row.
        APPEND intern1.
      ENDLOOP.
      SORT intern1 BY col.
      LOOP AT intern1.
        AT NEW col.
          t_col-col = intern1-col.
          APPEND t_col.
        ENDAT.
        zwlen = strlen( intern1-value ).
        READ TABLE t_col WITH KEY col = intern1-col.
        IF sy-subrc EQ 0.
          IF zwlen > t_col-size.
            t_col-size = zwlen.
    *                          Internal Table, Current Row Index
            MODIFY t_col INDEX sy-tabix.
          ENDIF.
        ENDIF.
      ENDLOOP.
      DESCRIBE TABLE t_col LINES zwlines.
      SORT intern BY row col.
      IF kzheader = 'X'.
        LOOP AT intern.
          fieldnames-title = intern-value.
          APPEND fieldnames.
          AT END OF row.
            EXIT.
          ENDAT.
        ENDLOOP.
      ELSE.
        DO zwlines TIMES.
          WRITE sy-index TO fieldnames-title.
          APPEND fieldnames.
        ENDDO.
      ENDIF.
      SORT intern BY row col.
      LOOP AT intern.
        IF kzheader = 'X'
        AND intern-row = 1.
          CONTINUE.
        ENDIF.
        tind = intern-col.
        CONCATENATE 'DATA_TAB-VALUE_' tind INTO zwfeld.
        ASSIGN (zwfeld) TO <fs1>.
        <fs1> = intern-value.
        AT END OF row.
          APPEND data_tab.
          CLEAR data_tab.
        ENDAT.
      ENDLOOP.
      CALL FUNCTION 'DISPLAY_BASIC_LIST'
           EXPORTING
                file_name     = filename
           TABLES
                data_tab      = data_tab
                fieldname_tab = fieldnames.
    *-- End of Program
    http://sap.ittoolbox.com/groups/technical-functional/sap-dev/excel-file-download-to-an-internal-table-in-sap-crm-1719453#
    tables: zinv_release,
    zpo_release.
    ** decleration of data
    DATA: BEGIN OF my_tab OCCURS 0.
    INCLUDE STRUCTURE zinv_release.
    DATA: END OF my_tab.
    *DATA: hex_tab TYPE x VALUE '09'.
    DATA: rec(200)."'/usr/test.dat'.
    DATA:
    zhours(20) TYPE c,
    MINS(20) type c. "decimals.
    data: coma.
    coma = ','.
    SELECTION-SCREEN BEGIN OF BLOCK txt
    WITH FRAME TITLE text-001.
    PARAMETERS: dsn(60) DEFAULT '\\sapdev01\prod\'.
    SELECTION-SCREEN END
    OF BLOCK txt.
    *using a dataset to get text
    OPEN DATASET dsn FOR INPUT IN TEXT MODE.
    IF sy-subrc = 0.
    DO.
    READ DATASET dsn INTO rec.
    IF sy-subrc <> 0.
    EXIT.
    ENDIF.
    split rec at coma into
    zpo_release-REL_GRP
    zpo_release-REL_CODE
    zpo_release-RESPREL
    zpo_release-ALTREL
    zpo_release-MANAGER
    ZHOURS
    MINS
    zpo_release-FROMTIME
    zpo_release-TOTIME
    zpo_release-EXCLWKENDS.
    move zpo_release-REL_GRP to my_tab-REL_GRP.
    move zpo_release-REL_CODE to my_tab-REL_CODE.
    move zpo_release-RESPREL to my_tab-RESPREL.
    move zpo_release-ALTREL to my_tab-ALTREL.
    move zpo_release-MANAGER to my_tab-MANAGER.
    move ZHOURS to my_tab-ZHOURS.
    move MINS to my_tab-mins.
    move zpo_release-FROMTIME to my_tab-fromtime.
    move zpo_release-TOTIME to my_tab-totime.
    move zpo_release-EXCLWKENDS to my_tab-exclwkends.
    APPEND my_tab.
    ENDDO.
    INSERT zpo_release FROM TABLE my_tab ACCEPTING DUPLICATE KEYS.
    ** DELETE zmm_ppa_cc FROM TABLE tab.
    ** INSERT zzzak_emp FROM TABLE my_tab ACCEPTING DUPLICATE KEYS.
    IF sy-subrc = 0.
    MESSAGE i000(zv) WITH 'File Successful stored in DB.' '' '' ''.
    ** ELSE.
    MESSAGE i000(zv) WITH 'File already stored in DB.' '' '' ''.
    endif.
    ENDIF.
    reward if helpful
    raam

  • Xml to abap internal table by using a dynamic internal table at runtime

    Hi ,
          I have a requirement to convert xml to abap internal table . But the requirement is that i need to create internal table according to the XML .
    Ex : If my XML is :
    <?xml version="1.0" ?>
    - <flights>
    - <airline code="AA" name="American Airlines">
    - <flight number="0017">
      <from airport="JFK">NEW YORK,US</from>
      <to airport="SFO">SAN FRANCISCO,US</to>
      <departure>110000</departure>
      <arrival>140100</arrival>
      <type>Scheduled</type>
      </flight>
    - <flight number="0064">
      <from airport="SFO">SAN FRANCISCO,US</from>
      <to airport="JFK">NEW YORK,US</to>
      <departure>090000</departure>
      <arrival>172100</arrival>
      <type>Scheduled</type>
      </flight>
      </airline>
    So after conversion my abap internal table shoul have fields as :
    airline_code     Name      flight_number   from_airport    to_airport      departure         arrival      type
    and the field values should be corresponding field values .
    Thanks in advance .
    Regards .

    Hi Ujjwal,
    use
    CALL TRANSFORMATION
    Study the online documentation and if required do some search for CALL TRANSFORMATION and/or XML PARSER
    And, when coming back here with next question, tell us what searches you did with what results - please always follow the 'search before post' rule, thank you.
    Regards,
    Clemens

  • Xml to ABAP internal table mapping and schema validation

    Hi Experts,
    I'm trying to get data from an xml file into internal tables in ABAP. My requirement is to validate xml against an xsd schema, how can i do it?
    My other question is, if there are any possible ways to map the fields of a table so that once the xml file is read, the fields automatically get populated depending on the different elements and attributes in the xml file.
    -joe

    Hi,
    check out :
    http://help.sap.com/saphelp_nw70/helpdata/en/fd/9d734b389211d596a200a0c94260a5/frameset.htm
    Terry

  • Error in xml to abap internal table transformation using xslt_tool

    Hi friends,
    When i am trying to convert xml data into internal table it is going to dump because of empty elements. Can any body help to delete the empty tags from xml before processing through xslt_tool.
    example
    <Activity>
    <ID>add12095</ID>
    <Start>09/01/2014 12:01</Start>
    <Type>3</Type>
    <Code>99202</Code>
    <Quantity>1</Quantity>
    <Net>244</Net>
    <Clinician>GD16130</Clinician>
    <PriorAuthorizationID/>                                        "empty tag
    <Gross>294</Gross>
    <PatientShare>50</PatientShare>
    <PaymentAmount>244</PaymentAmount>
    </Activity>
    the empty element some times will come in the xml and some times not. so i made a check in xslt. when this empty element tag processed through that condition i am getting the dump. either i need to remove the condition or we should delete the empty tags before processing. Removing of if condition is not possible because that element may or may not come all the time.
    Regards,
    Rajesh.

    You can replace all empty tags using regular expression.
    REPLACE ALL OCCURRENCES OF REGEX '<\w+/>' IN lv_xml WITH ''.

  • Xml data into internal table

    Hi Friends,
    See the followong code which converts xml data into itab.
    *& Report  ZTEST_XML1                                                  *
    REPORT  ZTEST_XML1                              .
    *PURPOSE: This program transfers XML data into SAP internal table format
    *The nodes in DOM can be stored as fields in SAP Internal table
    type pool definitions
    TYPE-POOLS: ixml. "iXML Library Types
    type definitions
    TYPES: BEGIN OF t_xml_line, "Structure for holding XML data
    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, " XML Table of the structure
    *t_xml_line
    l_xml_line TYPE t_xml_line, " Record of structure t_xml_line
    l_xml_table_size TYPE i. " XML table size
    DATA: l_filename TYPE string. " String to hold filename
    data: begin of i_final occurs 0,
          pnumber(20),
          pname(50),
          pdes(70),
          end of i_final.
    PARAMETERS: pa_file TYPE char1024 DEFAULT 'C:\product.xml'.
    Validation of XML file: Only DTD included in XML document is supported
    PARAMETERS: pa_val TYPE char1 AS CHECKBOX.
    start of selection
    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( ).
    Creating a Parser
    l_parser = l_ixml->create_parser( stream_factory = l_streamfactory
    istream = l_istream
    document = l_document ).
    Validate a document
    IF pa_val = 'X'.
    l_parser->set_validating( mode = if_ixml_parser=>co_validate ).
    ENDIF.
    Parse the stream
    IF l_parser->parse( ) <> 0.
    IF l_parser->num_errors( ) <> 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
    text
    <--P_L_XML_TABLE_SIZE text
    <--P_L_XML_TABLE text
    FORM get_xml_table CHANGING p_l_xml_table_size
    p_l_xml_table.
    Local variable declarations
    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 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
    text
    -->P_L_DOCUMENT text
    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.
    *delete adjacent duplicates from  i_final.
    *loop at i_final.
    *write:/ i_final-pnumber,i_final-pname,i_final-pdes.
    *endloop.
    *if not i_final[] is initial.
    *modify ztestproduct from table i_final.
    *endif.
    ENDFORM. " process_dom
    in the above code at line no: 268 there is a method:
    value = node->get_value( ).in which actual data from XML file is coming.
    So the varibale "Value" contains the data.
    see line no: 270:
    WRITE: AT indent value COLOR COL_GROUP INVERSE.
    what ever values i am getting here i want to append to a Internal table ...
    Can any body tell me how to do that?
    i am sure of reward points.

    Hai Ravi
    REPORT abc.
    DATA
    DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
    DATA : BEGIN OF itab OCCURS 0,
    a(100) TYPE c,
    END OF itab.
    DATA: xml_out TYPE string .
    DATA : BEGIN OF upl OCCURS 0,
    f(255) TYPE c,
    END OF upl.
    DATA: xmlupl TYPE string .
    FIRST PHASE
    FIRST PHASE
    FIRST PHASE
    Fetch Data
    SELECT * FROM t001 INTO TABLE t001.
    XML
    CALL TRANSFORMATION ('ID')
    SOURCE tab = t001[]
    RESULT XML xml_out.
    Convert to TABLE
    CALL FUNCTION 'HR_EFI_CONVERT_STRING_TO_TABLE'
    EXPORTING
    i_string = xml_out
    i_tabline_length = 100
    TABLES
    et_table = itab.
    Download
    CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
    filetype = 'BIN'
    filename = 'd:\xx.xml'
    TABLES
    data_tab = itab.
    SECOND PHASE
    SECOND PHASE
    SECOND PHASE
    BREAK-POINT.
    REFRESH t001.
    CLEAR t001.
    CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
    filename = 'D:\XX.XML'
    filetype = 'BIN'
    TABLES
    data_tab = upl.
    LOOP AT upl.
    CONCATENATE xmlupl upl-f INTO xmlupl.
    ENDLOOP.
    XML
    CALL TRANSFORMATION ('ID')
    SOURCE XML xmlupl
    RESULT tab = t001[].
    Regards
    Sreeni

  • XML file to Internal table through XSLT - Call Transformation

    Hi Friends,
    I am trying to work a scenario where i have a simple XML file and i need to convert the data in to an internal table. When i execute the XSLT seperately, it works fine. I get the output, but when it is invoked through a ABAP program, i am getting the error "The called method START_XSLT_DEBUGGER of the calss CL_WB_XSLT_DEBUGGER returned the exception CX_XSLT_FORMAT_ERROR"
    I feel my XSLT program is not correct, but i am unable to find out what the issue is. Any help is really apreciated. I have gone through the SDN forum replies. But could not figure out what is wrong with my program
    Below given are the details.
    My XML File:
    <?xml version="1.0" encoding="utf-8"?>
    <List>
      <ITEM>
        <ITEMQUALF>ITEM1</ITEMQUALF>
        <MATERIAL>MAT1</MATERIAL>
      </ITEM>
      <ITEM>
        <ITEMQUALF>ITEM2</ITEMQUALF>
        <MATERIAL>MAT2</MATERIAL>
      </ITEM>
      <ITEM>
        <ITEMQUALF>ITEM3</ITEMQUALF>
        <MATERIAL>MAT3</MATERIAL>
      </ITEM>
    </List>
    My XSLT program:
    <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" xmlns:asx="http://www.sap.com/abapxml" exclude-result-prefixes="asx" version="1.0">
      <xsl:strip-space elements="*"/>
      <xsl:output encoding="utf-8" indent="yes" omit-xml-declaration="yes"/>
      <!--xsl:template match="/"-->
      <xsl:template match="List">
        <asx:abap version="1.0">
          <asx:values>
            <T_ACTUAL>
              <xsl:for-each select="*">
                <ITEMQUALF>
                  <xsl:value-of select="ITEMQUALF" />
                </ITEMQUALF>
                <MATERIAL>
                  <xsl:value-of select="MATERIAL" />
                </MATERIAL>
              </xsl:for-each>
            </T_ACTUAL>
          </asx:values>
        </asx:abap>
      </xsl:template>
    </xsl:transform>
    In my ABAP program:
    REPORT  z_xslt_abap_2.
    TYPES:
      BEGIN OF ty_actual,
        itemqualf   TYPE char50,
        material    TYPE char50,
      END OF ty_actual,
      line_t(4096)  TYPE x,
      table_t       TYPE STANDARD TABLE OF line_t,
      ty_t_actual   TYPE STANDARD TABLE OF ty_actual.
    DATA:
      t_actual    TYPE ty_t_actual,
      t_srctab    TYPE table_t,
      v_filename  TYPE string.
    DATA: gs_rif_ex     TYPE REF TO cx_root,
          gs_var_text   TYPE string.
    v_filename = 'D:\XML\xslt_test.xml'.
    * Function call
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        filename = v_filename
        filetype = 'BIN'
      TABLES
        data_tab = t_srctab
      EXCEPTIONS
        OTHERS   = 1.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    * Call Transformation
    TRY.
        CALL TRANSFORMATION (`ZXSLT_RAM`)
                SOURCE XML t_srctab
                RESULT     t_actual = t_actual.
      CATCH cx_root INTO gs_rif_ex.
        gs_var_text = gs_rif_ex->get_text( ).
        MESSAGE gs_var_text TYPE 'E'.
    ENDTRY .
    IF t_actual IS NOT INITIAL.
      WRITE: 'Success'.
    ENDIF.
    When i run the XSLT program seperately, this is the output that i get:
    <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
      <asx:values>
        <T_ACTUAL>
          <ITEMQUALF>ITEM1</ITEMQUALF>
          <MATERIAL>MAT1</MATERIAL>
          <ITEMQUALF>ITEM2</ITEMQUALF>
          <MATERIAL>MAT2</MATERIAL>
          <ITEMQUALF>ITEM3</ITEMQUALF>
          <MATERIAL>MAT3</MATERIAL>
        </T_ACTUAL>
      </asx:values>
    </asx:abap>
    I have been stuck with this for more than two days. If anyone can help me out with this, it would be really great. Please let me know, where i am going wrong.
    Thanks in advance.
    Best Regards,
    Ram.

    Hi,
    You can try this sample program, hopefully will help you.
    <a href="https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/readdatafromXMLfileviaXSLT+program&">Read Data From XML</a>.
    Regards,

  • Convert XML to SAP internal table

    Hi gurus,
    My program is suppose to get current exchange rate file from website and upload it in SAP.
    by using FM 'HTTP_GET', im getting the data in XML format.My problem is..i have tried to use transformation but failed to
    map it against XML data element..and i have tried to use CALL FUNCTION 'SCMS_TEXT_TO_XSTRING' and then CALL FUNCTION 'SMUM_XML_PARSE' but it returns initial value with error ''line   0 col  12-unexpected symbol: '>'' .
    Below is an excerpt of my XML file:
    ..<xml version>
    ..<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
    .. xmlns:o="urn:schemas-microsoft-com:office:office"
    .. xmlns:x="urn:schemas-    microsoft-com:office:excel"
    .. xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
    .. <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel"> <WindowHeight>10875</WindowHeight>........ <WindowWidth>13260</WindowWidth><WindowTopX>480</WindowTopX><WindowTopY>30</Wind
    ..  <Style ss:ID="Default" ss:Name="Normal">
    ..  <Alignment ss:Vertical="Bottom"/>
    ..  <Borders/>
    ..  <Font/>
    ..  <Interior/>
    ..  <NumberFormat/>
    ..  <Protection/>
    ..  </Style>
    ..  <Style ss:ID="BoldColumn">
    ..  <Font ss:FontName="Microsoft Sans Serif" x:Family="Swiss" ss:Bold="1"/>
    .. <Worksheet ss:Name="Page1"><Table ss:StyleID="s21"   > <Column   ss:Width="130"/> <Column   ss:Width="85"/> <Column   .. ss:Width="85"/> <Column   ss:Width="85"/> <Column   ss:Widt
    .. Cell><Cell ss:MergeAcross="1" ss:StyleID="BoldColumn"><Data ss:Type="String">Average Buying Rates</Data></Cell><Cell .. ss:MergeDown="1" ss:StyleID="BoldColumn"><Data ss:Type="Stri
    .. ss:Type="Number">47.3732</Data></Cell><Cell ss:StyleID="Decimal"><Data ss:Type="Number">47.5374</Data></Cell><Cell .. ss:StyleID="Decimal"><Data ss:Type="Number">48.2323</Data></Ce
    .. "  ><Data ss:Type="String">HONG KONG</Data></Cell><Cell ss:StyleID="StringLiteralCenter"  ><Data .. .. ss:Type="String">HKD</Data></Cell><Cell ss:StyleID="Decimal"><Data ss:Type="Numb
    .. ss:Type="Number">22.8131</Data></Cell><Cell ss:StyleID="Decimal"><Data ss:Type="Number">23.2595</Data></Cell>.. .. </Row><Row><Cell ss:StyleID="StringLiteral"  ><Data ss:Type="String"
    .. ss:StyleID="StringLiteralCenter"  ><Data ss:Type="String">IDR</Data></Cell><Cell ss:StyleID="Decimal"><Data .. ss:Type="Number">3.0395</Data></Cell><Cell ss:StyleID="Decimal"><Data
    .. ecimal"><Data ss:Type="Number">30.6424</Data></Cell></Row><Row><Cell ss:StyleID="StringLiteral"  ><Data .. ss:Type="String">AUSTRALIA</Data></Cell><Cell ss:StyleID="StringLiteralCe
    .. ell ss:StyleID="Decimal"><Data ss:Type="Number">0.3392</Data></Cell><Cell ss:StyleID="Decimal"><Data .. ss:Type="Number">0.3409</Data></Cell><Cell ss:StyleID="Decimal"><Data ss:Typ
    .. StringLiteral"  ><Data ss:Type="String">DENMARK</Data></Cell><Cell ss:StyleID="StringLiteralCenter"  ><Data .. ss:Type="String">DKK</Data></Cell><Cell ss:StyleID="Decimal"><Data ss
    .. ata ss:Type="Number">4.4550</Data></Cell><Cell ss:StyleID="Decimal"><Data ss:Type="Number">4.6073</Data></Cell>.. </Row><Row></Row><Row></Row><Row><Cell ss:MergeAcross="4" ss:Style
    .. s of   23 November 2010</Data></Cell></Row><Row></Row><Row><Cell ss:MergeAcross="4" .. ss:StyleID="BoldColumn_Left" ><Data ss:Type="String">2. Foreign Exchange Rates (THOMSON REUTE
    ..  ><Data ss:Type="String">ZAR</Data></Cell><Cell ss:StyleID="Decimal"><Data ss:Type="Number">4.2735</Data></Cell>.. <Cell ss:StyleID="Decimal"><Data ss:Type="Number">4.3125</Data></
    .. ="Decimal"><Data ss:Type="Number">106.5459</Data></Cell><Cell ss:StyleID="Decimal"><Data .. ss:Type="Number">107.5164</Data></Cell></Row><Row><Cell ss:StyleID="StringLiteral"  ><Da
    .. a></Cell><Cell ss:StyleID="Decimal"><Data ss:Type="Number">4.6916</Data></Cell></Row><Row><Cell .. ss:StyleID="StringLiteral"  ><Data ss:Type="String">BANGLADESH</Data></Cell><Cell
    .. r">0.0074</Data></Cell></Row><Row><Cell ss:StyleID="StringLiteral"  ><Data ss:Type="String">KENYA</Data></Cell><Cell .. ss:StyleID="StringLiteralCenter"  ><Data ss:Type="String">KE
    .. ><Cell ss:StyleID="StringLiteral"  ><Data ss:Type="String">VIET NAM</Data></Cell><Cell ss:StyleID="StringLiteralCenter"  >.. <Data ss:Type="String">VND</Data></Cell><Cell ss:StyleI
    .. A</Data></Cell><Cell ss:StyleID="StringLiteralCenter"  ><Data ss:Type="String">LKR</Data></Cell><Cell .. .. ss:StyleID="Decimal"><Data ss:Type="Number">0.2686</Data></Cell><Cell ss:St
    .. String">OMR</Data></Cell><Cell ss:StyleID="Decimal"><Data ss:Type="Number">77.7094</Data></Cell><Cell
    Please help me to translate my XML file into SAP format...i need it fixed urgently..
    Edited by: Guest101 on Dec 28, 2010 12:11 PM

    It has 2 part one is source code and another is the XML file
    create an XML file with the data provided in the last 2.
    then place it in a path mention the path in the below source.
    1. Complete code for converting XML to internal table in SAP.
    *& Report  ZTST_PGM02
    REPORT  ZTST_PGM02.
    Load iXML Lib.
    type-pools: ixml.
    class cl_ixml definition load.
    data: G_IXML type ref to if_ixml.
    data: STREAMFACTORY type ref to if_ixml_stream_factory.
    data: ISTREAM type ref to if_ixml_istream.
    data: DOCUMENT type ref to if_ixml_document.
    data: PARSER type ref to if_ixml_parser.
    data: LV_FILE_URL type rlgrap-filename.
    You should provide the parameter for file name
    LV_FILE_URL = 'D:\navps\input_xml.xml'.
    types: begin of XML_LINE,
            DATA(256) type x,
          end of XML_LINE.
    types: begin of TY_HEADER,
             CUST_NAME(20)     type c,
             CARD_NO(20)       type c,
             TAX_AMOUNT(10)    type c,
             TOTAL_AMOUNT(10)  type c,
           end of TY_HEADER.
    types: begin of TY_ITEM,
             ITEM_NO(4)      type n,
             ITEM_ID(20)     type c,
             ITEM_TITLE(50)  type c,
             ITEM_QTY(10)    type c,
             ITEM_UPRICE(10) type c,
           end of TY_ITEM.
    data: GV_HEADER type TY_HEADER.
    data: GT_ITEM   type standard table of TY_ITEM  with header line.
    data: XML_TABLE      type table of XML_LINE,
          XML_TABLE_SIZE type i.
    The next step is creating the main factory for the iXML library:
    G_IXML = cl_ixml=>create( ).
    Now Create Stream Factory
    STREAMFACTORY = G_IXML->create_stream_factory( ).
    upload a file from the client's workstation
    call function 'WS_UPLOAD'
         exporting
              filename   = LV_FILE_URL
              filetype   = 'BIN'
         importing
              filelength = XML_TABLE_SIZE
         tables
              data_tab   = XML_TABLE
         exceptions
              others     = 11.
    wrap the table containing the file into a stream
    ISTREAM = STREAMFACTORY->create_istream_itable( table = XML_TABLE
                                                    size  = XML_TABLE_SIZE )
    Get the file data as Stream
    *istream = streamfactory->create_istream_uri( public_id = lv_file_url
                                                system_id = lv_file_url ).
    Create XML Document instance
    DOCUMENT = G_IXML->create_document( ).
    Create parser Object
    PARSER = G_IXML->create_parser( stream_factory = STREAMFACTORY
                                    ISTREAM = istream
                                    DOCUMENT = document ).
    Parse an XML document into a DOM tree
    *parser->parse( ).
    Parsing Error Processing
    if PARSER->parse( ) ne 0.
      if 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 = PARSER->num_errors( ).
        write: COUNT, ' parse errors have occured:'.
        INDEX = 0.
        while INDEX < COUNT.
          PARSEERROR = 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.
    Close the stream since it #s not needed anymore
    call method ISTREAM->close( ).
    clear ISTREAM.
    Now try to make it look good
    data : lv_size     type sytabix,
            lv_ret_code type sysubrc.
    data: lo_xml_document type ref to cl_xml_document.
    field-symbols: <fs_xml_data> type any table.
    lo_xml_document = document.
    call method lo_xml_document->get_as_table
       importing
         table   = <fs_xml_data>
         size    = lv_size
         retcode = lv_ret_code
    *data: items type ref to if_ixml_node_collection.
    *items = document->get_elements_by_tag_name( name = 'Item' ).
    *data: iterator type ref to if_ixml_node_iterator,
         node     type ref to if_ixml_node.
    *iterator = document->create_iterator( ).
    *node = iterator->get_next( ).
    *while not node is initial.
    do something with the node
    node = iterator->get_next( ).
    *endwhile.
    DATA : GV_NODE type ref to if_ixml_node.
    DATA : GV_NODETEXT type STRING.
    data:  GV_FIRST_TIME.
    GV_FIRST_TIME = 'X'.
    GV_NODE = DOCUMENT.
    GT_ITEM-item_no = 1.
    perform GET_DATA tables     GT_ITEM
                     using      GV_NODE
                     changing   GV_HEADER.
    Last item is still not added.
      append GT_ITEM.
    write  : GV_HEADER-cust_name,
             GV_HEADER-card_no,
             GV_HEADER-tax_amount,
             GV_HEADER-total_amount.
    loop at GT_ITEM.
      write  /:.
      write  : GT_ITEM-item_no,
               GT_ITEM-item_id,
               GT_ITEM-item_title,
               GT_ITEM-item_qty,
               GT_ITEM-item_uprice.
    endloop.
          FORM Get_data                                                 *
    form get_data tables   YT_ITEM    structure GT_ITEM
                  using value(x_node) type ref to if_ixml_node
                  changing Y_HEADER   type TY_HEADER.
      data: INDENT      type i.
      data: PTEXT       type ref to if_ixml_text.
      data: STRING      type string.
      data: TEMP_STRING(100).
      case X_NODE->get_type( ).
        when if_ixml_node=>co_node_element.
          STRING = X_NODE->get_name( ).
          GV_NODETEXT = STRING.
        when if_ixml_node=>co_node_text.
          PTEXT ?= X_NODE->query_interface( IXML_IID_TEXT ).
          if PTEXT->ws_only( ) is initial.
            STRING = X_NODE->get_value( ).
            case GV_NODETEXT.
              when 'Customer'.
                clear GV_HEADER.
              when 'Name'.
                move STRING to GV_HEADER-cust_name.
              when 'Cardnum'.
                move STRING to GV_HEADER-card_no.
              when 'Tax'.
                move STRING to GV_HEADER-tax_amount.
              when 'Total'.
                move STRING to GV_HEADER-total_amount.
            Iteam details
              when 'ID'.
                move STRING to GT_ITEM-item_id.
              when 'Title'.
                move STRING to TEMP_STRING.
                move TEMP_STRING to GT_ITEM-item_title.
              when 'Quantity'.
                move STRING to GT_ITEM-item_qty.
              when 'UnitPrice'.
                move STRING to GT_ITEM-item_uprice.
            endcase.
          endif.
      endcase.
      if GV_NODETEXT = 'Customer'.
        clear GV_HEADER.
      elseif GV_NODETEXT = 'Item'.
        if GV_FIRST_TIME ne 'X'.
           append GT_ITEM.
         clear : gt_item.
           GT_ITEM-item_no = gt_item-item_no + 1.
        endif.
        GV_FIRST_TIME = ' '.
      endif.
    Get the next child
      X_NODE = x_node->get_first_child( ).
    Recurse
      while not X_NODE is initial.
        perform GET_DATA tables     GT_ITEM
                         using      X_NODE
                         changing   GV_HEADER.
        X_NODE = x_node->get_next( ).
      endwhile.
    endform.
    Create an XML file with the following DATA given below and place it in the path mentioned above source code.
    2. XML File DATA. You create an XML File in this format to test the same.
      <?xml version="1.0" encoding="ISO-8859-1" standalone="yes" ?>
    - <Order>
    - <Customer>
      <Name>Bill Buckram</Name>
      <Cardnum>234 234 234 234</Cardnum>
      </Customer>
    - <Manifest>
    - <Item>
      <ID>209</ID>
      <Title>Duke: A Biography of the Java Evangelist</Title>
      <Quantity>1</Quantity>
      <UnitPrice>$10.75</UnitPrice>
      </Item>
    - <Item>
      <ID>208</ID>
      <Title>100% Pure: Making Cross Platform Deployment a Reality</Title>
      <Quantity>1</Quantity>
      <UnitPrice>$10.75</UnitPrice>
      </Item>
    - <Item>
      <ID>204</ID>
      <Title>Making the Transition from C++ to the Java(tm) Language</Title>
      <Quantity>1</Quantity>
      <UnitPrice>$10.75</UnitPrice>
      </Item>
    - <Item>
      <ID>202</ID>
      <Title>Web Servers for Fun and Profit</Title>
      <Quantity>1</Quantity>
      <UnitPrice>$10.75</UnitPrice>
      </Item>
    - <Item>
      <ID>210</ID>
      <Title>I Think Not: Dukes Likeness to the Federation Insignia</Title>
      <Quantity>1</Quantity>
      <UnitPrice>$10.75</UnitPrice>
      </Item>
      </Manifest>
    - <Receipt>
      <Subtotal>$53.75</Subtotal>
      <Tax>$4.43</Tax>
      <Total>$58.18</Total>
      </Receipt>
      </Order>

  • XML to ABAP internal table with CALL TRANSFORMATION

    I can't create a transformation that allow passing next XML file  to an internal table:
    Please, I need someone could help me, because I don t have XML knowledge
    << Moderator message - Everyone's problem is important. But the answers in the forum are provided by volunteers. Please do not ask for help quickly. >>
    Kind regards,
    Edited by: Rob Burbank on Jul 21, 2011 4:02 PM

    Hi Gastón Juarez,
    sorry, didn't see your post, you should have linked the previous to this one
    If we create a ZZZ transformation of type ST, it would be something like this (I didn't test). Note that I concatenated the date and time, because field operations in ST are not possible (we should use XSLT instead, but it's counter performant): 
    ... (here the usual header)
    <tt:root name="ABAP_X"/>
    <tt:template>
      <corailExport xmlns= " http://www.abc.com/corailExport_Transcou201D
    xmlns: xsi= " http://www.w3.org/2001/XMLSchema-instanceu201D
    xsi: schemaLocation= " http://www.abc.com/corailExport_Transco corailExport_Transco.xsd u201C>
        <exportDate><tt:skip></tt:skip></exportDate>
        <tt:loop ref=".ABAP_X" name="line">
          <transcodification>
                 <tt:attribute name="applyingDate" value-ref="$line.APPLYING_DATE"></tt:attribute>
            <previousCofor><tt:value ref="$line.OLD_COFOR"></tt:value></previousCofor>
            <newCofor><tt:value ref="$line.NEW_COFOR"></tt:value></newCofor>
          </transcodification>
        </tt:loop>
      </corailExport>
    </tt:template>
    The program:
    TYPES : BEGIN OF ty_x,
    applying_date TYPE string,
    old_cofor TYPE lifnr,
    new_cofor TYPE lifnr,
    END OF ty_x.
    DATA l_xml TYPE string.
    DATA lt_x TYPE TABLE OF ty_x.
    l_xml = 'your xml'.
    CALL TRANSFORMATION zzz
       SOURCE XML l_xml
       RESULT abap_x = lt_x.
    BR
    Sandra

Maybe you are looking for