Skip to Content

*Consume
a Web Service in ABAP*

* *It is impossible to implement all of the necessary
functions associated with a complex business problem in the same component or
even technology. A modern enterprise infrastructure system must be in the
position  to integrate functions in one
effective process. Until now, the combination of different applications have
been developed using point-to-point solutions which grow complex and impossible
to maintain over time.

 Web Services simplify the heterogeneous nature of
most mature enterprise system landscapes. They enable you to combine functions
in a single process, even if they are implemented in widely differing software
components. Web services are standalone, executable entities that can be
published, searched for, and called, across a network.

 To consume a web service via the ABAP engine,  you  need to do the following:

 

    • Create
      a Logical Port

 The creation of a proxy for the Web service in the
ABAP Workbench using a WSDL document can be done in a few clicks. Once the
proxy has been created a logical portal will be needed. Once those two tasks
are completed, the Web Service can be called via a standard API.

This demonstration was built for some much needed ABAP practice and because I never really found a WORKING example. Enjoy..

Setup Information

 

URL:  http://www.deeptraining.com/webservices/wsStrings.asmx?WSDL

+Note
that SAP only supports WSDL 1.1 ( at least from what I can tell )+

+ +

 

*1.     
*Create Client Proxy

 

You can generate client or server proxies in ABAP
to send or receive messages. You generate client proxies in this example. The
client proxy will provide an abstraction to the complexities of the web
service.

 

TCODE: SE80



Click on *EDIT
OBJECT*

 

 

!https://weblogs.sdn.sap.com/weblogs/images/14515/12510-2.jpg|height=225|alt=|width=336|src=https://weblogs.sdn.sap.com/weblogs/images/14515/12510-2.jpg!

Select EnterpriseServices

 

 

!https://weblogs.sdn.sap.com/weblogs/images/14515/12510-3.jpg|height=247|alt=|width=274|src=https://weblogs.sdn.sap.com/weblogs/images/14515/12510-3.jpg!

Enter the name of the Client Proxy (ZCG_CO_WEATHER_WS) and click the CREATE button.

 

 

 

!https://weblogs.sdn.sap.com/weblogs/images/14515/12510-4.jpg|height=244|alt=|width=325|src=https://weblogs.sdn.sap.com/weblogs/images/14515/12510-4.jpg!

Select +URL/HTTP
Destination+ and press the Continue  button.

 

 

!https://weblogs.sdn.sap.com/weblogs/images/14515/12510-5.jpg|height=251|alt=|width=337|src=https://weblogs.sdn.sap.com/weblogs/images/14515/12510-5.jpg!

Enter the +WSDL
+in the URL field and press the *Continue *button

 

 

!https://weblogs.sdn.sap.com/weblogs/images/14515/12510-6.jpg|height=236|alt=|width=313|src=https://weblogs.sdn.sap.com/weblogs/images/14515/12510-6.jpg!

 

For simplicity select Local Object and enter a value in the Prefix field. Press the *Continue
*button.

 

 

!https://weblogs.sdn.sap.com/weblogs/images/14515/12510-7.jpg|height=218|alt=|width=289|src=https://weblogs.sdn.sap.com/weblogs/images/14515/12510-7.jpg!

Press the Complete
button.

 

!https://weblogs.sdn.sap.com/weblogs/images/14515/12510-8.jpg|height=200|alt=|width=385|src=https://weblogs.sdn.sap.com/weblogs/images/14515/12510-8.jpg!

Remember to *SAVE
*and then *ACTIVATE *you code.

 

*2.    
*Create Logical Port

* *

You configure runtime features for Web services
client proxies using logical ports.

 

These runtime features can be configured when the
Web-service client is activated. An example of such a feature is the URL-call
of the Web service, which, if applicable, must be modified by users.

* *

TCODE: LPCONFIG

 

!https://weblogs.sdn.sap.com/weblogs/images/14515/12510-9.jpg|height=158|alt=|width=505|src=https://weblogs.sdn.sap.com/weblogs/images/14515/12510-9.jpg!

Enter the Proxy class and Logical Port
name. Make sure that DefaultPort
is selected. Click the Create button

 

!https://weblogs.sdn.sap.com/weblogs/images/14515/12510-10.jpg|height=280|alt=|width=349|src=https://weblogs.sdn.sap.com/weblogs/images/14515/12510-10.jpg!

Enter a description for the logical port.

 

!https://weblogs.sdn.sap.com/weblogs/images/14515/12510-11.jpg|height=137|alt=|width=420|src=https://weblogs.sdn.sap.com/weblogs/images/14515/12510-11.jpg!

Enter the WSDL URL into the URL fieldCopy the URL defined in that line into the SOAP Action line.

 

!https://weblogs.sdn.sap.com/weblogs/images/14515/12510-13.jpg|height=172|alt=|width=529|src=https://weblogs.sdn.sap.com/weblogs/images/14515/12510-13.jpg!

 

Save and then Activate the Logical Port

 

*3.    
*Test the Web Service
Call

* *

TCODE: se80

 

To test the web service call load the client  proxy in SE80

 

 

!https://weblogs.sdn.sap.com/weblogs/images/14515/12510-14.jpg|height=176|alt=|width=368|src=https://weblogs.sdn.sap.com/weblogs/images/14515/12510-14.jpg!

Click on the TEST
icon

 

!https://weblogs.sdn.sap.com/weblogs/images/14515/12510-15.jpg|height=205|alt=|width=421|src=https://weblogs.sdn.sap.com/weblogs/images/14515/12510-15.jpg!

Click on the *Execute
*button

 

!https://weblogs.sdn.sap.com/weblogs/images/14515/12510-16.jpg|height=238|alt=|width=432|src=https://weblogs.sdn.sap.com/weblogs/images/14515/12510-16.jpg!

Since the web service simply converts a string to
all upper case, you can now click on the *EXECUTE
*button.

 

+Note: +You can
also now change the default value being sent to the web service

 

!https://weblogs.sdn.sap.com/weblogs/images/14515/12510-17.jpg|height=188|alt=|width=267|src=https://weblogs.sdn.sap.com/weblogs/images/14515/12510-17.jpg!

As you can see you can even upload an entire file

 

 

!https://weblogs.sdn.sap.com/weblogs/images/14515/12510-18.jpg|height=167|alt=|width=323|src=https://weblogs.sdn.sap.com/weblogs/images/14515/12510-18.jpg!

If the test is successful you will see your
returned string in all Upper Case

 

 

*Call the Web Service
within an ABAP Function*

* *

FUNCTION Z_CG_TOUPPER_TEST.


*”—-



“Local Interface:

*”  IMPORTING

*”     VALUE(INPUT_PARAMETER) TYPE  STRING

*”  EXPORTING

*”     VALUE(OUTPUT_PARAMETER) TYPE  STRING

*”—-


DATA: WSProxy TYPE REF TO ZCG_CO_WS_STRINGS_SOAP .

TRY.

    CREATE OBJECT WSProxy .

    CATCH CX_AI_SYSTEM_FAULT .

ENDTRY.

   data: ls_response type ZCG_MAKE_UPPER_SOAP_OUT .

   data: ls_request type ZCG_MAKE_UPPER_SOAP_IN .

   ls_request-DATA = INPUT_Parameter .

TRY.

CALL METHOD WSProxy->MAKE_UPPER

  EXPORTING

    INPUT  = ls_request

 IMPORTING

    OUTPUT = ls_response .

 CATCH CX_AI_SYSTEM_FAULT .

 CATCH CX_AI_APPLICATION_FAULT .

ENDTRY.

COMMIT WORK.

OUTPUT_Parameter = ls_response-MAKE_UPPER_RESULT .

ENDFUNCTION.

 

For more information, please visit NetweaverCentral  </p>

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

  1. fabrizio gemma

    Hi craig,

     

    very usefull blog, good job!

     

    What about if the Web Service requires an authentication, like a Web Service build in ABAP?

     

    I try to call such a WS. In dialog mode, no problem: a popup appears where yuo can insert userid and passwrod. But i need to call the WS during a background job execution.

     

    How can i set user and password in the proxy client request, to skip the dialog popup ?

     

    thanks in advance

     

    Regards

     

    Fabrizio Gemma

    (0) 

Leave a Reply