Application Development 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: 

se24 - Methods linking Events

Former Member
0 Kudos

Hi All,

I am trying to understand the concept of assigning eventhandler to a method defined in a Class.

my question is :

ex : Method : meth assigned eventhandler event1.

what exactly we are assigning her ? if we write code in the method meth and i access the event in the class will it display the functionality that was written in the method meth .

please suggest with some custom sample class .

Thanks

Ry

2 REPLIES 2

MarcinPciak
Active Contributor
0 Kudos

Hi,

First, as you have noticed, you define class for receiveng an event


CLASS cl_event_receiver DEFINITION.
  PUBLIC SECTION.
    METHODS:
     "here goes your meth which will handle event
      handle_event FOR EVENT some_class_event OF class_of_the_event
                          IMPORTING 
                          "here you need to check what is imported to the method
                          "go to se24->event->properties and copy here all parameters from there
                          "note! you don't provide type of parameters here, just their names
ENDCLASS.
 
CLASS cl_event_receiver IMPLEMENTATION.
   METHOD handle_event.
      "here you do your coding in order to do certain thing when event is raised, it is up to you what you put there
      "it can be whatever depending on event and context
   ENDMETHOD.
ENDCLASS.
 
CREATE OBJECT cl_alv_event_receiver.
 
"now just indicate the handler for this class (acctually it is for all objects of this class, unless you replace 
"cl_class with your object of this class, then it will be applicable only for this object
SET HANDLER cl_event_receiver->handle_event FOR cl_class. 

Now, when the event is raised (i.e. expand event on tree control) processing is passed to your method

handle_event where you put your code.

Please note!

For some classes it is not sufficient. You need to register the event first with REGISTER_EVENTS method (usually but not always). Again it depends on used class and event. For more detail see documentation of a particular class.

Hope it will help you

Marcin

uwe_schieferstein
Active Contributor
0 Kudos

Hello

Marcin explained the concept quite well. Here I add just a few remarks.

ex : Method : meth assigned eventhandler event1.

Assigning method METH to event EVENT1 means it has the signature of this event as described in the class (SE24).

Please note that each event handler method has the optional IMPORTING parameter SENDER which is the instance that raised the event.

However, this assignment is not sufficient. You need to register the event handler method METH at the control framework (using statement SET HANDLER).

Now when the instance raises an event the control framework check which methods have been registered as event handler and calls these event handler methods (in an arbitrary way => not sorted).

Finally, whereas all events of the ALV grid (CL_GUI_ALV_GRID) are already registered at the class itself (i.e. all events of this class are active) you need to register the active events for the ALV tree (method SET_REGISTERED_EVENTS) that you want to use.

Thus, event handling requires 2-3 steps depending on the used control:

(1) Define event handler methods (usually within a local class)
(2) Register events (!) that should be active at the event-triggering class (e.g. CL_GUI_ALV_TREE, method SET_REGISTERED_EVENTS)
=> not required for ALV grid but all other controls
(3) Register event handling (!) at the control framework (statement SET HANDLER)

Regards

Uwe