SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Report to export an internal table to an XML file



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Programming Techniques | Приемы программирования -> Conversion
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Sat Sep 13, 2008 6:41 pm    Post subject: Report to export an internal table to an XML file Reply with quote

Author: Chaitanya Raju

This program exports an internal table to an XML file.
Code:
*----------------------------------------------------------------------*
* Report ZACDP_BHR_01 *
* Export an internal table to XML document *
*----------------------------------------------------------------------*
REPORT zacdp_bhr_01.
*----------------------------------------------------------------------*
* Code for selection screen field
PARAMETERS: GK_RUTA TYPE RLGRAP-FILENAME.
* Code for selection screen field*
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
*  Declaring with TYPE*
TYPES: BEGIN OF turnos,
    lu LIKE t552a-tpr01,
    ma LIKE t552a-tpr01,
    mi LIKE t552a-tpr01,
    ju LIKE t552a-tpr01,
    vi LIKE t552a-tpr01,
    sa LIKE t552a-tpr01,
    do LIKE t552a-tpr01,
END OF turnos.
* Declaring with TYPE *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Declaring with TYPE *
TYPES: BEGIN OF socio,
    numero LIKE pernr-pernr,
    reposicion LIKE pa0050-zauve,
    nombre LIKE pa0002-vorna,
    turnos TYPE turnos,
END OF socio.
*  Declaring with TYPE*
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
*Declare Internal Table*
DATA: BEGIN OF accesos OCCURS 0,
    socio TYPE socio,
END OF accesos.
*Declare Internal Table *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* START OF SELECTION *
START-OF-SELECTION.
  PERFORM llena_accesos.
  PERFORM descarga_xml.

END-OF-SELECTION.
* END OF SELECTION *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* FORM LLENA_ACCESOS *
FORM llena_accesos.
  REFRESH accesos.
  CLEAR accesos.
  MOVE: '45050' TO accesos-socio-numero,
                'MOISES MORENO' TO accesos-socio-nombre,
                '0' TO accesos-socio-reposicion,
                'T1' TO accesos-socio-turnos-lu,
                'T2' TO accesos-socio-turnos-ma,
                'T3' TO accesos-socio-turnos-mi,
                'T4' TO accesos-socio-turnos-ju,
                'T5' TO accesos-socio-turnos-vi,
                'T6' TO accesos-socio-turnos-sa,
                'T7' TO accesos-socio-turnos-do.
  APPEND accesos.
  CLEAR accesos.
  MOVE: '45051' TO accesos-socio-numero,
                'RUTH PENA' TO accesos-socio-nombre,
                '0' TO accesos-socio-reposicion,
                'T1' TO accesos-socio-turnos-lu,
                'T2' TO accesos-socio-turnos-ma,
                'T3' TO accesos-socio-turnos-mi,
                'T4' TO accesos-socio-turnos-ju,
                'T5' TO accesos-socio-turnos-vi,
                'T6' TO accesos-socio-turnos-sa,
                'T7' TO accesos-socio-turnos-do.
  APPEND accesos.
ENDFORM.                    "LLENA_ACCESOS
* FORM LLENA_ACCESOS *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* FORM DESCARGA_XML *
FORM descarga_xml.
  DATA: l_dom TYPE REF TO if_ixml_element,
                m_document TYPE REF TO if_ixml_document,
                g_ixml TYPE REF TO if_ixml,
                w_string TYPE xstring,
                w_size TYPE i,
                w_result TYPE i,
                w_line TYPE string,
                it_xml TYPE dcxmllines,
                s_xml LIKE LINE OF it_xml,
                w_rc LIKE sy-subrc.

  DATA: xml TYPE dcxmllines.
  DATA: rc TYPE sy-subrc,
  BEGIN OF xml_tab OCCURS 0,
                d LIKE LINE OF xml,
  END OF xml_tab.

  CLASS cl_ixml DEFINITION LOAD.
  g_ixml = cl_ixml=>create( ).
  CHECK NOT g_ixml IS INITIAL.
  m_document = g_ixml->create_document( ).
  CHECK NOT m_document IS INITIAL.
  WRITE: / 'Converting DATA TO DOM 1:'.
  CALL FUNCTION 'SDIXML_DATA_TO_DOM'
    EXPORTING
      name         = 'ACCESOS'
      dataobject   = accesos[]
    IMPORTING
      data_as_dom  = l_dom
    CHANGING
      document     = m_document
    EXCEPTIONS
      illegal_name = 1
      OTHERS       = 2.
  IF sy-subrc = 0.
    WRITE 'Ok'.
  ELSE.
    WRITE: 'Err =',
    sy-subrc.
  ENDIF.
  CHECK NOT l_dom IS INITIAL.
  w_rc = m_document->append_child( new_child = l_dom ).
  IF w_rc IS INITIAL.
    WRITE 'Ok'.
  ELSE.
    WRITE: 'Err =',
    w_rc.
  ENDIF.
  CALL FUNCTION 'SDIXML_DOM_TO_XML'
    EXPORTING
      document      = m_document
    IMPORTING
      xml_as_string = w_string
      size          = w_size
    TABLES
      xml_as_table  = it_xml
    EXCEPTIONS
      no_document   = 1
      OTHERS        = 2.
  IF sy-subrc = 0.
    WRITE 'Ok'.
  ELSE.
    WRITE: 'Err =',
    sy-subrc.
  ENDIF.
  LOOP AT it_xml INTO xml_tab-d.
    APPEND xml_tab.
  ENDLOOP.
  CALL FUNCTION 'WS_DOWNLOAD'
    EXPORTING
      bin_filesize = w_size
      filename     = gk_ruta
      filetype     = 'BIN'
    TABLES
      data_tab     = xml_tab
    EXCEPTIONS
      OTHERS       = 10.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

ENDFORM.                    "DESCARGA_XML
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Programming Techniques | Приемы программирования -> Conversion All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.