1
Essential SAP ABAP Tutorial
How To Use WEB Services In SAP ABAPBy Eugene Ostroumov
Copyrighted 2012 by LeverX, Inc.
Tutorial OverviewIn this tutorial you will learn how to create and call WEB Services in ABAP. Tutorial consists of two parts:
1)how to create WEB Service based on Function Module;2)how to call WEB Service via ABAP
Each part is a step-by-step instruction that will guide you thru the whole process of creation
2 Copyrighted 2012 by LeverX, Inc.
How to create WEB Service based on FMStep 1
3 Copyrighted 2012 by LeverX, Inc.
Creating a function module with import and export parameters
How to create WEB Service based on FMStep 2
4 Copyrighted 2012 by LeverX, Inc.
As an example of functional module logic let’s extract active users
How to create WEB Service based on FMStep 3
5 Copyrighted 2012 by LeverX, Inc.
Mark the function module as a Remote-Enabled Module
How to create WEB Service based on FMStep 4
6 Copyrighted 2012 by LeverX, Inc.
Create a Web Service based on the function module
How to create WEB Service based on FMStep 5
7 Copyrighted 2012 by LeverX, Inc.
Enter a name and description for the Web Service
NameDescription
How to create WEB Service based on FMStep 6
8 Copyrighted 2012 by LeverX, Inc.
The name of functional module is entered automatically
How to create WEB Service based on FMStep 7
9 Copyrighted 2012 by LeverX, Inc.
Choose a profile forSecurity Settings
How to create WEB Service based on FMStep 8
10 Copyrighted 2012 by LeverX, Inc.
Enter the name of the package and transport request or chooseLocal Object
How to create WEB Service based on FMStep 9
11 Copyrighted 2012 by LeverX, Inc.
Creation of Web Service is finished
It will be activated after pressing “Complete” button
How to create WEB Service based on FMStep 10
12 Copyrighted 2012 by LeverX, Inc.
After creation of Web Service it is important to get WSDL document. It is main key for access to your Web Service. Use the URL or save it to file.
URL
Save to file
How to create WEB Service based on FMStep 11
13 Copyrighted 2012 by LeverX, Inc.
The correctness of the WSDL document can be checked in the transaction SOAMANAGER:
Path: Business Administration => Web-Service Administration
How to create WEB Service based on FMStep 12
14 Copyrighted 2012 by LeverX, Inc.
Web Service can be found in the transaction SICF
Path:default_host => sap => bc =>srt => rfc => sap
How to call WEB Service using ABAPStep 1
15 Copyrighted 2012 by LeverX, Inc.
To call Web Service it is necessary to create a proxy object
Use transaction SE80 to do this
How to call WEB Service using ABAPStep 2
16 Copyrighted 2012 by LeverX, Inc.
Choose “Service Consumer” type of proxy
How to call WEB Service using ABAPStep 3
17 Copyrighted 2012 by LeverX, Inc.
Select a source of WSDL. In our case it is “URL/HTTP Destination”
How to call WEB Service using ABAPStep 4
18 Copyrighted 2012 by LeverX, Inc.
Define URL of WSDL Document
(Step 10 of creation of Web Service)
How to call WEB Service using ABAPStep 5
19 Copyrighted 2012 by LeverX, Inc.
Enter the name of the package and transport request or chooseLocal Object
How to call WEB Service using ABAPStep 6
20 Copyrighted 2012 by LeverX, Inc.
Creation of Proxy is finished. You should activate it after pressing “Complete” button
How to call WEB Service using ABAPStep 7
21 Copyrighted 2012 by LeverX, Inc.
Enter User name and Password to read WSDL Document
This step doesn’t exist is case of local file for WSDL Document
How to call WEB Service using ABAPStep 8
22 Copyrighted 2012 by LeverX, Inc.
Activate the Proxy
How to call WEB Service using ABAPStep 9
23 Copyrighted 2012 by LeverX, Inc.
Now we need to create a local logical port in transaction SOAMANAGER
Path: Business Administration => Web-Service Administration
Choose “Consumer Proxy”
Search your Proxy by name
Choose your Proxy
Apply Selection
Create Logical Port
How to call WEB Service using ABAPStep 10
24 Copyrighted 2012 by LeverX, Inc.
Enter general configuration settings
You can use WSDL document or do it manually
How to call WEB Service using ABAPStep 11
25 Copyrighted 2012 by LeverX, Inc.
Save logical port after it is generated
Save
How to call WEB Service using ABAPStep 12
26 Copyrighted 2012 by LeverX, Inc.
Now everything is done and you can call Web Service from your ABAP program
Here is an example of a report that shows all active users
REPORT zws_call.
DATA: lr_proxy TYPE REF TO zws_co_z_get_active_users.DATA: o_err TYPE REF TO cx_root.DATA: output TYPE zws_zws_users_response.DATA: input TYPE zws_zws_users.DATA: ls_item TYPE LINE OF zws_zws_users_response-users-item.
TRY. CREATE OBJECT lr_proxy EXPORTING logical_port_name = 'GET_USERS'. CATCH cx_ai_system_fault INTO o_err. MESSAGE o_err TYPE 'I'.ENDTRY.input-rfc_only = space.TRY. CALL METHOD lr_proxy->zws_users EXPORTING input = input IMPORTING output = output. CATCH cx_ai_system_fault INTO o_err. MESSAGE o_err TYPE 'I'. CATCH cx_ai_application_fault INTO o_err. MESSAGE o_err TYPE 'I'.ENDTRY.
LOOP AT output-users-item INTO ls_item. WRITE: / ls_item-bname, ls_item-tcode, ls_item-term.ENDLOOP.
Conclusion
27 Copyrighted 2012 by LeverX, Inc.
Mobile applications
Another systems
WEB
Your SAP system
Web Services allow to increase functionality of your system and leverage your investments
Web applications
Contact Information
Please contact us for more information about our services or solutions available.
LeverX, Inc. 800 West El Camino Real, Suite 180
Mountain View, CA 94040 USATel: (650) 625 – 8347
Web Site: www.LeverX.com28 Copyrighted 2012 by LeverX, Inc.