ABAP Data to XML file

Hi,
I have read this weblog
/people/patrick.baer/blog/2005/02/24/abap-serialization--part-i-quick-n-easy and tried to serialize ABAP data into XML format.
In fact, I have copied the exact code from this weblog, but somehow this file is not visible in my pc.
DATA example_data TYPE spfli.
select single * from spfli into example_data.
DATA xml_utils TYPE REF TO if_ixml.
xml_utils = cl_ixml=>create( ).
DATA xml_stream_factory TYPE REF TO if_ixml_stream_factory.
xml_stream_factory = xml_utils->create_stream_factory( ).
DATA xml_output_stream TYPE REF TO if_ixml_ostream.
xml_output_stream = xml_stream_factory->create_ostream_uri( system_id =
'file://c:test.xml' ).
try.
CALL TRANSFORMATION id
SOURCE data_node = example_data
RESULT XML xml_output_stream.
catch cx_sy_conversion_base64 CX_SY_CONV_ILLEGAL_DATE_TIME.
write 'there is an exception'.
endtry.
This part of the code, I have also changed to :
xml_stream_factory->create_ostream_uri( system_id =
'file://test.xml' ).
and still the file is not visible.
I presume three reasons:
a) Looking in the wrong place
b) Some configuration, I am not doing properly
c) Something else has to be done, to write a file to system
Any help on this regard, is highly appreciated.
Next issue being, how robust is the approach of serializing ABAP data into XML format, so that a third party system can pick up this data and do a comparison ?
Some parameters that I am looking for in this regards are:
a) Error Validation (can XML data be incorrectly written into a file/while transmitting this data some errors can creep in. If so, how do I rectify it. As far as I know, this data can only be written to Presentation Server or using FTP ,transported to required destination. Is there any other approach ? )
b) Security
Would be great if you could drop some hints for the above procedure.
Regards,
Subramanian V.

I think you are perhaps overestimating the capabilities of the osteam object.  If you want to write the XML to a file the easiest thing to do is render it an ostream_itable (internal ABAP table).  Then you can download it your PC with the GUI_DOWNLOAD function:
parameter: ifile type file_table-filename obligatory
           default 'c:issue.xml'.
****Temp File name for function module call.
data: ifilename type string.
  move ifile to ifilename.
  create object issue
     exporting
       id     = id
       create_mode = abap_false.
  data: g_ixml type ref to if_ixml,
         g_stream_factory type ref to if_ixml_stream_factory,
         xslt_err type ref to cx_xslt_exception,
         g_encoding type ref to if_ixml_encoding,
         ostream type ref to if_ixml_ostream.
  constants:  line_length type i value 4096.
  types:      line_t(line_length) type x,
              table_t type standard table of line_t.
  data: restab type table_t.
  constants:
* encoding for download of XML files
    encoding     type string value 'utf-8'.
  data: ressize type i.
  try.
      g_ixml = cl_ixml=>create( ).
      g_stream_factory = g_ixml->create_stream_factory( ).
      g_encoding = g_ixml->create_encoding( character_set = encoding
        byte_order = 0 ).
      refresh restab.
      ostream =
        g_stream_factory->create_ostream_itable( table = restab ).
      ostream->set_encoding( encoding = g_encoding ).
      call transformation id_indent
        source     asap_issue = issue
        result xml restab
        options
        data_refs = 'embedded'.
      ressize = ostream->get_num_written_raw( ).
    catch cx_xslt_exception into xslt_err.
      data: s type string.
      s = xslt_err->get_text( ).
  endtry.
  call function 'GUI_DOWNLOAD'
    exporting
      bin_filesize = ressize
      filename     = ifilename
      filetype     = 'BIN'
    tables
      data_tab     = restab
    exceptions
      others       = 1.
  call method cl_gui_frontend_services=>execute
     exporting
       document               = ifilename
*    APPLICATION            =
*    PARAMETER              =
*    DEFAULT_DIRECTORY      =
*    MAXIMIZED              =
*    MINIMIZED              =
*    SYNCHRONOUS            =
    exceptions
      cntl_error             = 1
      error_no_gui           = 2
      bad_parameter          = 3
      file_not_found         = 4
      path_not_found         = 5
      file_extension_unknown = 6
      error_execute_failed   = 7
      others                 = 8.
As far as a different system, once you have the data serialized into a string or internal table you have lots of possibilites.  If the other system is an SAP system you could send the data via RFC.  You could always write the XML string to the server file system (via open dataset, transfer to dataset).  You can then FTP the file (using built in SAP FTP functionality) just about anywhere.
What are you looking for as far as robust and secure.  The XML serializer is built in the ABAP Kernel and quite robust.  As far as secure- the data isn't secure at all.  The data is written into a simple string (if written into the file system or your pc - it is a text or binary file that can easily be read by just about anything).  Serializing to XML in and of itself isn't going to provide any security.

Similar Messages

  • 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

  • Transition data to XML file

    hi exeprt,
    please help me.
    Regards,
    Hamadelnil

    HI,
    Look at the Sample Program
    REPORT z_tab_file.
    PARAMETERS : gv_file(100) DEFAULT '.ATABTEST.TXT',
    p_csv AS CHECKBOX,
    p_xml AS CHECKBOX.
    *-----Types------------------------------------------------------------*
    TYPES:
    * Structure for Header File
    BEGIN OF gt_nisl_file,
    * urgent_flag(1) TYPE c,
    mat_typ(2) TYPE c,
    sales_org(4) TYPE c,
    dist_ch(2) TYPE c,
    division(2) TYPE c,
    * cont_no(1) TYPE c,
    * sold_to(4) TYPE c,
    * goods_rep(10) TYPE c,
    * delv_dt(1) TYPE c,
    * po_no(10) TYPE c,
    rep_name(40) TYPE c,
    * contact(32) TYPE c,
    * street(100) TYPE c,
    * postcode(10) TYPE c,
    * city(40) TYPE c,
    * region(1) TYPE c,
    * country(3) TYPE c,
    * phone_no(30) TYPE c,
    * fst_ln_ind(1) TYPE c,
    * order_ln_no(3) TYPE c,
    * ni_part_no(35) TYPE c,
    * cust_part(18) TYPE c,
    * quantity(3) TYPE c,
    * die_no(18) TYPE c,
    * town_circle(50) TYPE c,
    * code(1) TYPE c,
    * slogan_no(1) TYPE c,
    * head_txt(1000) TYPE c,
    * itm_txt1(32) TYPE c,
    * itm_txt2(10) TYPE c,
    END OF gt_nisl_file.
    *-----Internal Tables--------------------------------------------------*
    DATA:
    git_nisl_file TYPE TABLE OF gt_nisl_file.
    *-----Structures/Workareas---------------------------------------------*
    DATA:
    gs_nisl_file TYPE gt_nisl_file.
    * gv_dom TYPE REF TO if_ixml_element,
    * gv_document TYPE REF TO if_ixml_document,
    * gv_string TYPE xstring,
    * gv_size TYPE i,
    * git_xml TYPE dcxmllines.
    *FIELD-SYMBOLS: <f> TYPE ANY, <delim> TYPE ANY.
    * gv_file = '.ATABTEST.TXT'.
    *gs_nisl_file-urgent_flag = 'X'.
    DO 5000 TIMES.
    gs_nisl_file-mat_typ = 'MA'.
    gs_nisl_file-sales_org = '2000'.
    gs_nisl_file-dist_ch = '80'.
    gs_nisl_file-division = '01'.
    *gs_nisl_file-cont_no = '12345'.
    *gs_nisl_file-sold_to = '2002'.
    *gs_nisl_file-goods_rep = 'CUST ADDR'.
    *gs_nisl_file-po_no = 'PO12345'.
    *gs_nisl_file-delv_dt =
    gs_nisl_file-rep_name = 'REP NAME'.
    *gs_nisl_file-contact = 'CONTACT'.
    *gs_nisl_file-street = 'STREET'.
    *gs_nisl_file-postcode = 'POCODE'.
    *gs_nisl_file-city = 'CITY'.
    *gs_nisl_file-region =
    *gs_nisl_file-country = 'GB'.
    *gs_nisl_file-phone_no = '12234 57819'.
    *gs_nisl_file-fst_ln_ind = 'X'.
    *gs_nisl_file-order_ln_no = '010'.
    *gs_nisl_file-ni_part_no = '100110'.
    *gs_nisl_file-cust_part = '100110'.
    *gs_nisl_file-quantity = '1'.
    *gs_nisl_file-die_no = '1000032'.
    *gs_nisl_file-town_circle = '30000004'.
    *gs_nisl_file-code =
    *gs_nisl_file-slogan_no = '100110'.
    *gs_nisl_file-head_txt = 'HEADER TEXT'.
    *gs_nisl_file-itm_txt1 = 'ITEM TEXT1'.
    *gs_nisl_file-itm_txt2 = 'ITEM TEXT2'.
    APPEND gs_nisl_file TO git_nisl_file.
    ENDDO.
    DATA:
    lv_file(1000) TYPE c,
    lv_colt(5000) TYPE c,
    lv_cnt(2) TYPE c,
    lv_text(8) TYPE c.
    CONSTANTS:
    lc_hash TYPE x VALUE '09'.
    DATA :
    lc_hash_x TYPE xstring,
    * lc_hash_str type string.
    lc_hash_str(2) TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.
    FIELD-SYMBOLS:
    <lf_text> TYPE ANY.
    *ASSIGN lc_hash TO <delim>.
    * clear : lc_hash_x, lc_hash_str.
    * lc_hash_x = lc_hash.
    * CALL FUNCTION 'NLS_STRING_CONVERT_TO_SYS'
    * EXPORTING
    * lang_used = sy-langu
    * SOURCE = lc_hash_x
    * IMPORTING
    * RESULT = lc_hash_str.
    * XML
    TYPES: BEGIN OF ttab,
    record(65535) TYPE c,
    END OF ttab.
    DATA: xmltable TYPE TABLE OF ttab.
    DATA: xml_out TYPE string,
    length LIKE sy-tabix,
    result1 LIKE gs_nisl_file.
    DATA wa_xmltable TYPE ttab.
    CHECK NOT git_nisl_file IS INITIAL.
    OPEN DATASET gv_file FOR OUTPUT IN TEXT MODE ENCODING UTF-8. "DEFAULT.
    IF sy-subrc NE 0.
    WRITE :/ 'Unable to open file'(021),
    gv_file.
    EXIT.
    ENDIF. " sy-subrc
    IF p_csv = 'X'.
    PERFORM csv_download.
    ENDIF.
    IF p_xml = 'X'.
    PERFORM xml_download.
    ENDIF.
    CLOSE DATASET gv_file.
    END-OF-SELECTION.
    *& Form csv_download
    * text
    FORM csv_download.
    * Header line 1: Transfer empty line
    TRANSFER lv_file TO gv_file.
    lv_file = '1'.
    lv_colt = text-h01.
    lv_cnt = '1'.
    DO.
    lv_cnt = lv_cnt + 1.
    * Generate line with all column numbers
    CONCATENATE lv_file lv_cnt INTO lv_file SEPARATED BY lc_hash_str.
    IF lv_cnt LE 9.
    CONCATENATE 'TEXT-H0' lv_cnt INTO lv_text.
    ELSE.
    CONCATENATE 'TEXT-H' lv_cnt INTO lv_text.
    ENDIF.
    ASSIGN (lv_text) TO <lf_text>.
    * Generate line with all column headers
    CONCATENATE lv_colt <lf_text> INTO lv_colt SEPARATED BY lc_hash_str.
    IF lv_cnt = 30.
    EXIT.
    ENDIF.
    ENDDO.
    * Header line 2: Line with all column numbers
    TRANSFER lv_file TO gv_file.
    * Header line 3: Line with all column headers
    TRANSFER lv_colt TO gv_file.
    LOOP AT git_nisl_file INTO gs_nisl_file.
    CLEAR lv_file.
    * CONCATENATE gs_nisl_file-urgent_flag
    * gs_nisl_file-mat_typ
    * gs_nisl_file-sales_org
    * gs_nisl_file-dist_ch
    * gs_nisl_file-division
    * gs_nisl_file-cont_no
    * gs_nisl_file-sold_to
    * gs_nisl_file-goods_rep
    * gs_nisl_file-po_no
    * gs_nisl_file-delv_dt
    * gs_nisl_file-rep_name
    * gs_nisl_file-contact
    * gs_nisl_file-street
    * gs_nisl_file-postcode
    * gs_nisl_file-city
    * gs_nisl_file-region
    * gs_nisl_file-country
    * gs_nisl_file-phone_no
    * gs_nisl_file-fst_ln_ind
    * gs_nisl_file-order_ln_no
    * gs_nisl_file-ni_part_no
    * gs_nisl_file-cust_part
    * gs_nisl_file-quantity
    * gs_nisl_file-die_no
    * gs_nisl_file-town_circle
    * gs_nisl_file-code
    * gs_nisl_file-slogan_no
    * gs_nisl_file-head_txt
    * gs_nisl_file-itm_txt1
    * gs_nisl_file-itm_txt2
    * INTO lv_file SEPARATED BY lc_hash_str.
    * PO details
    TRANSFER lv_file TO gv_file.
    ENDLOOP. " LOOP AT git_nisl_file
    ENDFORM. "csv_download
    *& Form xml_download
    * text
    FORM xml_download.
    CALL TRANSFORMATION ('ID')
    SOURCE output = git_nisl_file
    RESULT XML xml_out.
    CALL FUNCTION 'CONVERT_STRING_TO_TABLE'
    EXPORTING
    i_string = xml_out
    i_tabline_length = '65535'
    TABLES
    et_table = xmltable.
    LOOP AT xmltable INTO wa_xmltable.
    TRANSFER wa_xmltable-record TO gv_file.
    ENDLOOP.
    ENDFORM. "xml_download
    and also look at the 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
    Regards
    Sudheer
    Message was edited by:
            Sudheer Junnuthula

  • Read data from xml files and  populate internal table

    Hi.
    How to read data from xml files into internal tables?
    Can u tell me the classes and methods to read xml data..
    Can u  explain it with a sample program...

    <pre>DATA itab_accontextdir TYPE TABLE OF ACCONTEXTDIR.
    DATA struct_accontextdir LIKE LINE OF itab_accontextdir.
    DATA l_o_error TYPE REF TO cx_root.
    DATA: filename type string ,
                 xmldata type xstring .
    DATA: mr      TYPE REF TO if_mr_api.
    mr = cl_mime_repository_api=>get_api( ).
    mr->get( EXPORTING  i_url     = 'SAP/PUBLIC/BC/xml_files_accontext/xml_accontextdir.xml'
                  IMPORTING  e_content = xmldata ).
    WRITE xmldata.
    TRY.
    CALL TRANSFORMATION id
          SOURCE XML xmldata
          RESULT shiva = itab_accontextdir.
      CATCH cx_root INTO l_o_error.
    ENDTRY.
    LOOP AT itab_accontextdir INTO struct_accontextdir.
        WRITE: / struct_accontextdir-context_id,
               struct_accontextdir-context_name,
               struct_accontextdir-context_type.
        NEW-LINE.
        ENDLOOP.</pre>
    <br/>
    Description:   
    In the above code snippet I am storing the data in an xml file(you know xml is used to store and transport data ) called 'xml_accontextdir.xml' that is uploaded into the MIME repository at path 'SAP/PUBLIC/BC/xml_files_accontext/xml_accontextdir.xml'.
    The below API is used to read a file in MIME repo and convert it into a string that is stored in ' xmldata'. (This is just a raw data that is got by appending the each line of  xml file).
    mr = cl_mime_repository_api=>get_api( ).
    mr->get( EXPORTING  i_url     = 'SAP/PUBLIC/BC/xml_files_accontext/xml_accontextdir.xml'
                  IMPORTING  e_content = xmldata ).
        Once the 'xmldata' string is available we use the tranformation to parse the xml string that we have got from the above API and convert it into the internal table.
    <pre>TRY.
    CALL TRANSFORMATION id
          SOURCE XML xmldata
          RESULT shiva = itab_accontextdir.
      CATCH cx_root INTO l_o_error.
    ENDTRY.</pre>
    Here the trasnsformation 'id ' is used to conververt the source xml 'xmldata' to resulting internal table itab_accontextdir, that have same structure as our xml file 'xml_accontextdir.xml'.  In the RESULT root of the xml file has to be specified. (In my the root is 'shiva'). 
    Things to be taken care:
    One of the major problem that occurs when reading the xml file is 'format not compatible with the internal table' that you are reading into internal table.  Iin order to get rid of this issue use one more tranformation to convert the data from the internal table into the xml file.    
    <pre>TRY.
          CALL TRANSFORMATION id
            SOURCE shiv = t_internal_tab
            RESULT XML xml.
        CATCH cx_root INTO l_o_error.
      ENDTRY.
      WRITE xml.
      NEW-LINE.</pre>
    <br/>
    This is the same transformation that we used above but the differnce is that the SOURCE and RESULT parameters are changed the source is now the internal table and result is *xml *string. Use xml browser that is available with the ABAP workbench to read the xml string displayed with proper indentation. In this way we get the format of xml file to be used that is compatable with the given internal table. 
    Thank you, Hope this will help you!!!
    Edited by: Shiva Prasad L on Jun 15, 2009 7:30 AM
    Edited by: Shiva Prasad L on Jun 15, 2009 11:56 AM
    Edited by: Shiva Prasad L on Jun 15, 2009 12:06 PM

  • Pls Help me with steps to add data from xml file to SAP B1 through B1iSN.

    Pls Help me with steps to add data from xml file to SAP B1 through B1iSN. I  am getting stuck in xsl transformation. not able to understand where the mapping code needs to be added.
    Pls explain me the steps for adding data from xml to B1 quotation step by step.
    thanks and regards
    Priya

    Hi,
    Have you checked this: https://sap.na.pgiconnect.com/p45508295/?launcher=false&fcsContent=true&pbMode=normal ?
    Thanks,
    Gordon

  • Internal table data to XML file.

    Hi All,
    May I know how can we convert the internal table data to xml file?
    Regards
    Ramesh.

    Re: Convert XML to internal Table
       Go through the link..u should be able to solve the problem..

  • Why we need to conver Context  Node data into XML file----Export to Excel

    Hi All,
    Let me clarify my dought........today i have gone through the concept of  "Exporting Context Data Using the Webdynpro Binary cache" in SAP Online Help.
    From the SAP Online Help pdf document, i have found that, the context node data has been converted first in to XML file,after that file had been stored in the web dynpor binary cache...bla....bla.........
    Here my qtn is why they had converted context node data into XML file. With out doing that can not we export context node data to excel file..?
    Regards
    Seshu
    Edited by: Sesshanna D on Dec 19, 2007 7:25 AM

    Hi Sesshanna,
    it is not neccessary to do that but xml has the advantage, that it can be easily transformed into every output format that might occur in later project stages.
    If it's simply about blowing out some Excel, I suggest using an OSS library such as jexcelAPI or Jakarta POI and building the Excel how you need it.
    regards,
    Christian

  • Load data in xml file into Pdf form created by LiveCycle Designer

    I want to load data in xml file into Pdf form when Pdf opened and Form field will be filled with data from xml file .I try to use $host.importdata("filename.xml"); But i could not find suitable place to run my code. Can anyone give me some advice? thank you.

    Hi,
    extract your xml and then you can use insert all clause.
    here's very small example on 10.2.0.1.0
    SQL> create table table1(id number,val varchar2(10));
    Table created.
    SQL> create table table2(id number,val varchar2(10));
    Table created.
    SQL> insert all
      2  into table1 values(id,val)
      3  into table2 values(id2,val2)
      4  select extractValue(x.col,'/a/id1') id
      5        ,extractValue(x.col,'/a/value') val
      6        ,extractValue(x.col,'/a/value2') val2
      7        ,extractValue(x.col,'/a/id2') id2
      8  from (select xmltype('<a><id1>1</id1><value>a</value><id2>2</id2><value2>b</value2></a>') col from dual) x;
    2 rows created.
    SQL> select * from table1;
            ID VAL                                                                 
             1 a                                                                   
    SQL> select * from table2;
            ID VAL                                                                 
             2 b                                                                    Ants

  • Reading data From XML file and setting into ViewObject to Pouplate ADF UI

    Hi,
    I have following requirement.
    I would like to read data from XML file and populate the data in ViewObject so that the data can be displayed in the ADF UI.
    Also when user modifies the data in the ADF UI, it should be modified back into to ViewObject.
    Here is an example - XML file contains Book Title and Author. I would like to read Book Title and Author from XML file and set it into ViewObject Attribute and then display Book title and Author in ADF UI page. Also when user modifies Book title and Author, I would like to store it back in View Object.
    Please help me with this requirement and let me know if any solution exist in ADF, for populating the ADF UI screen fields with external XML file data.
    Thanks

    Read chapter 42 http://download.oracle.com/docs/cd/E16162_01/web.1112/e16182/bcadvvo.htm of the fusion developer guide
    Section 42.7, "Reading and Writing XML"
    Section 42.8, "Using Programmatic View Objects for Alternative Data Sources"
    Timo

  • How to extract data from XML file with JavaScript

    HI All
    I am new to this group.
    Can anybody help me regarding XML.
    I want to know How to extract data from XML file with JavaScript.
    And also how to use API for XML
    regards
    Nagaraju

    This is a Java forum.
    JavaScript is something entirely different than Java, even though the names are similar.
    Try another website with forums about JavaScript.
    For example here: http://www.webdeveloper.com/forum/forumdisplay.php?s=&forumid=3

  • How to add data in xml file

    Hi ALL
    I want to add new fields on seeded EBS page to store their values in hr_api_transaction table whoch contain information of other fields on that page which are seeded
    but that table has one column which stores xml file and that xml file has all information about that page's fields
    how can I store my custom fields values in that xml file ?

    Hi,
    As Andy said,  add data to an xml file is overwriting, if you mean append data to xml file, please look this article:
    http://codesamplez.com/programming/linq-to-xml-tutorial, Since this issue is more related to ASP.net, you could also ask this issue in asp.net forum:
    http://forums.asp.net/
    Best Regards,
    Jambor
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How can i query oracle database data to xml file with c++?

    I want query data to xml file directly in my c++ application .
    I know the oracle XSU provide interferce for query data to xml
    file directly.
    But XSU for oracle8i does not support c++.
    I do not know if XSU for oracle9i support c++.
    can you tell me?
    If i do not use XSU to finish my applicayion.
    what interface that oracle provide can help me do my work?
    thank you !

    BTW why do you want to migrate oracle database data to db2 database? Any specific project requirement like Parallel run with Oracle database (e.g data replication)? Or any other issues - Cost? Manageability? Availability? Business requirements?
    Do you need to do a day-to-day data transfer or it is for permanent migration?

  • Storing data in XML file

    Hi,
    I am a student and very new to XML. I know what it is but I never had developed anything in it.Now I am doing an assignment for which I need your help.
    I have to store Customer data in XML file after he enters it in GUI.Customer is having the following fields:
    String name1=BuyerGui.name.getText().trim();
    String street1=BuyerGui.street.getText().trim();
    int zipcode1=Integer.parseInt(BuyerGui.zipCode.getText().trim());
    String city1=BuyerGui.city.getText().trim();
    String country1=BuyerGui.country.getText().trim();
    String email1=BuyerGui.eMailAddress.getText().trim();
    I may have to update it some times.
    I am working in Java 4.2. I heard that I can use JAXP but no idea how to do it.
    Anybody help me with sample code because I dont have verymuch time for my assignment.
    Thanks in advance,
    Sai Ram

    Here is sun's tutorial on JAXP with samples:
    http://java.sun.com/xml/tutorial_intro.html
    -jay

  • Hi, extract data from xml file and insert into another exiting xml file

    i am searching code to extract data from xml file and insert into another exiting xml file by a java program. I understood it is easy to extract data from a xml file, and how ever without creating another xml file. We want to insert the extracted data into another exiting xml file. Suggestions?
    1st xml file which has two lines(text1.xml)
    <?xml version="1.0" encoding="iso-8859-1"?>
    <xs:PrintDataRequest xmlns:xs="http://com.unisys.com/Anid"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://com.unisys.com/Anid file:ANIDWS.xsd">
    <xs:Person>
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://com.unisys.com/Anid file:ANIDWS.xsd">
    These two lines has to be inserted in the existing another xml(text 2.xml) file(at line 3 and 4)
    Regards,
    bubbly

    Jadz_Core wrote:
    RandomAccessFile? If you know where you want to insert it.Are you sure about this? If using this, the receiving file would have to have bytes inserted that exactly match the number of bytes replaced. I'm thinking that you'll likely have to stream through the second XML with a SAX parser and copy information (or insert new information) as you stream with an XML writer of some sort.

  • Extract data from xml file and insert into another exiting xml fil

    hello,
    i am searching extract data from xml file and insert into another exiting xml file by a java program. I understood it is easy to extract data from a xml file, and how ever without creating another xml file. We want to insert the extracted data into another exiting xml file. Suggestions?
    Regards,
    Zhuozhi

    If the files are small, you can load the target file in a DOM document, insert the data from the source file and persist the DOM.
    If the files are large, you probably want to use a StAX or SAX.

Maybe you are looking for

  • How do I add MPEG-4 files to my library?!

    I've been able to simply drag videos into my library in previous versions of iTunes but now I can't import them at all. I can't drag them, I can't go add file to library, I can't make a new folder inside my iTunes content and copy the file over. Star

  • Run macro in PDF form created in LC

    I have created a form in LiveCycle Designer with a text field that can expand to several pages if need be.  It works great.  Now when the person fills it out and emails it back to us, we need to be able to pull all of the comma-delimted text out of t

  • Newbie needs JNI help

    the JNI tutorial speaks about creating a "shared directory" where a "dll" file is created and stored. How do i create this ".dll" file and store it into the shared directory ? ...

  • How to enable the edit option for the sample downloaded portlets

    Hi, I had downloaded some samples from the portal studia site. Here is the folowing URL http://portalstudio.oracle.com/pls/ops/docs/FOLDER/COMMUNITY/PDK/ARTICLES/GUIDELINES.PARAMETER.PASSING.HTML This is related to passing the parameters between the

  • Validating IDML file

    First, I'm not sure if this is where I should post this question. If not, please tell me where to post IDML questions. I am writing a VB.NET program to generate an IDML file. I have used validate.bat (CS5) on the file and it reports no errors. Howeve