REPORT YTST_XML_14.
*----------------------------------------------------------------------*
* PANTALLA SELECCION *
PARAMETERS: GK_RUTA TYPE RLGRAP-FILENAME DEFAULT ‘C:\ECC6.XML‘.
* PANTALLA SELECCION *
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* 针对XML文件的特殊结构需要构造一个特殊的数据结构
* 定义一个下层节点
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.
* TYPE TURNOS *
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* 根据XML file stru 嵌套一下
TYPES:BEGIN OF SOCIO,
NUMERO LIKE PERNR-PERNR,
REPOSICION LIKE PA0050-ZAUVE,
NOMBRE LIKE PA0002-VORNA,
TURNOS TYPE TURNOS,
END OF SOCIO.
* TYPE SOCIO *
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* 放到哪里呢,当然是internal table
DATA:BEGIN OF ACCESOS OCCURS 0,
SOCIO TYPE SOCIO,
END OF ACCESOS.
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM LLENA_ACCESOS.
PERFORM DESCARGA_XML.
END-OF-SELECTION.
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
FORM LLENA_ACCESOS.
REFRESH ACCESOS.
CLEAR ACCESOS.
* 开始填充了,这里只搞两个基本Item
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. "LLENA_ACCESOS
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* FORM DESCARGA_XML *
FORM DESCARGA_XML.
DATA: L_DOM TYPE REF TO IF_IXML_ELEMENT, " XML 元素对象,也可以叫一个Item
M_DOCUMENT TYPE REF TO IF_IXML_DOCUMENT, " XML 文件对象
G_IXML TYPE REF TO IF_IXML, " XML 接口对象
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.
* 先装载一个XML对象,象JAVA的IMPORT一样
CLASS CL_IXML DEFINITION LOAD.
* 创建一个XML文件对象
G_IXML = CL_IXML=>CREATE( ).
CHECK NOT G_IXML IS INITIAL.
* 创建一个XML文件
M_DOCUMENT = G_IXML->CREATE_DOCUMENT( ).
CHECK NOT M_DOCUMENT IS INITIAL.
WRITE: / ‘Converting DATA TO DOM 1:‘.
* 这下好了,该创建XML元素了,创建时参考了元素的数据结构‘ACCESOS‘
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.
* 好了,该转换XML File了,添加该死的</>,不要怪我老带着一点恨劲,被逼的!
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 ‘GUI_DOWNLOAD‘
EXPORTING
BIN_FILESIZE = W_SIZE
FILENAME = GK_RUTA
FILETYPE = ‘BIN‘
TABLES
DATA_TAB = XML_TAB.
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