Sample XML Source Code For SAP

A XML source code for sap or abap.

*&---------------------------------------------------------------------*
*& Report  ZULH_MM_RP_XMLtest001
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZULH_MM_RP_XMLtest001.

PARAMETERS: GK_RUTA TYPE RLGRAP-FILENAME DEFAULT 'C:\test01.XML'.

* TYPE TURNOS *
TYPES: BEGIN OF TURNOS,
    LU LIKE T552A-TPR01,
    MA LIKE T552A-TPR01,
    MI LIKE T552A-TPR01,
    JU LIKE T552A-TPR01,
    VI LIKE T55AA-TPR01,
    SA LIKE T552A-TPR01,
    DO LIKE T552A-TPR01,
END OF TURNOS.
* TYPE TURNOS *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* TYPE SOCIO *
TYPES: BEGIN OF SOCIO,
    NUMERO LIKE PERNR-PERNR,
    REPOSICION LIKE PA0050-ZAUVE,
    NOMBRE LIKE PA0002-VORNA,
    TURNOS TYPE TURNOS,
END OF SOCIO.
* TYPE SOCIO *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* ESTRUCTURA ACCESOS *
DATA: BEGIN OF ACCESOS OCCURS 0,
    SOCIO TYPE SOCIO,
END OF ACCESOS.
* ESTRUCTURA ACCESOS *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* 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 PEÑA' 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.
* 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.
Tips by : Abdurrahim Mazlumoglu

Get help for your ABAP problems
Do you have a ABAP Question?

SAP Books
SAP Certification, Functional, Basis Administration and ABAP Programming Reference Books

ABAP Tips
ABAP Forum for Discussion and Samples Program Codes for Abapers

Best regards,
SAP Basis, ABAP Programming and Other IMG Stuff
http://www.erpgreat.com

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.