[SAP-ABAP] - Convert ITAB to XML

*&---------------------------------------------------------------------*
*& Report  YO_ITAB_TO_XML
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  yo_itab_to_xml.

TYPE-POOLStruxs.

DATA xmltab TYPE truxs_xml_table,
       gv_bin_size TYPE i.

DATA gi_t001 LIKE STANDARD TABLE OF t001 WITH HEADER LINE.

START-OF-SELECTION.

  SELECT INTO TABLE gi_t001
  FROM t001.

  CALL FUNCTION 'SAP_CONVERT_TO_XML_FORMAT'
    EXPORTING
      i_filename           'c:\test.xml'
      i_xml_doc_name       'test'
    IMPORTING
      pe_bin_filesize      gv_bin_size
    TABLES
      i_tab_sap_data       gi_t001
    CHANGING
      i_tab_converted_data xmltab
    EXCEPTIONS
      conversion_failed    1
      OTHERS               2.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

END-OF-SELECTION.
  CALL FUNCTION 'DOWNLOAD'
    EXPORTING
      bin_filesize gv_bin_size
      filename     'c:\test.xml'
      filetype     'BIN'
    TABLES
      data_tab     xmltab.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

Comments