11/02/2010

Download Tabela Interna Para Arquivo XML

REPORT  ZRR_SAMPLE.

TABLES: spfli.

DATA: it_table   TYPE STANDARD TABLE OF spfli WITH HEADER LINE,
      l_dom      TYPE REF TO if_ixml_element,
      m_document TYPE REF TO if_ixml_document,
      m_xmldoc   TYPE REF TO cl_xml_document,
      g_ixml     TYPE REF TO if_ixml,
      w_result   TYPE i,
      w_rc       LIKE sy-subrc.

DATA: p_file_tmp LIKE rlgrap-filename.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

SELECT-OPTIONS: s_carrid FOR spfli-carrid.

PARAMETERS: p_file LIKE rlgrap-filename OBLIGATORY DEFAULT 'C:\spfli'.

SELECTION-SCREEN END OF BLOCK b1.

START-OF-SELECTION.

  SELECT * FROM spfli INTO TABLE it_table WHERE carrid IN s_carrid.

END-OF-SELECTION.

*  *******************************************
*  *** Inicializa o iXML-Framework        ****
*  *******************************************
  CLASS cl_ixml DEFINITION LOAD.

  g_ixml = cl_ixml=>create( ).

  CHECK NOT g_ixml IS INITIAL.

*  *******************************************
*  *** Cria o DOM com dados do SAP        ****
*  *******************************************
  m_document = g_ixml->create_document( ).

  CHECK NOT m_document IS INITIAL.

*  ** Conversão da tabela interna em DOM ***

  CALL FUNCTION 'SDIXML_DATA_TO_DOM'
    EXPORTING
      name         = 'DADOS'
      dataobject   = it_table[]
    IMPORTING
      data_as_dom  = l_dom
    CHANGING
      document     = m_document
    EXCEPTIONS
      illegal_name = 1
      OTHERS       = 2.

  IF NOT sy-subrc = 0.

    WRITE: /'Erro DADOS -> DOM: ', sy-subrc.

  ENDIF.

  CHECK NOT l_dom IS INITIAL.

*  ** Apendando o DOM ao documento iXML ***
  w_rc = m_document->append_child( new_child = l_dom ).

  IF NOT w_rc IS INITIAL.

    WRITE: /'Erro DOM -> iXML: ', w_rc.

  ENDIF.

*  *******************************************
*  *** Criar XML apartir do DOM no iXML   ****
*  *******************************************
  CREATE OBJECT m_xmldoc.

  CHECK NOT m_xmldoc IS INITIAL.

  w_rc = m_xmldoc->create_with_dom( document = m_document ).

  IF NOT w_rc IS INITIAL.

    WRITE: /'Erro DOM+iXML -> XML: ', w_rc.

  ENDIF.

*  *******************************************
*  *** Mostrando o arquivo XML            ****
*  *******************************************

  CALL METHOD m_xmldoc->display.

*  *******************************************
*  *** Salvar o arquivo XML               ****
*  *******************************************

  CONCATENATE p_file '.xml' INTO p_file_tmp .

  CALL METHOD m_xmldoc->export_to_file( filename = p_file_tmp ).

Um comentário:

  1. Rafael,

    Achei interessante sua iniciativa.
    Qualquer dúvida que precisar sobre SD, saiba que pode contar comigo.

    Sucesso!!

    Ricardo Portugal
    SAP SD Consultant

    ResponderExcluir