abap - part 2 how to pass data to web dynpro abap from · how to pass data to web dynpro abap from...

15
Generated by Jive on 2013-08-30+02:00 1 How to pass data to Web Dynpro ABAP from ABAP - Part 2 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. Creating ABAP ALV Report Execute Transaction SE38. Enter Program Name and click on create.

Upload: hoangkien

Post on 08-Sep-2018

320 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: ABAP - Part 2 How to pass data to Web Dynpro ABAP from · How to pass data to Web Dynpro ABAP from ABAP - Part 2 In the first part, How to pass data to from ABAP to Web Dynpro ABAP-

Generated by Jive on 2013-08-30+02:001

How to pass data to Web Dynpro ABAP fromABAP - Part 2

In the first part, How to pass data to from ABAP to Web Dynpro ABAP- Part 1 , we haveseen 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 DynproApplication using shared memory object.

Creating ABAP ALV ReportExecute Transaction SE38. Enter Program Name and click on create.

Page 2: ABAP - Part 2 How to pass data to Web Dynpro ABAP from · How to pass data to Web Dynpro ABAP from ABAP - Part 2 In the first part, How to pass data to from ABAP to Web Dynpro ABAP-

How to pass data to Web Dynpro ABAP from ABAP - Part 2

Generated by Jive on 2013-08-30+02:002

Enter description, select report type and click on Save.

Page 3: ABAP - Part 2 How to pass data to Web Dynpro ABAP from · How to pass data to Web Dynpro ABAP from ABAP - Part 2 In the first part, How to pass data to from ABAP to Web Dynpro ABAP-

How to pass data to Web Dynpro ABAP from ABAP - Part 2

Generated by Jive on 2013-08-30+02:003

Now Enter the below code

Header 1

*&---------------------------------------------------------------------*

*& Report ZKK_FLIGHT_SHM_DEMO

*&

*&---------------------------------------------------------------------*

Page 4: ABAP - Part 2 How to pass data to Web Dynpro ABAP from · How to pass data to Web Dynpro ABAP from ABAP - Part 2 In the first part, How to pass data to from ABAP to Web Dynpro ABAP-

How to pass data to Web Dynpro ABAP from ABAP - Part 2

Generated by Jive on 2013-08-30+02:004

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

Page 5: ABAP - Part 2 How to pass data to Web Dynpro ABAP from · How to pass data to Web Dynpro ABAP from ABAP - Part 2 In the first part, How to pass data to from ABAP to Web Dynpro ABAP-

How to pass data to Web Dynpro ABAP from ABAP - Part 2

Generated by Jive on 2013-08-30+02:005

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 fordemo

Page 6: ABAP - Part 2 How to pass data to Web Dynpro ABAP from · How to pass data to Web Dynpro ABAP from ABAP - Part 2 In the first part, How to pass data to from ABAP to Web Dynpro ABAP-

How to pass data to Web Dynpro ABAP from ABAP - Part 2

Generated by Jive on 2013-08-30+02:006

* Create ALV Instance

CREATE OBJECT lr_grid

EXPORTING

i_parent = cl_gui_custom_container=>screen0. " Default sceen ( No need of customcontainer )

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

Page 7: ABAP - Part 2 How to pass data to Web Dynpro ABAP from · How to pass data to Web Dynpro ABAP from ABAP - Part 2 In the first part, How to pass data to from ABAP to Web Dynpro ABAP-

How to pass data to Web Dynpro ABAP from ABAP - Part 2

Generated by Jive on 2013-08-30+02:007

* 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

Page 8: ABAP - Part 2 How to pass data to Web Dynpro ABAP from · How to pass data to Web Dynpro ABAP from ABAP - Part 2 In the first part, How to pass data to from ABAP to Web Dynpro ABAP-

How to pass data to Web Dynpro ABAP from ABAP - Part 2

Generated by Jive on 2013-08-30+02:008

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

*----------------------------------------------------------------------*

Page 9: ABAP - Part 2 How to pass data to Web Dynpro ABAP from · How to pass data to Web Dynpro ABAP from ABAP - Part 2 In the first part, How to pass data to from ABAP to Web Dynpro ABAP-

How to pass data to Web Dynpro ABAP from ABAP - Part 2

Generated by Jive on 2013-08-30+02:009

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

Page 10: ABAP - Part 2 How to pass data to Web Dynpro ABAP from · How to pass data to Web Dynpro ABAP from ABAP - Part 2 In the first part, How to pass data to from ABAP to Web Dynpro ABAP-

How to pass data to Web Dynpro ABAP from ABAP - Part 2

Generated by Jive on 2013-08-30+02:0010

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.

Page 11: ABAP - Part 2 How to pass data to Web Dynpro ABAP from · How to pass data to Web Dynpro ABAP from ABAP - Part 2 In the first part, How to pass data to from ABAP to Web Dynpro ABAP-

How to pass data to Web Dynpro ABAP from ABAP - Part 2

Generated by Jive on 2013-08-30+02:0011

We can see the Flight Bookings Web Dynpro Application for the selected Flight in the nextscreen.

Page 12: ABAP - Part 2 How to pass data to Web Dynpro ABAP from · How to pass data to Web Dynpro ABAP from ABAP - Part 2 In the first part, How to pass data to from ABAP to Web Dynpro ABAP-

How to pass data to Web Dynpro ABAP from ABAP - Part 2

Generated by Jive on 2013-08-30+02:0012

Explanation

1. Here when we double click on any record in ALV, the handle_double_click method will becalled, 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

Page 13: ABAP - Part 2 How to pass data to Web Dynpro ABAP from · How to pass data to Web Dynpro ABAP from ABAP - Part 2 In the first part, How to pass data to from ABAP to Web Dynpro ABAP-

How to pass data to Web Dynpro ABAP from ABAP - Part 2

Generated by Jive on 2013-08-30+02:0013

CALL TRANSACTION 'ZBOOKINGS_SHM'.

4. Once the Web Dynpro Application is called, the WDDOINT method will be executed andhere we are Importing the data from Shared Memory which was exported earlier describedin 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 theimported 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).

Page 14: ABAP - Part 2 How to pass data to Web Dynpro ABAP from · How to pass data to Web Dynpro ABAP from ABAP - Part 2 In the first part, How to pass data to from ABAP to Web Dynpro ABAP-

How to pass data to Web Dynpro ABAP from ABAP - Part 2

Generated by Jive on 2013-08-30+02:0014

As we binded the Flight Bookings data, when the Web Dynpro View rendered, we can seethe Flight Bookings data in the Table.

Recommendation

Here I would like to mention Thomas Jung sir's comment regarding shared memory objectswhich 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 thanone application server. When the WDA application opens, due to load balancing there isno guarantee that the user session for the WDA application will be on the same applicationserver 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 notcross application servers. Unless you use some RFC based tricks to propigate your sharedmemory objects across all application servers, you will likely find that this approach failssome times in production systems with multiple application servers.

I would instead suggest passing small amounts of information via URL parameters. Forlarger amounts or data types that can't easily be converted to strings, you should considerwritting the data into the database temporarily (perhaps as a server cookie). This is the onlyway to ensure persistence in a multiple application server environment.

Page 15: ABAP - Part 2 How to pass data to Web Dynpro ABAP from · How to pass data to Web Dynpro ABAP from ABAP - Part 2 In the first part, How to pass data to from ABAP to Web Dynpro ABAP-

How to pass data to Web Dynpro ABAP from ABAP - Part 2

Generated by Jive on 2013-08-30+02:0015

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