Quantcast
Channel: SCN : Document List - ABAP Development
Viewing all articles
Browse latest Browse all 935

Step by step to create, consume and trace web service in ABAP system

$
0
0

This document could be used as guide for beginners to learn and use ABAP web service.

 

How to create web service provider in ABAP system


The following steps demonstrates how to expose a function module as a web service provider in SAP CRM system.

 

 

1. create a new function module to return product description by given input product ID.

 

Signature and source code of function module:

 

FUNCTION ZGET_PROD_DESCRIPTION.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(IV_PROD_ID) TYPE  COMM_PRODUCT-PRODUCT_ID
*"  EXPORTING
*"     VALUE(RV_TEXT) TYPE  STRING
*"----------------------------------------------------------------------
SELECT SINGLE A~short_text INTO rv_text FROM COMM_PRSHTEXT  AS A  INNER JOIN comm_product AS B ON B~product_id = iv_prod_id AND B~product_guid = A~product_guid.
ENDFUNCTION.

Make sure the FM is marked as "Remote enabled".

clipboard1.png

2. start the web service creation wizard:

clipboard2.png

Just follow the wizard to finish creation. Choose the appropriate authentication approach according to your use case.

clipboard3.png

3. Once creation is finished, you would find your service definition as below:

clipboard4.png

click tab WSDL, write down your WSDL link:

clipboard5.png

4. use tcode SOAMANAGER, click Web Service Configuration

clipboard6.png

you can find your service definition created just now:

clipboard7.png

click the hyperlink and create a new service:

clipboard8.png

For security reasons choose radio box "SSL".

clipboard9.png

click Finish button:

clipboard10.png

Now your web service is ready for consumption. click this icon:

clipboard11.png

write down this link for later usage:

clipboard12.png

How to consume web service in ABAP system

1. tcode SE80, create a new service consumer:

clipboard14.png

2. Choose external WSDL:

clipboard15.png

choose the url got from last step of chapter "How to create web service provider in ABAP system":

clipboard16.png

activate your consumer proxy and write down the ABAP class name.

clipboard17.png

3. go back to SOAMANAGER, find the consumer proxy created in step2:

clipboard18.png

create a new logical point:

clipboard19.png

clipboard20.png

4. Make sure you specify URL got from the last step of web service creation chapter. If you just use the URL got from SE80 in tab "WSDL", you will meet with below error.

clipboard21.png

choose HTTPS:

clipboard22.png

5. consume the web service in ABAP report:

 

you can find the data type for input and output parameters in SE80:

clipboard22.png

data: lr_proxy TYPE REF TO CO_ZPRODUCTDESCRIPTION4,
input TYPE ZGET_PROD_DESCRIPTION,
output TYPE ZGET_PROD_DESCRIPTION_RESPONSE.
input-iv_prod_id = 'ARNO_TEST004'.
CREATE OBJECT lr_proxy     EXPORTING            LOGICAL_PORT_NAME = 'ZLP_JERRY1'.
CALL METHOD lr_proxy->ZGET_PROD_DESCRIPTION     EXPORTING            input = input     IMPORTING            output = output.

Now we execute the report and get the web service execution result as expected:

clipboard23.png


The product description in UI:

clipboard24.png

How to trace the web service execution


Use tcode SRT_UTIL, add a new configuration for your user which triggers the web service call:

clipboard26.png

Set the Functional Trace to "High". You could also enable Performance and Payload trace if necessary.

Click Save Configuration button to persist the change.

clipboard27.png

Execute the report which triggers the web service call. After it finishes, click tab "Functional Trace" and click refresh button, you should see several records for execution trace.

clipboard28.png

Double click and select the row with type "Response", where you could find the product description value returned by service provider.

clipboard29.png


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>