XML解析服务

文章目录

      • [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.
相关推荐
爱喝水的鱼丶14 天前
SAP-ABAP:SAP外网接口调用技术全景指南
运维·http·sap·abap·erp·接口调用·开发运维
爱喝水的鱼丶16 天前
SAP -ABAP:SAP 业务能力培养体系(结构化学习路径)
运维·开发语言·sap·abap·erp·业务学习
爱喝水的鱼丶1 个月前
SAP-ABAP:SAP数据库视图(Database View)详解-创建
sap·abap·erp·企业级应用·经验交流
聆听-往昔1 个月前
SAP Webide系列(7)- 优化FreeStyle新建项目预设模板
前端·sap·开发工具·fiori·sap ui5·webide
izumisrcd2 个月前
Fiori APP配置中的Semantic object 小bug
sap
爱喝水的鱼丶2 个月前
SAP-ABAP:SAP中REPORT程序和online程序的区别对比
sap·abap·erp·企业应用·开发运维
数字化转型20252 个月前
SAP CO End-User Training Material Document Agenda
sap
SAP学习成长之路2 个月前
了解 ALV 中的 field catalog (ABAP List Viewer)
开发语言·sap·abap
天边浮云2 个月前
ABAP 获取用户参数文件
经验分享·sap
山茶花开时。2 个月前
[SAP ABAP] 静态断点的使用
开发语言·sap·abap