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.
- Create an ABAP ALV report to display flight data.
- Create a Web Dynpro ABAP application to display bookings of flight.
- 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.
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:
- Create ‘Shared Memory-Enabled’ class.
- 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.
Enter description and click on OK.
Go to Properties tab and select ‘Shared Memory-Enabled’ Check box.
Go to Attributes tab and create an attribute to hold the data
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 :
Select the method and click on parameters button to create parameters
Create an importing parameter is_flight of type sflight.
Now create one more method get_selected_flight:
create an exporting parameter es_flight of type sflight.
Enter the below code in SET_SELECTED_FLIGHT by double clicking on it.
* Set Flight Data
ms_flight = is_flight.
Enter the below code in GET_SELECTED_FLIGHT by double clicking on it.
* Get Selected Flight
es_flight = ms_flight.
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.
Enter description, In Root class enter the created ‘Shared Memory-Enabled’ class in step 1, and select client-specific Area check box.
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.
Enter Description and click on OK.
Step 2: Data Binding
Go to the Context tab of Main View and create a node BOOKINGS.
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 WDDOINIT method.
* 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 ).
* Reading from Shared Memory ( Importing from memory )
lr_shm_handle = zcl_flight_data_area=>attach_for_read( ).
es_flight = ls_flight ).
* Here ls_flight contains the data if exported to shared memory,
* else it will catch the exception
* 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 ).
Now Save and Activate the Web Dynpro Component.
Create Web Dynpro Application and save it.
Creating Transaction for Web Dynpro ABAP Application
Go to the SE93 transaction, Enter Transaction name and click on create.
Enter description, select ‘Transaction with parameters’ radio button and click on OK.
In the following screen,
- Enter Transaction WDYID
- Select ‘Skip Initial screen’
- Select GUI Support
- Under Default Values, Enter:
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.