Wednesday, June 5, 2013

Consume Web Service in ABAP Stack

During SAP Development along with other system, we need to communicate with other system.
We will focus on one communication type which is web service.

Here is my experience in achieving web service communication.

  1. Create ABAP Proxy. In order for ABAP Stack to consume web service, you will need to generate proxy in ABAP stack. Please go to transaction code se80. As per screen shot, please right click on the Enterprise Service -> choose create














  2. Create Logical Port. Please go to transaction SOAMANAGER. Please follow the screen shot below to create logical port. Please do Ping Web Service after that to see whether web service can be called.






















  3. Test your web service consumer. Go back to transaction code se80. Please open your service consumer. Press Execute as per screen shot below:









  4. Consume in ABAP Function Module. Please see coding below:


    FUNCTION zkrb_test02.
    *"----------------------------------------------------------------------
    *"*"Local Interface:
    *" IMPORTING
    *" VALUE(I_INPUT) TYPE CHAR10 DEFAULT 'kris'
    *" EXPORTING
    *" VALUE(I_OUTPUT) TYPE CHAR10
    *"----------------------------------------------------------------------

    DATA: o_proxy TYPE REF TO zsc_co_zkrb_test01.
    DATA: port_name TYPE prx_logical_port_name.
    DATA: wa_input TYPE zsc_zkrb_test01,
    wa_output TYPE zsc_zkrb_test01response.

    CLEAR: port_name, wa_input, wa_output.

    port_name = 'LP_KRB_TEST01'. "Based on Logical Port we created in soamanager



    TRY.
    CREATE OBJECT o_proxy
    EXPORTING
    logical_port_name = port_name.
    CATCH cx_ai_system_fault .
    ENDTRY.

    * Populate data
    wa_input-i_input = i_input.

    TRY.
    CALL METHOD o_proxy->zkrb_test01
    EXPORTING
    input = wa_input
    IMPORTING
    output = wa_output.
    CATCH cx_ai_system_fault .
    CATCH cx_ai_application_fault .
    ENDTRY.



    i_output = wa_output-e_output.

    ENDFUNCTION.


Notes:
This is in SAP ECC 6.0. You may refer to consume web service in abap stack in other lower version in below website:
http://www.sapdev.co.uk/sap-webapps/sap-webservices/ws_abapproxy.htm