分类: IT职场
2015-07-15 17:07:01
原文地址:如何解析XML到ABAP内表里 作者:SAP大兵
DATA :RESPONSE TYPE STRING VALUE
'.
'
DATA XMLDATA TYPE XSTRING .
DATA: RESULT_XML TYPE STANDARD TABLE OF SMUM_XMLTB .
DATA: RETURN TYPE STANDARD TABLE OF BAPIRET2 .
DATA: WA_XML TYPE SMUM_XMLTB.
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
TEXT = RESPONSE
IMPORTING
BUFFER = XMLDATA.
CALL FUNCTION 'SMUM_XML_PARSE'
EXPORTING
XML_INPUT = XMLDATA
TABLES
XML_TABLE = RESULT_XML
RETURN = RETURN.
DELETE result_xml WHERE type NE 'A' OR hier NE '3'.
DESCRIBE TABLE result_xml LINES line.
IF result_xml IS NOT INITIAL.
CLEAR lv_index.
CLEAR ls_table.
REFRESH lt_table.
LOOP AT result_xml INTO wa_xml.
lv_index = lv_index + 1.
CLEAR line.
line = lv_index MOD 8.
CASE line.
WHEN 1.
ls_table-partner = wa_xml-cvalue.
WHEN 2.
ls_table-partner_name = wa_xml-cvalue.
WHEN 3.
ls_table-product_id = wa_xml-cvalue.
WHEN 4.
ls_table-product_id_t = wa_xml-cvalue.
WHEN 5.
* ls_table-zdate = wa_xml-cvalue.
ls_table-zdate = lv_date.
WHEN 6.
ls_table-cangku = wa_xml-cvalue.
WHEN 7.
ls_table-cangku_t = wa_xml-cvalue.
WHEN 0.
ls_table-quantity = wa_xml-cvalue.
APPEND ls_table TO lt_table.
CLEAR ls_table.
ENDCASE.
ENDLOOP.