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
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:
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_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'.
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
Enter Description and click on OK.
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.
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.
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_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 ). endmethod. |
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,
Name Value
APPLICATION | ZWD_BOOKINGS_SHM_DEMO |
STARTMODE | SAPGUI |
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
37 | |
10 | |
7 | |
5 | |
5 | |
5 | |
4 | |
4 | |
3 | |
3 |