ABAP- 调用 WebService 服务

SAP 中有用到外部 WebService 接口进行数据传输的场景,因此需要进行 WebService 接口的配置,这边整理一下调用外部 WebService 接口的配置及开发过程


SE80 找到对应的包配置企业服务

以上企业服务配置完成。


SOAMANAGER 配置


在程序中引用 Z_HCX_WSDL

*&---------------------------------------------------------------------*
*& Report Z_HCX_WSDL
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT z_hcx_wsdl.

DATA:lo_clientproxy   TYPE REF TO zhcx_co_zcrm_get_menge, "企业服务中配置的ABAP_NAME,可以在SE24中看到
     lo_sys_exception TYPE REF TO cx_ai_system_fault,
     lo_app_exception TYPE REF TO cx_ai_application_fault,
     wa_index         TYPE c,
     ls_input         TYPE zhcx_zcrm_get_menge,        "SE24:zhcx_co_zcrm_get_menge->ZCRM_GET_MENGE->INPUT参数
     ls_output        TYPE zhcx_zcrm_get_mengeresponse. "SE24:zhcx_co_zcrm_get_menge->ZCRM_GET_MENGE->OUTPUT参数


TRY.
    CREATE OBJECT lo_clientproxy
      EXPORTING
        logical_port_name = 'ZHCX_CO_ZCRM_GET_MENGE'. "SOAMANAGER中创建的逻辑端口
    APPEND VALUE #( sign = 'I'
                    option = 'EQ'
                    low = 'S190304002'
                    high = '' ) TO ls_input-i_data-item.
    CALL METHOD lo_clientproxy->zcrm_get_menge "SE24:zhcx_co_zcrm_get_menge->ZCRM_GET_MENGE
      EXPORTING
        input  = ls_input
      IMPORTING
        output = ls_output.
    LOOP AT ls_output-e_data-item INTO DATA(ls_item).
      WRITE:/ ls_item-posnr.
    ENDLOOP.
*为此webservice创建的逻辑端口
  CATCH cx_ai_system_fault .
    MESSAGE '出错了' TYPE 'E'.
    wa_index = '1'.
ENDTRY.

转载于:https://zhuanlan.zhihu.com/p/382497100

posted @ 2022-08-04 12:22  阿胖的阿多  阅读(1018)  评论(0编辑  收藏  举报