2020-11-05
如何解析XML到ABAP內表裡
2970閱讀 0評論2015-05-12 SAP大兵
分類:IT職場
DATA :RESPONSE TYPE STRING VALUE
'
false
90
null
'.
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.
轉載於:http://m.blog.chinaunix.net/uid-29195436-id-5023960.html.