*&---------------------------------------------------------------------*
*& Report Z1766_TEST_XML
*&
*&---------------------------------------------------------------------*
*& Report Z1766_TEST_XML
*&
*&---------------------------------------------------------------------*
REPORT z1766_test_xml.
*DATA:itab_item TYPE TABLE OF z1crm_sales_item.
DATA: BEGIN OF s_head,
order_id LIKE z1crm_sales_head-order_id,
status_h LIKE z1crm_sales_head-status_h,
creat_date_h LIKE z1crm_sales_head-creat_date_h,
creat_time_h LIKE z1crm_sales_head-creat_time_h,
sold_to LIKE z1crm_sales_head-sold_to,
ship_to LIKE z1crm_sales_head-ship_to,
cont_total LIKE z1crm_sales_head-cont_total,
zzroute LIKE z1crm_sales_head-zzroute,
ship_cond LIKE z1crm_sales_head-ship_cond,
pmnttrms LIKE z1crm_sales_head-pmnttrms,
END OF s_head,
itab_head LIKE STANDARD TABLE OF s_head.
DATA: BEGIN OF s_item,
itemcode LIKE z1crm_sales_item-number_int,
pn_group LIKE z1crm_sales_item-pn_group,
matnr LIKE z1crm_sales_item-matnr,
charg LIKE z1crm_sales_item-charg,
status_i LIKE z1crm_sales_item-status_i,
END OF s_item,
itab_item LIKE STANDARD TABLE OF s_item.
*DATA:itab_item TYPE TABLE OF z1crm_sales_item.
DATA: BEGIN OF s_head,
order_id LIKE z1crm_sales_head-order_id,
status_h LIKE z1crm_sales_head-status_h,
creat_date_h LIKE z1crm_sales_head-creat_date_h,
creat_time_h LIKE z1crm_sales_head-creat_time_h,
sold_to LIKE z1crm_sales_head-sold_to,
ship_to LIKE z1crm_sales_head-ship_to,
cont_total LIKE z1crm_sales_head-cont_total,
zzroute LIKE z1crm_sales_head-zzroute,
ship_cond LIKE z1crm_sales_head-ship_cond,
pmnttrms LIKE z1crm_sales_head-pmnttrms,
END OF s_head,
itab_head LIKE STANDARD TABLE OF s_head.
DATA: BEGIN OF s_item,
itemcode LIKE z1crm_sales_item-number_int,
pn_group LIKE z1crm_sales_item-pn_group,
matnr LIKE z1crm_sales_item-matnr,
charg LIKE z1crm_sales_item-charg,
status_i LIKE z1crm_sales_item-status_i,
END OF s_item,
itab_item LIKE STANDARD TABLE OF s_item.
DATA: BEGIN OF adminfo,
object TYPE string,
version TYPE string,
END OF adminfo,
adminfo_itab LIKE STANDARD TABLE OF adminfo.
PARAMETERS:order_id LIKE z1crm_sales_head-order_id DEFAULT '8895100207'.
PARAMETERS: p_show AS CHECKBox DEFAULT 'X'.
CONSTANTS:
c_xml_root TYPE string VALUE 'BOM',
c_xml_adminfo TYPE string VALUE 'AdmInfo',
c_xml_documents TYPE string VALUE 'Documents',
c_xml_document_lines TYPE string VALUE 'Document_Lines',
c_xml_bo TYPE string VALUE 'BO'.
DATA:
g_xml TYPE REF TO cl_xml_document.",
object TYPE string,
version TYPE string,
END OF adminfo,
adminfo_itab LIKE STANDARD TABLE OF adminfo.
PARAMETERS:order_id LIKE z1crm_sales_head-order_id DEFAULT '8895100207'.
PARAMETERS: p_show AS CHECKBox DEFAULT 'X'.
CONSTANTS:
c_xml_root TYPE string VALUE 'BOM',
c_xml_adminfo TYPE string VALUE 'AdmInfo',
c_xml_documents TYPE string VALUE 'Documents',
c_xml_document_lines TYPE string VALUE 'Document_Lines',
c_xml_bo TYPE string VALUE 'BO'.
DATA:
g_xml TYPE REF TO cl_xml_document.",
START-OF-SELECTION.
REFRESH:itab_head,itab_item.
SELECT * INTO CORRESPONDING FIELDS OF TABLE itab_head
FROM z1crm_sales_head
WHERE order_id = order_id.
READ TABLE itab_head INTO s_head INDEX 1.
REFRESH:itab_head,itab_item.
SELECT * INTO CORRESPONDING FIELDS OF TABLE itab_head
FROM z1crm_sales_head
WHERE order_id = order_id.
READ TABLE itab_head INTO s_head INDEX 1.
SELECT number_int AS itemcode pn_group matnr charg status_i
INTO CORRESPONDING FIELDS OF TABLE itab_item
FROM z1crm_sales_item
WHERE order_id = order_id.
INTO CORRESPONDING FIELDS OF TABLE itab_item
FROM z1crm_sales_item
WHERE order_id = order_id.
adminfo-object = '17'.
adminfo-version = '2'.
END-OF-SELECTION.
DATA:
mtd_name TYPE string,
class_root TYPE REF TO if_ixml_node,
class_bo TYPE REF TO if_ixml_node.
adminfo-version = '2'.
END-OF-SELECTION.
DATA:
mtd_name TYPE string,
class_root TYPE REF TO if_ixml_node,
class_bo TYPE REF TO if_ixml_node.
CREATE OBJECT g_xml
EXPORTING
description = 'test'
object_type = cl_xml_document=>c_bor_classtype.
* object_name = s_head-mill.
EXPORTING
description = 'test'
object_type = cl_xml_document=>c_bor_classtype.
* object_name = s_head-mill.
* Simply generate sections of XML document
* First create root section
g_xml->set_data( name = c_xml_root
dataobject = '' ).
g_xml->set_data( name = c_xml_root
dataobject = '' ).
class_root = g_xml->find_node( name = c_xml_root ).
g_xml->set_data( name = c_xml_bo
parent_node = class_root
dataobject = '' ).
class_bo = g_xml->find_node( name = c_xml_bo ).
parent_node = class_root
dataobject = '' ).
class_bo = g_xml->find_node( name = c_xml_bo ).
* All other sections will be under the root (see parent_node)
DEFINE set_section_data.
g_xml->set_data( name = &1
parent_node = class_bo
dataobject = &2 ).
END-OF-DEFINITION.
DEFINE set_section_data.
g_xml->set_data( name = &1
parent_node = class_bo
dataobject = &2 ).
END-OF-DEFINITION.
set_section_data:
'AdmInfo' '',
'Object' adminfo-object,
'Version' adminfo-version,
'Documents' s_head,
'Document_Lines' itab_item .
* LOOP AT itab_item INTO s_item.
* set_section_data:
* 'row' s_item.
* ENDLOOP.
'AdmInfo' '',
'Object' adminfo-object,
'Version' adminfo-version,
'Documents' s_head,
'Document_Lines' itab_item .
* LOOP AT itab_item INTO s_item.
* set_section_data:
* 'row' s_item.
* ENDLOOP.
* Now display resulting XML-file or export it into workstation file
mtd_name = order_id.
IF p_show = 'X'.
g_xml->display( ).
EXIT.
ENDIF.
g_xml->display( ).
EXIT.
ENDIF.
DATA:
user_action TYPE i,
path TYPE string,
full_path TYPE string,
file_name TYPE string.
user_action TYPE i,
path TYPE string,
full_path TYPE string,
file_name TYPE string.
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
default_extension = 'xml'
default_file_name = mtd_name
file_filter = cl_gui_frontend_services=>filetype_xml
CHANGING
filename = file_name
path = path
fullpath = full_path
user_action = user_action
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
EXPORTING
default_extension = 'xml'
default_file_name = mtd_name
file_filter = cl_gui_frontend_services=>filetype_xml
CHANGING
filename = file_name
path = path
fullpath = full_path
user_action = user_action
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CHECK user_action = cl_gui_frontend_services=>action_ok.
DATA:
localfile TYPE localfile.
localfile TYPE localfile.
localfile = full_path.
g_xml->export_to_file( filename = localfile ).
执行结果:
原文链接:https://www.f2er.com/xml/295902.html
xml version="1.0"?>
<
AdmInfo
/>
<
Object
>
17
Object>
<
Version
>
2
Version>
<
ORDER_ID
>
8895100207
ORDER_ID>
<
STATUS_H
>
A
STATUS_H>
<
CREAT_DATE_H
>
2009-07-09
CREAT_DATE_H>
<
CREAT_TIME_H
>
16:00:24
CREAT_TIME_H>
<
SOLD_TO
>
0006000056
SOLD_TO>
<
SHIP_TO
>
0006000056
SHIP_TO>
<
CONT_TOTAL
>
1*20GP*22.00
CONT_TOTAL>
<
ZZROUTE
>
B3US79
ZZROUTE>
<
SHIP_COND
>
11
SHIP_COND>
<
PMNTTRMS
>
N030
PMNTTRMS>
Documents>
<
ITEMCODE
>
0000000010
ITEMCODE>
<
PN_GROUP
>
GZ0300
PN_GROUP>
<
MATNR
>
43250003
MATNR>
<
CHARG
>
0000000003
CHARG>
<
STATUS_I
>
A010
STATUS_I>
item>
<
ITEMCODE
>
0000000020
ITEMCODE>
<
PN_GROUP
>
GZ0300
PN_GROUP>
<
MATNR
>
43250003
MATNR>
<
CHARG
>
0000000003
CHARG>
<
STATUS_I
>
A010
STATUS_I>
item>
<
ITEMCODE
>
0000000030
ITEMCODE>
<
PN_GROUP
>
GZ0300
PN_GROUP>
<
MATNR
>
43255002
MATNR>
<
CHARG
>
0000000093
CHARG>
<
STATUS_I
>
A010
STATUS_I>
item>
<
ITEMCODE
>
0000000040
ITEMCODE>
<
PN_GROUP
>
GZ0300
PN_GROUP>
<
MATNR
>
43255002
MATNR>
<
CHARG
>
0000000093
CHARG>
<
STATUS_I
>
A010
STATUS_I>
item>
Document_Lines>
BO>