Skip to Content

Introduction

       This document explains how to pass data from ABAP to Web Dynpro ABAP application.

Here I am taking a simple and well known example, Flight data and display bookings of flights, to explain how to pass data to Web Dynpro ABAP application from ABAP.

Scenario

  1. Create an ABAP ALV report to display flight data.
  2. Create a Web Dynpro ABAP application to display bookings of flight.
  3. When we double click on any record of flight data in ALV, We have to pass the selected flight data and display Flight bookings Web dynpro application in SAP GUI. 

Generally, we can pass data to Web Dynpro application through URL parameters (when displaying web dynpro application in browser). But here, we are displaying web dynpro application in SAP GUI itself. So we cannot pass data to web dynpro application through URL parameters.

Here we are going to use Shared Memory Objects concept to pass data to Web Dynpro ABAP application from ABAP.

Shared Memory

The shared memory is a memory area on an application server, which is accessed by all of this server’s ABAP programs.

To make use of shared memory object:

  1. Create ‘Shared Memory-Enabled’ class.
  2. Create a Shared Memory Area.

Step 1: Creating ‘Shared Memory-Enabled’ class

Execute transaction SE24 (Class Builder). Enter class name and click on create button.

/wp-content/uploads/2012/04/1_97119.jpg

Enter description and click on OK.

/wp-content/uploads/2012/04/2_97120.jpg

Go to Properties tab and select ‘Shared Memory-Enabled’ Check box.

/wp-content/uploads/2012/04/3_97127.jpg

Go to Attributes tab and create an attribute to hold the data

/wp-content/uploads/2012/04/4_97128.jpg

Go to methods tab and create methods: set_selected_flight and get_selected_flight, to enable our ABAP programs to access the attribute.

Create method set_selected_flight :

/wp-content/uploads/2012/04/5_97129.jpg

Select the method and click on parameters button to create parameters

/wp-content/uploads/2012/04/6_97130.jpg

Create an importing parameter is_flight of type sflight.

/wp-content/uploads/2012/04/7_97131.jpg

Now create one more method get_selected_flight:

/wp-content/uploads/2012/04/8_97132.jpg

create an exporting parameter es_flight of type sflight.

/wp-content/uploads/2012/04/9_97133.jpg

Enter the below code in SET_SELECTED_FLIGHT by double clicking on it.

SET_SELECTED_FLIGHT

method SET_SELECTED_FLIGHT.

* Set Flight Data

   ms_flight = is_flight.

endmethod.

Enter the below code in GET_SELECTED_FLIGHT by double clicking on it.

GET_SELECTED_FLIGHT

method GET_SELECTED_FLIGHT.

* Get Selected Flight

   es_flight = ms_flight.

endmethod.

Now Save and Activate the class.

This class is called as ‘Root Class’.

Step 2: Creating Shared Memory Area

Here we will use our created root class as ‘global area root class’ of our new memory area.

Execute transaction SHMA. Enter Area name and click on create button.

/wp-content/uploads/2012/04/10_97134.jpg

Enter description, In Root class enter the created ‘Shared Memory-Enabled’ class in step 1, and select client-specific Area check box.

/wp-content/uploads/2012/04/11_97135.jpg

Click on Save.

Once you click on save, it will automatically generate an Area Class with the given Area name. you can see it in SE24 transaction by giving the area name and click on display.

This second step gives us ‘Area Handle’ – a specific class which is needed to interact with the memory object created in step 1.

We are done with creating Shared Memory Object.

Now we will use this in our ABAP program to export data to shared memory and in our web dynpro application to import data from 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/2012/04/1_97119.jpg

Enter Description and click on OK.

Step 2: Data Binding

Go to the Context tab of Main View and create a node BOOKINGS.

/wp-content/uploads/2012/04/2_97120.jpg

Enter dictionary structure SBOOK, cardinality 0..n and click on Add attributes from structure.

/wp-content/uploads/2012/04/3_97127.jpg

Select the required fields and click on OK.

/wp-content/uploads/2012/04/4_97128.jpg

Step 3: Layout Design.

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

/wp-content/uploads/2012/04/5_97129.jpg

Double click on Table to create and bind Table UI.

/wp-content/uploads/2012/04/6_97130.jpg

Click on context and select the Bookings Node.

/wp-content/uploads/2012/04/7_97131.jpg

Click on OK.

/wp-content/uploads/2012/04/8_97132.jpg

Now we can see the Table UI in the layout.

/wp-content/uploads/2012/04/9_97133.jpg

Now goto Methods tab, and enter below code in WDDOINIT method.

WDDOINIT

method WDDOINIT.

* Data declarations

   DATA: lo_nd_bookings TYPE REF TO if_wd_context_node,

             lt_bookings    TYPE wd_this->Elements_bookings,

             lr_shm_handle  TYPE REF TO zcl_flight_data_area, ” Area Class

             lr_shm_root    TYPE REF TO zcl_flight_data_root, ” Root Class

             ls_flight      TYPE sflight.

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

   TRY.

*     Reading from Shared Memory ( Importing from memory )

       lr_shm_handle = zcl_flight_data_area=>attach_for_read( ).

       lr_shm_handle->root->get_selected_flight(

                                                                  importing

                                                                  es_flight = ls_flight ).

       lr_shm_handle->detach( ).

*   Here ls_flight contains the data if exported to shared memory,

*   else it will catch the exception

     CATCH cx_shm_no_active_version

                 cx_shm_read_lock_active

                 cx_shm_change_lock_active

                 cx_shm_exclusive_lock_active

                 cx_shm_inconsistent.

   ENDTRY.

*  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 ).

endmethod.


Now Save and Activate the Web Dynpro Component.

Create Application.

Create Web Dynpro Application and save it.

/wp-content/uploads/2012/04/10_97134.jpg

Creating Transaction for Web Dynpro ABAP Application

Go to the SE93 transaction, Enter Transaction name and click on create.

/wp-content/uploads/2012/04/11_97135.jpg

Enter description, select ‘Transaction with parameters’ radio button and click on OK.

/wp-content/uploads/2012/04/12_97136.jpg

In the following screen,

  • Enter Transaction WDYID
  • Select ‘Skip Initial screen’
  • Select GUI Support
  • Under Default Values, Enter:

Name                Value

APPLICATION ZWD_BOOKINGS_SHM_DEMO
STARTMODE SAPGUI

/wp-content/uploads/2012/04/13_97137.jpg

/wp-content/uploads/2012/04/14_97138.jpg


In the next part, How to pass data from ABAP to Web Dynpro ABAP – Part 2  we will see creating ALV report and how to attach data to Shared Memory.


To report this post you need to login first.

8 Comments

You must be Logged on to comment or reply to a post.

Leave a Reply