Consume Web Service from SAP - Sap 4 All

Latest

Please enter your email and get the updates in your inbox.

Friday 15 April 2016

Consume Web Service from SAP

This is show a step by step guide how to invoke a web service from SAP. There are three steps you need to follow. 
  1. Create proxy object
  2. Create logical port
  3. Create program to consume created proxy object
Prerequisites: You need to have your webservice URL ready Obviously! :P Check the webservice URL using IE to check the attributes and methods. This will give you a understanding of the behavior of the service.

I will explain each step with more detail.

1. Create Proxy Object

We need to create proxy object in SAP for the web-service URL you are going to invoke.
eg URL: http://<IP of the host>:8090/<Namespace>/<Service Name>.asmx?WSDL

Go to se80>select package>right click>Create>Enterprise Services/Web Services>Proxy Object














Select URL/HTTP Destination option and type in the web service URL and click ok. Give the Class name.









If the URL is available and without any errors, proxy object will be generated.

You can check the created class using transaction se24. Select the method and it's parameters you are going to access. This will be needed to create data objects at 3rd step.

2. Create logical port 

Go to transaction "lpconfig" and create logical port with the desired name.






Hit the create button.

Give the webservice URL in call parameter tab as below.













3. Create program


Proxy object and port are created, now we write a program to access methods of the created proxy class. You need to have a understanding of basic ABAP OO concepts to develop this program.

Using se24, check the structure and parameters of the method of proxy class. 

Basic structure of the program is as below:

DATA: lo_send_mail  TYPE REF TO zproxy_class.
ls_input TYPE <check_se24>,  
ls_output TYPE <check_se24>.  

*create object: Port name = Port created in step 2
TRY.
    CREATE OBJECT lo_send_mail
      EXPORTING
        logical_port_name  = <PORT_NAME>.

  CATCH cx_ai_system_fault .
ENDTRY

This section of the code should include the logic to fill the ls_input or any other parameters that need to pass to the proxy object method. 

*call desired method with correct parameters 
TRY.

    CALL METHOD lo_send_mail-><Method name from se24>
          EXPORTING
            input  = ls_input
          IMPORTING
            output = ls_output.
    CATCH cx_ai_system_fault INTO lo_error.
    CATCH cx_ai_application_fault.

ENDTRY.

3 comments:

  1. Very nice information thank you for sharing. Know more about SAPUI5 Training

    ReplyDelete
  2. Thanks for sharing this Information,

    Got to learn new things from your Blog on Sap abap.

    http://thecreatingexperts.com/sap-abap-training-in-chennai/

    Both online and classroom training is provided.

    Contact 8122241286

    ReplyDelete