Read URL Parameters in Web Dynpro ABAP
Introduction
This document explains how to pass data from ABAP to Web Dynpro ABAP application through URL Parameters.
Here I will take the same example demonstrated in How to Pass Data from ABAP to Web Dynpro ABAP using Shared Memory
Creating Web Dynpro ABAP Application
Step 1: Create a Web Dynpro Component
Go to the SE80 transaction and create a Web Dynpro Component.
Enter Description and click on OK.
Step 2: Data Binding
Go to the Context tab of Component Controller and create a node Flight with cardinality 1:1 and add the following attributes:
CARRID of type SFLIGHT-CARRID.
CONNID of type SFLIGHT-CONNID.
FLDATE of type SFLIGHT-FLDATE.
Now go to the Context tab of MAIN view and drag and drop the FLIGHT node to the View Context.
Now create a node BOOKINGS and enter dictionary structure SBOOK, cardinality 0..n and click on Add attributes from structure.
Select the required fields and click on OK.
Step 3: Layout Design.
Now Go to Layout tab, and click on Web Dynpro Code Wizard( magic symbol button).
Double click on Table to create and bind Table UI.
Click on context and select the Bookings Node.
Click on OK.
Now we can see the Table UI in the layout.
Now goto Methods tab, and enter below code in WDDOMODIFYVIEW method.
WDDOMODIFYVIEW |
---|
METHOD WDDOMODIFYVIEW .
DATA lo_nd_flight TYPE REF TO if_wd_context_node. IF first_time = abap_true. lo_nd_flight = wd_context->get_child_node( name = wd_this->wdctx_flight ). * Read data from context lo_nd_bookings = wd_context->get_child_node( name = wd_this->wdctx_bookings ). * Get Flight Bookings Data ENDIF. ENDMETHOD. |
Note: The parameter value will not be available with in the WDDOINIT of our main view as WDDOINIT method of this view is called before the HANDLEDEFAULT method of Window. So we have to write our code in the method WDDOMODIFYVIEW of our main.
Reading URL Parameters
We can read the URL parameters in the HANDLEDEFAULT method of the Window.
Now go to Context tab of Window and drag and drop the FLIGHT node in the Window context.
Now go to methods tab and double click on HANDLEDEFAULT method and create the following importing parameters:
CARRID of type SFLIGHT-CARRID
CONNID of type SFLIGHT-CONNID
FLDATE of type SFLIGHT-FLDATE
Write the below code in Handle Default method.
HANDLEDEFAULT |
---|
method HANDLEDEFAULT .
DATA lo_nd_flight TYPE REF TO if_wd_context_node. lo_nd_flight = wd_context->get_child_node( name = wd_this->wdctx_flight ). * set the url parameter values to the context endmethod. |
Create Application.
Create Web Dynpro Application and save it.
Enter description and save it.
Now we will see creating ABAP ALV Report and how to call and pass data to Web Dynpro Application through URL Parameters.
Creating ABAP ALV Report
Execute Transaction SE38. Enter Program Name and click on create.
Enter description, select report type and click on Save.
Now Enter the below code
Header 1 |
---|
*&———————————————————————* *& Report ZKK_FLIGHT_URL_DEMO *& *&———————————————————————* *& Author: V Kiran Kumar Reddy *& Purpose: Shared Memory Objects Demo *&———————————————————————* *& 1. Create Screen 0100. *& 2. Create calls to PBO and PAI in the flow logic of screen 0100: *& PROCESS BEFORE OUTPUT. *& MODULE STATUS_0100. *& *& PROCESS AFTER INPUT. *& MODULE USER_COMMAND_0100. *& *& 3. Create GUI status zpf_url, assign Functions BACK and EXIT to *& standard icons. and create Title zt_url. *&———————————————————————* REPORT zkk_flight_url_demo. *———————————————————————-* PUBLIC SECTION. PRIVATE SECTION. ENDCLASS. “lcl_alv_event DEFINITION *———————————————————————-* METHOD display_alv. * Get Flight Data from DB * Create ALV Instance * Display ALV CALL SCREEN 100. ENDMETHOD. “display_alv METHOD handle_double_click. DATA lv_url TYPE string. * Get the double clicked row (selected Flight data) * Get Web Dynpro Appplication URL * Append parameters and values to Web Dynpro Application URL CLEAR lv_value. CALL METHOD cl_http_server=>append_field_url CLEAR lv_value. CALL METHOD cl_http_server=>append_field_url * Call Web Dynpro Application with URL parameters ENDMETHOD. “handle_double_click ENDCLASS. “lcl_alv_event IMPLEMENTATION START-OF-SELECTION. * Data declaration for local flight object * Creating instance of local flight class * Registering Event Handler. * Call method to display ALV *———————————————————————-* *———————————————————————-* IF sy–ucomm = ‘BACK’ OR sy–ucomm = ‘EXIT’. ENDMODULE. “USER_COMMAND_0100 INPUT |
Now Save and Activate the program.
Result:
Now Execute the Report (F8). We can see the Flight Data ALV.
Double click on any row.
We can see the Flight Bookings Web Dynpro Application in browser for the selected Flight and the parameters in the URL.
Other ways to read URL parameters:
Write the below code in HANDLEDEFAULT method to read all the URL parameters instead of creating Importing parameters in HANDLEDEFAULT method.
DATA: lt_parameter TYPE tihttpnvp,
ls_parameter TYPE ihttpnvp.
* Read all URL parameters
wdevent->get_data(
EXPORTING
name = if_wd_application=>all_url_parameters
IMPORTING
value = lt_parameter ).
OR to read a single parameter we can simple use a READ TABLE statement of wdevent->parameters.
DATA ls_parameter TYPE wdr_event_parameter.
READ TABLE wdevent->parameters INTO ls_parameter WITH KEY name = 'CARRID'. " here carrid is the parameter name
Reference:
http://scn.sap.com/thread/3412659
Terrific document Kiran and very detailed as always!
Cheers,
Amy
Hi Kiran, Nice Document Thanks Vijay
Very detailed .... nice document