Skip to Content
Author's profile photo Kiran Kumar Valluru

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.

/wp-content/uploads/2013/08/1_269373.jpg

Enter Description and click on OK.

/wp-content/uploads/2013/08/2_269374.jpg

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.

/wp-content/uploads/2013/08/3_269384.jpg

Now go to the Context tab of MAIN view and drag and drop the FLIGHT node to the View Context.

/wp-content/uploads/2013/08/4_269385.jpg

Now create a node BOOKINGS and enter dictionary structure SBOOK, cardinality 0..n and click on Add attributes from structure.

/wp-content/uploads/2013/08/5_269386.jpg

Select the required fields and click on OK.

/wp-content/uploads/2013/08/6_269387.jpg

Step 3: Layout Design.

   Now Go to Layout tab, and click on Web Dynpro Code Wizard( magic symbol button).

/wp-content/uploads/2013/08/7_269388.jpg

Double click on Table to create and bind Table UI.

/wp-content/uploads/2013/08/8_269389.jpg

Click on context and select the Bookings Node.

/wp-content/uploads/2013/08/9_269390.jpg

Click on OK.

/wp-content/uploads/2013/08/10_269391.jpg

Now we can see the Table UI in the layout.

/wp-content/uploads/2013/08/11_269392.jpg

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.
   DATA lo_el_flight TYPE REF TO if_wd_context_element.
   DATA ls_flight TYPE wd_this->element_flight.
   DATA lo_nd_bookings TYPE REF TO if_wd_context_node.
   DATA lt_bookings TYPE wd_this->elements_bookings.

   IF first_time = abap_true.

       lo_nd_flight = wd_context->get_child_node( name = wd_this->wdctx_flight ).
       lo_el_flight = lo_nd_flight->get_element( ).

*     Read data from context
       lo_el_flight->get_static_attributes(
         IMPORTING
           static_attributes = ls_flight ).
” **  Here ls_flight contains the data if passed through URL parameters

      lo_nd_bookings = wd_context->get_child_node( name = wd_this->wdctx_bookings ).

*    Get Flight Bookings Data
      SELECT * FROM sbook INTO TABLE lt_bookings WHERE carrid = ls_flightcarrid
                                                                               AND     connid = ls_flightconnid
                                                                               AND     fldate   = ls_flightfldate.
*    Binding data to table
      lo_nd_bookings->bind_table( new_items = lt_bookings set_initial_elements = abap_true ).

   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.

/wp-content/uploads/2013/08/13_269393.jpg

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

/wp-content/uploads/2013/08/12_269394.jpg

Write the below code in Handle Default method.

HANDLEDEFAULT
method HANDLEDEFAULT .

     DATA lo_nd_flight TYPE REF TO if_wd_context_node.
     DATA lo_el_flight TYPE REF TO if_wd_context_element.
     DATA ls_flight TYPE wd_this->element_flight.

     lo_nd_flight = wd_context->get_child_node( name = wd_this->wdctx_flight ).
     lo_el_flight = lo_nd_flight->get_element( ).
 
*  Fill structure with the received url parameters
     ls_flightcarrid   = carrid.
     ls_flightconnid = connid.
     ls_flightfldate   = fldate.

*   set the url parameter values to the context
     lo_el_flight->set_static_attributes(
        static_attributes = ls_flight ).

endmethod.

Create Application.

Create Web Dynpro Application and save it.

/wp-content/uploads/2013/08/14_269395.jpg

Enter description and save it.

/wp-content/uploads/2013/08/15_269396.jpg

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.

/wp-content/uploads/2013/08/16_269397.jpg

Enter description, select report type and click on Save.

/wp-content/uploads/2013/08/17_269398.jpg

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.

*———————————————————————-*
*       CLASS lcl_flight_alv DEFINITION
*———————————————————————-*
CLASS lcl_flight_alv DEFINITION.

   PUBLIC SECTION.
     METHODS: display_alv,                               ” Display ALV
              handle_double_click FOR EVENT double_click ” Event Handler Method
                                      OF cl_gui_alv_grid
                                      IMPORTING e_row.

   PRIVATE SECTION.
     DATA: lr_grid    TYPE REF TO cl_gui_alv_grid,
           lt_sflight TYPE STANDARD TABLE OF sflight,
           ls_sflight TYPE sflight.

ENDCLASS.                    “lcl_alv_event DEFINITION

*———————————————————————-*
*       CLASS lcl_flight_alv IMPLEMENTATION
*———————————————————————-*
CLASS lcl_flight_alv IMPLEMENTATION.

   METHOD display_alv.

*   Get Flight Data from DB
     SELECT * FROM sflight INTO TABLE lt_sflight UP TO 10 ROWS. ” Only 10 records for demo

*   Create ALV Instance
     CREATE OBJECT lr_grid
       EXPORTING
         i_parent = cl_gui_custom_container=>screen0. ” Default sceen ( No need to create custom container )

*    Display ALV
     CALL METHOD lr_grid->set_table_for_first_display
       EXPORTING
         i_structure_name = ‘SFLIGHT’
       CHANGING
         it_outtab        = lt_sflight.

     CALL SCREEN 100.

   ENDMETHOD.                    “display_alv

   METHOD handle_double_click.

      DATA lv_url   TYPE string.
      DATA lv_value TYPE string.

*   Get the double clicked row (selected Flight data)
     READ TABLE lt_sflight INTO ls_sflight INDEX e_row.

*   Get Web Dynpro Appplication URL
      CALL METHOD cl_wd_utilities=>construct_wd_url
        EXPORTING
          application_name              = ‘ZWD_READ_URL_PARAM_DEMO’ ” Application Name
        IMPORTING
          out_absolute_url              lv_url.

*    Append parameters and values to Web Dynpro Application URL
      lv_value = ls_sflightcarrid.
      CALL METHOD cl_http_server=>append_field_url
        EXPORTING
          name  = ‘CARRID’
          value = lv_value
        CHANGING
          url   = lv_url.

      CLEAR lv_value.
      lv_value = ls_sflightconnid.

      CALL METHOD cl_http_server=>append_field_url
        EXPORTING
          name  = ‘CONNID’
          value = lv_value
        CHANGING
          url   = lv_url.

      CLEAR lv_value.
      CALL FUNCTION ‘CONVERT_DATE_TO_EXTERNAL’
       EXPORTING
         DATE_INTERNAL                  = ls_sflightfldate
       IMPORTING
         DATE_EXTERNAL                  = lv_value.

      CALL METHOD cl_http_server=>append_field_url
        EXPORTING
          name  = ‘FLDATE’
          value = lv_value
        CHANGING
          url   = lv_url.

*   Call Web Dynpro Application with URL parameters
      CALL METHOD cl_gui_frontend_services=>execute
        EXPORTING
          document               lv_url .

   ENDMETHOD.                    “handle_double_click

ENDCLASS.                    “lcl_alv_event IMPLEMENTATION

START-OF-SELECTION.

*  Data declaration for local flight object
   DATA lr_flight_alv TYPE REF TO lcl_flight_alv.

*  Creating instance of local flight class
   CREATE OBJECT lr_flight_alv.

*  Registering Event Handler.
   SET HANDLER lr_flight_alv->handle_double_click FOR ALL INSTANCES.

*  Call method to display ALV
   lr_flight_alv->display_alv( ).

*———————————————————————-*
*  MODULE STATUS_0100 OUTPUT
*———————————————————————-*
*
*———————————————————————-*
MODULE status_0100 OUTPUT.
* Set title bar & PF status
   SET TITLEBAR  ‘ZT_URL’” Create title bar zt_url
   SET PF-STATUS ‘ZPF_URL’. ” Create PF status zpf_url
ENDMODULE.                    “STATUS_0100 OUTPUT

*———————————————————————-*
*  MODULE USER_COMMAND_0100 INPUT
*———————————————————————-*
*
*———————————————————————-*
MODULE user_command_0100 INPUT.

   IF syucomm = ‘BACK’ OR  syucomm = ‘EXIT’.
     LEAVE PROGRAM.
   ENDIF.

ENDMODULE.                    “USER_COMMAND_0100 INPUT

Now Save and Activate the program.

Result:

Now Execute the Report (F8). We can see the Flight Data ALV.

/wp-content/uploads/2013/08/18_269425.jpg

Double click on any row.

/wp-content/uploads/2013/08/19_269429.jpg

We can see the Flight Bookings Web Dynpro Application in browser for the selected Flight and the parameters in the URL.

/wp-content/uploads/2013/08/20_269430.jpg

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


Assigned Tags

      3 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Amy King
      Amy King

      Terrific document Kiran and very detailed as always!

      Cheers,

      Amy

      Author's profile photo Former Member
      Former Member

      Hi Kiran,  Nice Document  Thanks  Vijay

      Author's profile photo Former Member
      Former Member

      Very detailed .... nice document