Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member184578
Active Contributor

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.
   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_flight-carrid
                                                                               AND     connid = ls_flight-connid
                                                                               AND     fldate   = ls_flight-fldate.
*    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.

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.
     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_flight-carrid   = carrid.
     ls_flight-connid = connid.
     ls_flight-fldate   = 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.


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.

*----------------------------------------------------------------------*
*       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_sflight-carrid.
      CALL METHOD cl_http_server=>append_field_url
        EXPORTING
          name  = 'CARRID'
          value = lv_value
        CHANGING
          url   = lv_url.

      CLEAR lv_value.
      lv_value = ls_sflight-connid.

      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_sflight-fldate
       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 sy-ucomm = 'BACK' OR  sy-ucomm = '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.

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


3 Comments
Labels in this area