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的原创文章,请关注公众号"汪子熙":

  • 相关阅读:
    linux下svn命令大全
    php常用函数
    在centos上设置计划任务
    sphinx使用心得
    sphinx2.8.8的配置文件
    Mac使用
    sftp
    uwp应用在debug模式下运行正常,编译为release版本的时候抛出异常
    win10 uwp 读取resw资源文件
    dll被设置为用记事本打开的解决方法
  • 原文地址:https://www.cnblogs.com/sap-jerry/p/13614070.html
Copyright © 2011-2022 走看看