Exemplos 1
Creating ABAP based web services and consuming the same in ABAP
By Chandra Dasari, YASH Technologies
Description: Creating ABAP based Web services and consuming in report. In this example we will be using
wizard provided by SAP.
Go to SE37. Enter the name of the function module already created.
Menu->utilities->more utilities->create web service->from function module:
Enter the Service Definition Name followed by short text as shown below
Select the end point, as of now the following options are available
• Function module
• Function Group
• BAPI
• Message interface (from XI)
Select the function module created earlier
Since we are using basic Authorizations, select the option as shown
Make sure we select the check box “release Service for Runtime”
If this is not selected we need to go to TCode: “WSCONFIG” & release it
This is the final screen for wizard before completion.
Click on “Complete” and save it in package.
Go to TCode wsconfig to check whether the wsd created has been released for soap runtime
Click on “Display” button
Click on “ICF Details” button
The web service is created in “sicf” transaction as shown
Go back
Yes the green icon shows the wsd is released successfully for soap runtime.
Generating the wsdl from wsd
Go to transaction code wsadmin as shown
Select the wsd for which the wsdl has to be generated.
Make sure the administrative settings has been configured
Click on generate function after selecting the respective wsd
Save the wsdl file on to the local pc for further use
Testing the web service
Click on “submit” button
Copy the wsdl as shown
WSDL:
http://yhsapx09.yashsap.com:8003/sap/bc/srt/rfc/sap/Z_ESA_GETCARRIERS_WSD?sap-
client=100&wsdl=1.1
Click on “test” button to test the functionality of web service
Click on the parameters
Enter the input parameters and click on submit
Comments: The web service has been tested successfully and is ready to use.
Create any client application for consuming it.
Generating the proxy object-Consuming in ABAP
Login to SAP system.
Go to SE80 create proxy object,
Path: create-> enterprise web service->proxy object
Select the option “local File” and select the wsdl saved on local pc in earlier step.
Specify the package & prefix (z) save it.
Creating RFC destination for Yhsapi01.
Create RFC destination of type “H”
If needed configure the proxy settings
For configuring proxy settings click on Global Configuration”
Save the settings
Creating Logical port
Go to lpconfig
Creating Client Application-> report
*&---------------------------------------------------------------------*
*& Report ZXI3
*& AUTHOR: chandra dasari
*&---------------------------------------------------------------------*
REPORT ZXI3.
*&----------------------------------------------------------------*&
*& Data Declaration
*&----------------------------------------------------------------*&
tables : spfli.
DATA: proxy TYPE REF TO zco_zgetflightdet19_wsd,
OUTPUT type ZZGETSFLIGHTDETRESPONSE ,
INPUT type ZZGETSFLIGHTDET .
Data : sys_fault type ref to cx_ai_system_fault,
app_fault type ref to cx_ai_application_fault.
Data : itab type spfli.
*&----------------------------------------------------------------*&
*& UI Declaration
*&----------------------------------------------------------------*&
parameters : p_carrid type spfli-carrid,
p_connid type spfli-connid.
*&----------------------------------------------------------------*&
*& Application logic
*&----------------------------------------------------------------*&
start-of-selection.
TRY.
CREATE OBJECT proxy
exporting
LOGICAL_PORT_NAME = 'ZCO_ZGETFLIGHTDET19_WSD' .
CATCH cx_ai_system_fault .
create object sys_fault.
write :/ 'error at level 1', sys_fault->errortext.
exit.
ENDTRY.
TRY.
input-carrid = p_carrid.
input-connid = p_connid.
CALL METHOD proxy->zgetsflightdet
EXPORTING
input = input
IMPORTING
OUTPUT = output
.
CATCH CX_AI_SYSTEM_FAULT .
create object sys_fault.
write :/ 'error at level 2', sys_fault->errortext.
exit.
CATCH ZCX_EXCEPTION00 .
CATCH CX_AI_APPLICATION_FAULT .
write : 'error 3'.
exit.
ENDTRY.
write : / 'TEST RESULTS OF CLIENT APPLICATION RUNNING ON YHSAPX05'.
WRITE : / 'THE CLIENT APPLICATION CALLS THE WEBSERVICE LOCATED ON YHSAPI01
SYSTEM'.
SKIP.
write :/ output-carrid,
/ output-connid,
/ output-currency,
/ output-planetype,
/ output-price,
/ output-seatsmax,
/ output-seatsocc.
Performing test from client application.
Execute the application.
Input screen:
Output: