In the first part, How to pass data to from ABAP to Web Dynpro ABAP- Part 1 , we have seen how to create shared memory objects and creating Web Dynpro ABAP Application.
Now we will see, creating ABAP ALV Report and how to call and pass data to Web Dynpro Application using shared memory object.
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_SHM_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_shm, assign Functions SAVE and EXIT to *& standard icons. and create Title zt_shm. *&---------------------------------------------------------------------* REPORT ZKK_FLIGHT_SHM_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 of 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: lr_shm_handle TYPE REF TO zcl_flight_data_area, lr_shm_root TYPE REF TO zcl_flight_data_root. * Get the double clicked row (selected Flight data) READ TABLE lt_sflight INTO ls_sflight INDEX e_row. TRY . * Writing to Shared Memory ( Exporting to memory ) lr_shm_handle = zcl_flight_data_area=>attach_for_write( ). CREATE OBJECT lr_shm_root AREA HANDLE lr_shm_handle. lr_shm_handle->set_root( lr_shm_root ). lr_shm_root->set_selected_flight( exporting is_flight = ls_sflight ). lr_shm_handle->detach_commit( ). 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. * Call Flight Bookings Web Dynpro Appl CALL TRANSACTION 'ZBOOKINGS_SHM'. 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_SHM'. " Create title bar zt_shm SET PF-STATUS 'ZPF_SHM'. " Create PF status zpf_shm 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.
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 for the selected Flight in the next screen.
1. Here when we double click on any record in ALV, the handle_double_click method will be called, and we are getting the selected row data using:
Get selected row data |
---|
* Get the double clicked row (selected Flight data) READ TABLE lt_sflight INTO ls_sflight INDEX e_row. |
2. Then we are Exporting the selected row data to Shared Memory using:
Writing to Shared Memory (Export to Memory) |
---|
* Writing to Shared Memory ( Exporting to memory ) lr_shm_handle = zcl_flight_data_area=>attach_for_write( ). CREATE OBJECT lr_shm_root AREA HANDLE lr_shm_handle. lr_shm_handle->set_root( lr_shm_root ). lr_shm_root->set_selected_flight( exporting is_flight = ls_sflight ). lr_shm_handle->detach_commit( ). |
3. Then we are calling the Flight Bookings Data Web Dynpro Application
Call Bookings Web Dynpro Application |
---|
* Call Flight Bookings Web Dynpro Appl CALL TRANSACTION 'ZBOOKINGS_SHM'. |
4. Once the Web Dynpro Application is called, the WDDOINT method will be executed and here we are Importing the data from Shared Memory which was exported earlier described in step 2.
Reading from Shared memory( Importing from Memory) |
---|
* 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( ). |
5. Once the data is importing from memory, we are fetching the Flight Bookings for the imported data and binding it to the Table UI.
Get Flight Booking data and Binding to Table UI |
---|
* 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 ). |
As we binded the Flight Bookings data, when the Web Dynpro View rendered, we can see the Flight Bookings data in the Table.
Recommendation
Here I would like to mention thomas.jung sir's comment regarding shared memory objects which I found in one thread
Thomas Jung's Comment regarding Shared Memory Object |
---|
This approach is actually not that reliable. In post production servers you have more than one application server. When the WDA application opens, due to load balancing there is no guarantee that the user session for the WDA application will be on the same application server as the originating SAPGUI screen (or whatever your original process was). Share memory objects exist in the global memory of the application server. They do not cross application servers. Unless you use some RFC based tricks to propigate your shared memory objects across all application servers, you will likely find that this approach fails some times in production systems with multiple application servers. I would instead suggest passing small amounts of information via URL parameters. For larger amounts or data types that can't easily be converted to strings, you should consider writting the data into the database temporarily (perhaps as a server cookie). This is the only way to ensure persistence in a multiple application server environment. |
References
http://help.sap.com/saphelp_nw70/helpdata/en/14/dafc3e9d3b6927e10000000a114084/frameset.htm
http://help.sap.com/saphelp_nw70/helpdata/en/c5/85634e53d422409f0975aa9a551297/content.htm
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
7 | |
5 | |
4 | |
4 | |
4 | |
4 | |
3 | |
3 | |
3 |