Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

multiple event handler at the same time

Former Member
0 Likes
2,805

Hi,

I registered two event handler for two alv object, which are displayed in same screen. But sometimes one can be triggered and sometimes the other especially for event DATA_CHANGED and SUBTOTAL_TEXT. For example, DATA_CHANGED under event handler A is triggered and that under event handler B is not.

Best regards,

ts

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,806

Hi T.S,

You can handle the events for all instances by defining just a single event handler.

DATA : alv01 TYPE REF TO cl_gui_alv_grid ,

            alv02 TYPE REF TO cl_gui_alv_grid .

SET HANDLER g_event_receiver->handle_data_changed FOR FOR ALL INSTANCES.

CLASS lcl_event_receiver DEFINITION.

PUBLIC SECTION.

CLASS-METHODS:

      handle_data_changed

        FOR EVENT data_changed OF cl_gui_alv_grid

        IMPORTING

          er_data_changed

          e_onf4

          e_onf4_before

          e_onf4_after

          e_ucomm

         sender.


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

* CLASS lcl_event_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*

  CLASS lcl_event_receiver IMPLEMENTATION.

METHOD handle_data_changed.

CASE sender.

     WHEN alv01.

     "  alv01 has fired the event

     WHEN alv02.

     "   alv02 has fired the event

In this way, you will get events for all instances handled correctly with a single handler.

You can refer these links for sample codes on multiple instance handling and data changed event handling

http://abap-development-consultant.blogspot.ae/2011/05/using-alv-event-handler-for-all.html

http://wiki.scn.sap.com/wiki/display/ABAP/Get+Changed+Value+In+ALV+Grid+Dynamically.

5 REPLIES 5
Read only

Former Member
0 Likes
1,806

Don't need one handler for each ALV GRID

Can use

SET HANDLER ... FOR ALL INSTANCES OF ...

Read only

0 Likes
1,806

I use different event handlers because the user commands are different. Can SET HANDLER ... FOR ALL INSTANCES OF ... handle this?

Read only

0 Likes
1,806

Yes, it can. Refer the code below.

Read only

hiriyappa_myageri
Participant
0 Likes
1,806

Hi TS,


Hi refer below code.
for different alv objects you can pass registered events like this.

data:grid1 type ref to cl_gui_alv_grid,

grid2 type ref to cl_gui_alv_grid,

call method grid1->check_changed_data.

    call method grid1->register_edit_event

exporting

i_event_id = cl_gui_alv_grid=>mc_evt_modified

exceptions

error = 1

others = 2.

call method grid2->check_changed_data.

    call method grid2->register_edit_event

exporting

i_event_id = cl_gui_alv_grid=>mc_evt_modified

exceptions

error = 1

others = 2.


Thanks & Reagards

Hiriyappa

Read only

Former Member
0 Likes
1,807

Hi T.S,

You can handle the events for all instances by defining just a single event handler.

DATA : alv01 TYPE REF TO cl_gui_alv_grid ,

            alv02 TYPE REF TO cl_gui_alv_grid .

SET HANDLER g_event_receiver->handle_data_changed FOR FOR ALL INSTANCES.

CLASS lcl_event_receiver DEFINITION.

PUBLIC SECTION.

CLASS-METHODS:

      handle_data_changed

        FOR EVENT data_changed OF cl_gui_alv_grid

        IMPORTING

          er_data_changed

          e_onf4

          e_onf4_before

          e_onf4_after

          e_ucomm

         sender.


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

* CLASS lcl_event_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*

  CLASS lcl_event_receiver IMPLEMENTATION.

METHOD handle_data_changed.

CASE sender.

     WHEN alv01.

     "  alv01 has fired the event

     WHEN alv02.

     "   alv02 has fired the event

In this way, you will get events for all instances handled correctly with a single handler.

You can refer these links for sample codes on multiple instance handling and data changed event handling

http://abap-development-consultant.blogspot.ae/2011/05/using-alv-event-handler-for-all.html

http://wiki.scn.sap.com/wiki/display/ABAP/Get+Changed+Value+In+ALV+Grid+Dynamically.