文章目录
-
-
- [1 Introduction](#1 Introduction)
- [2 Code](#2 Code)
-
1 Introduction
In the sap there is xml code . We will use the code for it .
2 Code
sql
CALL METHOD LR_PALLET_INFO->LZLJ_1299_SAP_Requirements_PLA
EXPORTING
INPUT = LS_INPUT
IMPORTING
OUTPUT = LS_OUTPUT.
"4.记录返回结果
LV_SIGN = LS_OUTPUT-SIGN.
CONDENSE LV_SIGN NO-GAPS.
LV_MESSAGE = LS_OUTPUT-MESSAGE.
IF LV_SIGN = 'TRUE'.
"4.1 ESB返回成功
"4.1.1解析返回的MESSAGE节点信息
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
TEXT = LV_MESSAGE
IMPORTING
BUFFER = LV_XMLDATA
EXCEPTIONS
FAILED = 1
OTHERS = 2.
IF SY-SUBRC NE 0.
LV_ERROR = 'X'.
LV_MSG = '返回MESSAGE节点XML数据格式错误!'.
ENDIF.
CHECK LV_ERROR IS INITIAL.
CALL FUNCTION 'SMUM_XML_PARSE'
EXPORTING
XML_INPUT = LV_XMLDATA
TABLES
XML_TABLE = LT_XML_INFO
RETURN = LT_RET2
EXCEPTIONS
OTHERS = 0.
LOOP AT LT_RET2 INTO LS_RET2.
CASE LS_RET2-TYPE.
WHEN 'E' OR 'A'.
LV_ERROR = 'X'.
LV_MSG = '解析返回MESSAGE节点XML数据!'.
EXIT.
WHEN OTHERS.
ENDCASE. .
ENDLOOP.
"4.1.2获取MESSAGE节点中解析出来的ITEM节点信息,该节点是SRM返回信息的JSON字符传
CHECK LV_ERROR IS INITIAL.
LOOP AT LT_XML_INFO INTO DATA(LS_XML_INFO) WHERE CNAME = 'ITEM'.
LV_JSON_RES = LV_JSON_RES && LS_XML_INFO-CVALUE.
ENDLOOP.
CONDENSE LV_JSON_RES NO-GAPS.
IF LV_JSON_RES IS INITIAL.
LV_ERROR = 'X'.
LV_MSG = '未获取到SRM返回数据!'.
ENDIF.
CHECK LV_ERROR IS INITIAL.
/UI2/CL_JSON=>DESERIALIZE(
EXPORTING
JSON = LV_JSON_RES
PRETTY_NAME = /UI2/CL_JSON=>PRETTY_MODE-CAMEL_CASE
CHANGING
DATA = LS_OUTPUT ).
IF LS_OUTPUT-SIGN = 'FAILURE'.
EV_STATUS = 'E' .
EV_MESSAGE = '传送数据失败'.
* MESSAGE '传送数据成功' TYPE 'S' DISPLAY LIKE 'S'.
ELSE.
EV_STATUS = 'S' .
EV_MESSAGE = '传送数据成功'.
* MESSAGE '传送数据失败' TYPE 'E' DISPLAY LIKE 'E'.
ENDIF.
ENDIF.
ENDTRY.