This is show a step by step guide how to invoke a web service from SAP. In this method you do not require additional middleware such as PI/PO. There are three steps you need to follow.
Create proxy object
Create logical port
Create program to consume created proxy object
Prerequisites: You need to have your webservice URL ready Obviously! 😛 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
CREATE OBJECT lo_send_mail
logical_port_name = <PORT_NAME>.
CATCH cx_ai_system_fault .
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
CALL METHOD lo_send_mail-><Method name from se24>
input = ls_input
output = ls_output.
CATCH cx_ai_system_fault INTO lo_error.