*&---------------------------------------------------------------------*
REPORT z1766_test_xml001.
*----------------------------------------------------------------------*
* 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
阅读(1547) | 评论(0) | 转发(1) |