Sie sind auf Seite 1von 28

Essential

SAP ABAP Tutorial


How To Use WEB Services In SAP ABAP
By Eugene Ostroumov

1 Copyrighted 2012 by LeverX, Inc.


Tutorial Overview
In 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 FM
Step 1
Creating a
function module
with
import and export
parameters

3 Copyrighted 2012 by LeverX, Inc.


How to create WEB Service based on FM
Step 2
As an example of
functional module
logic let’s extract
active users

4 Copyrighted 2012 by LeverX, Inc.


How to create WEB Service based on FM
Step 3
Mark the function
module as a
Remote-Enabled
Module

5 Copyrighted 2012 by LeverX, Inc.


How to create WEB Service based on FM
Step 4
Create a
Web Service
based on the
function module

6 Copyrighted 2012 by LeverX, Inc.


How to create WEB Service based on FM
Step 5
Enter a name and
description for the
Web Service

Name
Description

7 Copyrighted 2012 by LeverX, Inc.


How to create WEB Service based on FM
Step 6
The name of
functional module
is entered
automatically

8 Copyrighted 2012 by LeverX, Inc.


How to create WEB Service based on FM
Step 7
Choose a
profile for
Security Settings

9 Copyrighted 2012 by LeverX, Inc.


How to create WEB Service based on FM
Step 8
Enter the name of
the package and
transport request
or choose
Local Object

10 Copyrighted 2012 by LeverX, Inc.


How to create WEB Service based on FM
Step 9
Creation of Web
Service is finished
It will be activated
after pressing
“Complete” button

11 Copyrighted 2012 by LeverX, Inc.


How to create WEB Service based on FM
Step 10
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

12 Copyrighted 2012 by LeverX, Inc.


How to create WEB Service based on FM
Step 11
The correctness
of the WSDL
document can be
checked in the
transaction
SOAMANAGER:
Path:
Business
Administration =>
Web-Service
Administration

13 Copyrighted 2012 by LeverX, Inc.


How to create WEB Service based on FM
Step 12
Web Service can
be found in the
transaction SICF
Path:
default_host =>
sap => bc =>
srt => rfc => sap

14 Copyrighted 2012 by LeverX, Inc.


How to call WEB Service using ABAP
Step 1
To call Web
Service it is
necessary to
create a proxy
object
Use transaction
SE80 to do this

15 Copyrighted 2012 by LeverX, Inc.


How to call WEB Service using ABAP
Step 2
Choose
“Service Consumer”
type of proxy

16 Copyrighted 2012 by LeverX, Inc.


How to call WEB Service using ABAP
Step 3
Select a source of
WSDL. In our case
it is “URL/HTTP
Destination”

17 Copyrighted 2012 by LeverX, Inc.


How to call WEB Service using ABAP
Step 4
Define URL of
WSDL Document
(Step 10 of creation
of Web Service)

18 Copyrighted 2012 by LeverX, Inc.


How to call WEB Service using ABAP
Step 5
Enter the name of
the package and
transport request
or choose
Local Object

19 Copyrighted 2012 by LeverX, Inc.


How to call WEB Service using ABAP
Step 6
Creation of Proxy
is finished. You
should activate it
after pressing
“Complete” button

20 Copyrighted 2012 by LeverX, Inc.


How to call WEB Service using ABAP
Step 7
Enter User name and
Password to read
WSDL Document
This step doesn’t
exist is case of local
file for WSDL
Document

21 Copyrighted 2012 by LeverX, Inc.


How to call WEB Service using ABAP
Step 8

Activate the Proxy

22 Copyrighted 2012 by LeverX, Inc.


How to call WEB Service using ABAP
Step 9
Now we need to Choose “Consumer Proxy”
create a local
logical port in
transaction
SOAMANAGER Search your Proxy by name
Choose your Proxy
Path:
Business Apply Selection
Administration => Create Logical Port
Web-Service
Administration

23 Copyrighted 2012 by LeverX, Inc.


How to call WEB Service using ABAP
Step 10
Enter general
configuration
settings
You can use
WSDL document
or do it manually

24 Copyrighted 2012 by LeverX, Inc.


How to call WEB Service using ABAP
Step 11
Save logical port
after it is
generated

Save

25 Copyrighted 2012 by LeverX, Inc.


How to call WEB Service using ABAP
Step 12
REPORT zws_call.
Now everything is done DATA: lr_proxy TYPE REF TO zws_co_z_get_active_users.
DATA: o_err TYPE REF TO cx_root.
and you can call Web DATA:
DATA:
output TYPE zws_zws_users_response.
input TYPE zws_zws_users.

Service from your ABAP DATA: ls_item TYPE LINE OF zws_zws_users_response-users-item.

TRY.
program CREATE OBJECT lr_proxy
EXPORTING
logical_port_name = 'GET_USERS'.
CATCH cx_ai_system_fault INTO o_err.
Here is an example of a MESSAGE o_err TYPE 'I'.
ENDTRY.
input-rfc_only = space.
report that shows all active TRY.
CALL METHOD lr_proxy->zws_users
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.

26 Copyrighted 2012 by LeverX, Inc.


Conclusion
Web Services allow to increase functionality of your system
and leverage your investments

Mobile applications

Web applications WEB


Another systems Your SAP system

27 Copyrighted 2012 by LeverX, Inc.


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 USA
Tel: (650) 625 – 8347
Web Site: www.LeverX.com
28 Copyrighted 2012 by LeverX, Inc.