zoukankan      html  css  js  c++  java
  • 如何在SAP ABAP系统里创建和消费Web Service

    This document could be used as guide for beginners to learn and use ABAP web service.

    How to create web service provider in ABAP system

    The following steps demonstrates how to expose a function module as a web service provider in SAP CRM system.

    (1) create a new function module to return product description by given input product ID.
    Signature and source code of function module:

    FUNCTION ZGET_PROD_DESCRIPTION.
    *"----------------------------------------------------------------------
    *"*"Local Interface:
    *"  IMPORTING
    *"     VALUE(IV_PROD_ID) TYPE  COMM_PRODUCT-PRODUCT_ID
    *"  EXPORTING
    *"     VALUE(RV_TEXT) TYPE  STRING
    *"----------------------------------------------------------------------
    SELECT SINGLE A~short_text INTO rv_text FROM COMM_PRSHTEXT  AS A
      INNER JOIN comm_product AS B ON B~product_id = iv_prod_id AND B~product_guid = A~product_guid.
    ENDFUNCTION.
    

    Make sure the FM is marked as “Remote enabled”.

    (2) start the web service creation wizard:

    Just follow the wizard to finish creation. Choose the appropriate authentication approach according to your use case.

    (3) Once creation is finished, you would find your service definition as below:

    click tab WSDL, write down your WSDL link:

    (4) use tcode SOAMANAGER, click Web Service Configuration

    you can find your service definition created just now:

    click the hyperlink and create a new service:

    For security reasons choose radio box “SSL”.

    click Finish button:

    Now your web service is ready for consumption. click this icon:

    write down this link for later usage.

    How to consume web service in ABAP system

    (1) tcode SE80, create a new service consumer:

    (2) Choose external WSDL:

    choose the url got from last step of chapter “How to create web service provider in ABAP system”:

    activate your consumer proxy and write down the ABAP class name.

    (3) go back to SOAMANAGER, find the consumer proxy created in step2:

    create a new logical port:


    (4) Make sure you specify URL got from the last step of web service creation chapter. If you just use the URL got from SE80 in tab “WSDL”, you will meet withbelow error.

    (5) consume the web service in ABAP report:
    you can find the data type for input and output parameters in SE80:

    data: lr_proxy TYPE REF TO CO_ZPRODUCTDESCRIPTION4,
    input TYPE ZGET_PROD_DESCRIPTION,
    output TYPE ZGET_PROD_DESCRIPTION_RESPONSE.
    input-iv_prod_id = 'ARNO_TEST004'.
    CREATE OBJECT lr_proxy
         EXPORTING
                LOGICAL_PORT_NAME = 'ZLP_JERRY1'.
    CALL METHOD lr_proxy->ZGET_PROD_DESCRIPTION
         EXPORTING
                input = input
         IMPORTING
                output = output.
    

    Now we execute the report and get the web service execution result as expected:

    The product description in UI:

    How to trace the web service execution

    Use tcode SRT_UTIL, add a new configuration for your user which triggers the web service call:

    Set the Functional Trace to “High”. You could also enable Performance and Payload trace if necessary.
    Click Save Configuration button to persist the change.

    Execute the report which triggers the web service call. After it finishes, click tab “Functional Trace” and click refresh button, you should see several records for execution trace.

    Double click and select the row with type “Response”, where you could find the product description value returned by service provider.

    要获取更多Jerry的原创文章,请关注公众号"汪子熙":

  • 相关阅读:
    406, "PRECONDITION_FAILED
    windows10x64环境安装RabbitMQ
    jquery插件formValidator的ajaxValidator传参数问题
    “~/Views/Home/Text.aspx”处的视图必须派生自 ViewPage、ViewPage<TModel>、ViewUserControl 或 ViewUserControl<TModel>。
    无法安装程序包“MIcrosoft.Owin.Security 2.0.2”。您正在尝试将此程序包安装到某个将“.NETFramework,Version=v4.0”作为目标的项目中。
    MSSQL优化之——查看语句执行情况
    C# 测试代码运行时间
    转换 Html 内容为纯文本内容(html,文本互转)
    腾讯微博OAuth2.0 .NET4.0 SDK 发布以及网站腾讯微博登陆示例代码(原创)
    QQ互联OAuth2.0 .NET SDK 发布以及网站QQ登陆示例代码(转)
  • 原文地址:https://www.cnblogs.com/sap-jerry/p/13614070.html
Copyright © 2011-2022 走看看