11/02/2010

Upload Arquivo XML Para Tabela Interna

REPORT  ZRR_SAMPLE.

TABLES: spfli.

FIELD-SYMBOLS :     TYPE ANY,
                 TYPE ANY.

TYPES : ty_itab TYPE STANDARD TABLE OF spfli.

DATA : it_table   TYPE ty_itab,
       it_bindata TYPE swxmlcont,
       v_filename TYPE string,
       v_size     TYPE i,
       retcode    TYPE sy-subrc,
       objxml     TYPE REF TO cl_xml_document.

CREATE OBJECT objxml.

v_filename = 'c:\spfli.xml'.

CALL METHOD cl_gui_frontend_services=>gui_upload
  EXPORTING
    filename                = v_filename
    filetype                = 'BIN'
  IMPORTING
    filelength              = v_size
  CHANGING
    data_tab                = it_bindata
  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.

retcode = sy-subrc.

IF retcode = 0.
  retcode = objxml->create_with_table( table = it_bindata size = v_size ).
ENDIF.

retcode = objxml->parse_table( table = it_bindata size = v_size ).

objxml->get_data( CHANGING dataobject = it_table ).

LOOP AT it_table ASSIGNING .

  DO.

    ASSIGN COMPONENT sy-index OF STRUCTURE  TO .

    IF  IS ASSIGNED.

      WRITE .

    ELSE.

      NEW-LINE.

      EXIT.

    ENDIF.

    UNASSIGN .

  ENDDO.

ENDLOOP.

FREE : it_bindata,
       it_table.

UNASSIGN : ,
           .

Nenhum comentário:

Postar um comentário