28
Essential SAP ABAP Tutorial How To Use WEB Services In SAP ABAP By Eugene Ostroumov Copyrighted 2012 by LeverX, Inc. 1

LeverX SAP ABAP Tutorial - Creating and Calling Web Services

  • Upload
    leverx

  • View
    4.327

  • Download
    6

Embed Size (px)

DESCRIPTION

The SAP Web Application Server allows companies to extend their solutions by exposing and integrating Web services. The SAP NetWeaver Developer Studio provides an environment for publishing, discovering, and accessing Web services. Therefore, it allows the SAP Web Application Server to act both as a “server” and as a “client” for Web services.

Citation preview

Page 1: LeverX SAP ABAP Tutorial - Creating and Calling Web Services

1

Essential SAP ABAP Tutorial

How To Use WEB Services In SAP ABAPBy Eugene Ostroumov

Copyrighted 2012 by LeverX, Inc.

Page 2: LeverX SAP ABAP Tutorial - Creating and Calling Web Services

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.

Page 3: LeverX SAP ABAP Tutorial - Creating and Calling Web Services

How to create WEB Service based on FMStep 1

3 Copyrighted 2012 by LeverX, Inc.

Creating a function module with import and export parameters

Page 4: LeverX SAP ABAP Tutorial - Creating and Calling Web Services

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

Page 5: LeverX SAP ABAP Tutorial - Creating and Calling Web Services

How to create WEB Service based on FMStep 3

5 Copyrighted 2012 by LeverX, Inc.

Mark the function module as a Remote-Enabled Module

Page 6: LeverX SAP ABAP Tutorial - Creating and Calling Web Services

How to create WEB Service based on FMStep 4

6 Copyrighted 2012 by LeverX, Inc.

Create a Web Service based on the function module

Page 7: LeverX SAP ABAP Tutorial - Creating and Calling Web Services

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

Page 8: LeverX SAP ABAP Tutorial - Creating and Calling Web Services

How to create WEB Service based on FMStep 6

8 Copyrighted 2012 by LeverX, Inc.

The name of functional module is entered automatically

Page 9: LeverX SAP ABAP Tutorial - Creating and Calling Web Services

How to create WEB Service based on FMStep 7

9 Copyrighted 2012 by LeverX, Inc.

Choose a profile forSecurity Settings

Page 10: LeverX SAP ABAP Tutorial - Creating and Calling Web Services

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

Page 11: LeverX SAP ABAP Tutorial - Creating and Calling Web Services

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

Page 12: LeverX SAP ABAP Tutorial - Creating and Calling Web Services

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

Page 13: LeverX SAP ABAP Tutorial - Creating and Calling Web Services

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

Page 14: LeverX SAP ABAP Tutorial - Creating and Calling Web Services

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

Page 15: LeverX SAP ABAP Tutorial - Creating and Calling Web Services

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

Page 16: LeverX SAP ABAP Tutorial - Creating and Calling Web Services

How to call WEB Service using ABAPStep 2

16 Copyrighted 2012 by LeverX, Inc.

Choose “Service Consumer” type of proxy

Page 17: LeverX SAP ABAP Tutorial - Creating and Calling Web Services

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”

Page 18: LeverX SAP ABAP Tutorial - Creating and Calling Web Services

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)

Page 19: LeverX SAP ABAP Tutorial - Creating and Calling Web Services

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

Page 20: LeverX SAP ABAP Tutorial - Creating and Calling Web Services

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

Page 21: LeverX SAP ABAP Tutorial - Creating and Calling Web Services

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

Page 22: LeverX SAP ABAP Tutorial - Creating and Calling Web Services

How to call WEB Service using ABAPStep 8

22 Copyrighted 2012 by LeverX, Inc.

Activate the Proxy

Page 23: LeverX SAP ABAP Tutorial - Creating and Calling Web Services

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

Page 24: LeverX SAP ABAP Tutorial - Creating and Calling Web Services

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

Page 25: LeverX SAP ABAP Tutorial - Creating and Calling Web Services

How to call WEB Service using ABAPStep 11

25 Copyrighted 2012 by LeverX, Inc.

Save logical port after it is generated

Save

Page 26: LeverX SAP ABAP Tutorial - Creating and Calling Web Services

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.

Page 27: LeverX SAP ABAP Tutorial - Creating and Calling Web Services

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

Page 28: LeverX SAP ABAP Tutorial - Creating and Calling Web Services

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.