Tips on Generating Proxies
Exercise 6: Consume a Web Service (Optional)
Exercise Objectives
After completing this exercise, you will be able to:
• Generate a Web service client proxy
• Create a logical port
• Implement a Web service client application
Business Example
The ABAP application created in the preceding exercises needs to be enhanced:
You must now integrate the z##_getDetails ABAP Web service and provide detailed data for a chosen flight. You need to generate a new proxy and define a logical port.
Task 1: Web Service Client Proxy
You need to generate a Web service client proxy for the z##_getDetails Web service.
1. Generate a proxy for the z##_getDetails Web service. Use the Z## prefix for the objects to be generated.
You should replace ## with your two-digit group number.
Task 2: Logical Port
You have to create a logical port for the generated Web service client proxy.
1. Create a logical port for your Web service client proxy and classify it as the default port. Suggested name: LP##_DETAILS.
You should replace ## with your two-digit group number.
2. You still have to specify the Call URL for the Web service via the logical port. Use your HTTP destination for this.
3. Save and then activate your logical port.
Task 3: Implement a Client Application
The ABAP application created in the preceding exercises needs to be enhanced:
You must now integrate the z##_getDetails ABAP Web service into the application and display detailed data for a chosen flight on the details list.
Enhance your Z##_WS_CLIENT program for this.
1. Enhance your Z##_WS_CLIENT program with the AT LINE-SELECTION event, and make sure that the flight data chosen on the basic list is available again in the AT LINE-SELECTION event.
2. In the AT LINE-SELECTION ABAP processing block, call your z##_getDetails Web service using the Web service client proxy that you generated. Use the constructor to specify the LP##_DETAILS logical port.
When calling the Web service operation, complete the relevant interface.
Use the data from the HIDE area for this.
3. Now print the detailed flight data on the details list.
Solution 6: Consume a Web Service (Optional)
Task 1: Web Service Client Proxy
You need to generate a Web service client proxy for the z##_getDetails Web service.
1. Generate a proxy for the z##_getDetails Web service. Use the Z## prefix for the objects to be generated.
You should replace ## with your two-digit group number.
a) To do this, go to the Object Navigator (SE80). From the context menu for your package zbc416_## follow the menu path Create → Enterprise Service / Web Service → Proxy Object to create a proxy.
b) The WSDL document is used to generate the proxy. Enter the URL of the WSDL document on the corresponding screen. Use the HTTP destination you created earlier, which points to the following destination: http://<server>:<port>/sap/bc/srt/rfc/sap/.
As the path suffix, enter your z##_getDetails Web service followed by the ?wsdl=1.1 query string. You do not need to specify the client in the query string, since this was already defined in the HTTP destination.
Replace ## with your group number.
c) On the next screen, enter your package (zbc416_##). Use Z## as the prefix. Replace ## with your group number.
d) Then save and activate your Web service client proxy.
Task 2: Logical Port
You have to create a logical port for the generated Web service client proxy.
1. Create a logical port for your Web service client proxy and classify it as the default port. Suggested name: LP##_DETAILS.
You should replace ## with your two-digit group number.
a) Use the transaction LPCONFIG for this.
b) On the initial screen, use the input help to select your proxy class and assign a name to your logical port: Suggested name: LP##_DETAILS.
c) Classify the logical port as the default port using the corresponding
2. You still have to specify the Call URL for the Web service via the logical port. Use your HTTP destination for this.
a) You can enter the Web service URL on the Call Parameters tab page.
Use your WS##_DES HTTP destination for this. Specify your Web service z##_getDetails as the path suffix. You do not need to specify the client, since this was defined in the HTTP destination. Replace ##
with your group number.
3. Save and then activate your logical port.
a) If you have questions, contact your instructor.
Task 3: Implement a Client Application
The ABAP application created in the preceding exercises needs to be enhanced:
You must now integrate the z##_getDetails ABAP Web service into the application and display detailed data for a chosen flight on the details list.
Enhance your Z##_WS_CLIENT program for this.
1. Enhance your Z##_WS_CLIENT program with the AT LINE-SELECTION event, and make sure that the flight data chosen on the basic list is available again in the AT LINE-SELECTION event.
a) Keyword: HIDE area!
2. In the AT LINE-SELECTION ABAP processing block, call your z##_getDetails Web service using the Web service client proxy that you generated. Use the constructor to specify the LP##_DETAILS logical port.
When calling the Web service operation, complete the relevant interface.
Use the data from the HIDE area for this.
a) See the sample solution.
3. Now print the detailed flight data on the details list.
a) Refer to the sample solution for details.
Result
*&---*
*& Report BC416_WS_CLIENT_S2
*&---*
*& Musterlösung zur Übung 6: Web Service konsumieren (optional)
*&---*
REPORT bc416_ws_client_s2.
*********************************************
* Selektionsbild
*
PARAMETERS: pa_airl TYPE bc00char3 DEFAULT 'LH', pa_depa TYPE bc00char20 DEFAULT 'Frankfurt', pa_dest TYPE bc00char20 DEFAULT 'New York'.
SELECT-OPTIONS pa_date FOR date DEFAULT '20080101' TO '20090101' OPTION BT SIGN I.
DATA proxy_flights TYPE REF TO co_bc00bc416_get_flights.
TRY.
DATA: wa_date LIKE LINE OF pa_date, wa_date2 TYPE bc00bapisfldra.
ENDLOOP.
*********************************************************
* Web Service Operation über Proxy rufen (Flugliste)
* TRY.
proxy_flights->flight_get_list( EXPORTING input = in_flights IMPORTING output = out_flights ).
CATCH cx_ai_system_fault . CATCH cx_ai_application_fault . ENDTRY.
*********************************************************
* Flugliste auf Grundliste ausgeben
* und HIDE Bereich versorgen
*
DATA wa_flights TYPE bc00bapisfldat.
LOOP AT out_flights-flight_list-item INTO wa_flights.
WRITE: / wa_flights-airlineid,
* AT LINE-SELECTION NEW CODING HERE. DONT FORGET HIDE *
**************************************************************
AT LINE-SELECTION.
*********************************************************
* Proxy instanziieren (Details)
*
DATA proxy_details TYPE REF TO co_bc00bc416_get_details.
TRY.
* Schnittstelle versorgen: Verwenden Sie
* hierzu die Daten aus dem HIDE Bereich
*
* WS Operation über Proxy rufen (Details)
* TRY.
proxy_details->flight_get_detail( EXPORTING input = in_details IMPORTING output = out_details ).
CATCH cx_ai_system_fault . CATCH cx_ai_application_fault . ENDTRY.
*********************************************************
* Detaildaten auf Verzweigungsliste ausgeben
* SKIP.
ULINE.
FORMAT COLOR COL_HEADING.
WRITE: / 'Ausgewählter Flug'(001), AT sy-linsz space.
FORMAT COLOR OFF.
ULINE.
WRITE: / out_details-flight_data-airlineid, out_details-flight_data-connectid,
out_details-flight_data-cityto.
ULINE.
WRITE: / 'Abflug:'(004),
10 out_details-flight_data-flightdate, 25 out_details-flight_data-deptime.
WRITE: / 'Ankunft:'(005),
10 out_details-flight_data-arrdate, 25 out_details-flight_data-arrtime.
WRITE: / 'Preis:'(006),
10 out_details-flight_data-price LEFT-JUSTIFIED, 25 out_details-flight_data-curr.
ULINE.
FORMAT COLOR COL_HEADING.
WRITE: / 'Verfügbare Plätze'(007), AT sy-linsz space.
FORMAT COLOR OFF.
ULINE.
WRITE: / 'Economy:'(008), 15 out_details-availibility-econofree, / 'Business:'(009), 15 out_details-availibility-businfree, / 'First Class:'(010), 15 out_details-availibility-firstfree.
ULINE.
Lesson Summary
You should now be able to:
• Generate a proxy using a WSDL document
• Define a logical port
• Call a Web service from an ABAP program