内表生成XML简单实例

前端之家收集整理的这篇文章主要介绍了内表生成XML简单实例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
REPORTzlm_xml_02 .

*&---------------------------------------------------------------------*
*&声明及定义部分
*&---------------------------------------------------------------------*

TYPE-POOLS :ixml .

****声明存放XML文件的结构
TYPES : BEGIN OFxml_line ,
data ( 256 ) TYPE x ,
END OFxml_line .

****声明对象
DATA :l_ixml TYPE REF TOif_ixml ,
l_streamfactory TYPE REF TOif_ixml_stream_factory ,
l_ostream TYPE REF TOif_ixml_ostream ,
l_renderer TYPE REF TOif_ixml_renderer ,
l_document TYPE REF TOif_ixml_document .

****声明XML元素
DATA :l_element_inpot TYPE REF TOif_ixml_element ,
l_element_matnr TYPE REF TOif_ixml_element ,
l_element_art TYPE REF TOif_ixml_element ,
l_element_prueflos TYPE REF TOif_ixml_element ,
l_element_budat TYPE REF TOif_ixml_element ,
l_element_losmenge TYPE REF TOif_ixml_element ,
l_element_enstehdat TYPE REF TOif_ixml_element ,
l_value TYPEstring .

****声明存放XML文件的内表以及字节数
DATA :l_xml_table TYPE TABLE OFxml_line ,
l_xml_size TYPE i ,
l_rc TYPE i ,
flag TYPEstring .

****声明数据内表
DATA : BEGIN OFi_data OCCURS 0 ,
matnr LIKEqals -matnr ,
prueflos LIKEqals -prueflos ,
art LIKEqals -art ,
budat LIKEqals -budat ,
losmenge LIKEqals -losmenge ,
enstehdat LIKEqals -enstehdat ,
END OFi_data .

*&---------------------------------------------------------------------*
*&主逻辑部分
*&---------------------------------------------------------------------*

START-OF-SELECTION .
PERFORMzform_get_data .
PERFORMzform_save_xml .


*&---------------------------------------------------------------------*
*&FORM定义部分
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&Formzform_get_data
*&---------------------------------------------------------------------*
*text
*----------------------------------------------------------------------*
FORMzform_get_data .
SELECTmatnr art prueflos budat losmenge enstehdat
INTOCORRESPONDING FIELDS OF TABLEi_data
FROMqals
WHEREbudat = '20000412' .
ENDFORM . "zform_get_data

*&---------------------------------------------------------------------*
*&Formsave_xml
*&---------------------------------------------------------------------*
*text
*----------------------------------------------------------------------*
FORMzform_save_xml .
LOOP ATi_data .
****创建一个XML容器
AT FIRST .
l_ixml =cl_ixml => create ( ) .
****创建一个文档对象模型
l_document =l_ixml ->create_document ( ) .
****填充根节点
l_element_inpot =l_document ->create_simple_element (
name = 'INPOT'
parent =l_document ) .
ENDAT .
AT NEWmatnr .
****填充子节点(物料)
l_value =i_data -matnr .
l_element_matnr =l_document ->create_simple_element (
name = 'MATNR'
value =l_value
parent =l_element_inpot ) .
flag =flag + 1 .
l_rc =l_element_matnr ->set_attribute (name = 'ID' value =
flag ) .
ENDAT .
****填充子节点(检验批)
AT NEWprueflos .
l_value =i_data -prueflos .
l_element_prueflos =l_document ->create_simple_element (
name = 'PRUEFLOS'
value =l_value
parent =l_element_matnr ) .
ENDAT .
****填充子节点(检验批细节)
l_value =i_data -art .
l_element_art =l_document ->create_simple_element (
name = 'ART'
value =l_value
parent =l_element_prueflos ) .

l_value =i_data -budat .
l_element_budat =l_document ->create_simple_element (
name = 'BUDAT'
value =l_value
parent =l_element_prueflos ) .

l_value =i_data -enstehdat .
l_element_enstehdat =l_document ->create_simple_element (
name = 'ENSTEHDAT'
value =l_value
parent =l_element_prueflos ) .

l_value =i_data -losmenge .
l_element_losmenge =l_document ->create_simple_element (
name = 'LOSMENGE'
value =l_value
parent =l_element_prueflos ) .
ENDLOOP .
****创建一个流容器
l_streamfactory =l_ixml ->create_stream_factory ( ) .
****连接内部XML表到流容器
l_ostream =l_streamfactory ->create_ostream_itable (
table =l_xml_table ) .
****递交XML文档
l_renderer =l_ixml ->create_renderer (ostream =l_ostream
document =l_document ) .
l_rc =l_renderer ->render ( ) .
****保存XML文档
l_xml_size =l_ostream ->get_num_written_raw ( ) .
CALL METHODcl_gui_frontend_services =>gui_download
EXPORTING
bin_filesize =l_xml_size
filename = 'c:\temp\INPOT.xml'
filetype = 'BIN'
CHANGING
data_tab =l_xml_table
EXCEPTIONS
OTHERS = 24 .
IFsy -subrc = 0 .
MESSAGE 'XML文件保存成功!!!!' TYPE 'I' .
STOP .
ENDIF .
ENDFORM . "save_xml
原文链接:https://www.f2er.com/xml/299223.html

猜你在找的XML相关文章