Event handler method can be used in the same class by declaring the event and the handler method with the triggering method. Here the triggering method will raise or trigger the event in the implementation part.
The program below contains a class CLASS_A which contains data and constant in the public section. It contains events evnt1 and evnt2 here. And also it has event handler methods evnthand1 and evnthand2. It also contains triggering methods trig1 and trig2.
Now at the time of implementation, we implement the event handler methods evnthand1 and evnthand2 with a general statement. After that, we implement the triggering of event method trig1 and trig2 with RAISE EVENT statement.
Finally, at the start of selection, we set handler method evnthand1 and evnthand2 by the object. Then we call triggering method trig1 and trig2.
In the debugging mode when the program controller is at CALL METHOD: obj->trig1 then it calls the method trig1 and as the controller goes to RAISE EVENT evnt1 then it goes to event handler method evnthand1. There it follows the general statement. After finishing off that the controller comes back to the triggering method trig1 and end this method. Then it will go for the next triggering method trig2 and next steps will be similar. Here raise event will be evnt2 and event handler method is evnthand2.
REPORT zevent_sameclass.
*----------------------------------------------------------------------*
* CLASS CLASS_A DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class_a DEFINITION.
PUBLIC SECTION.
* Data Declaration
DATA lv_txt TYPE char50.
CONSTANTS c_das TYPE char50 VALUE '--------------------------------'.
* Method and Event Declaration
EVENTS:
evnt1, evnt2.
METHODS:
evnthand1 FOR EVENT evnt1 OF class_a,
evnthand2 FOR EVENT evnt2 OF class_a,
trig1,
trig2.
ENDCLASS. "A DEFINITION
*----------------------------------------------------------------------*
* CLASS CLASS_A IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS class_a IMPLEMENTATION.
METHOD evnthand1.
lv_txt = 'First Event Handler Method'.
WRITE / lv_txt.
SKIP 2.
ENDMETHOD. "evnthand1
METHOD evnthand2.
lv_txt = 'Second Event Handler Method'.
WRITE / lv_txt.
SKIP 2.
ENDMETHOD. "evnthand2
METHOD trig1.
lv_txt = 'First Event is being Triggered:'.
WRITE: / lv_txt,
/ c_das.
RAISE EVENT evnt1.
ENDMETHOD. "trig1
METHOD trig2.
lv_txt = 'Second Event is being Triggered:'.
WRITE: / lv_txt,
/ c_das.
RAISE EVENT evnt2.
ENDMETHOD. "trig2
ENDCLASS. "A IMPLEMENTATION
* Start of selection
START-OF-SELECTION.
DATA obj TYPE REF TO class_a.
* Create object
CREATE OBJECT obj.
* Set the event handler
SET HANDLER: obj->evnthand1 FOR obj,
obj->evnthand2 FOR obj.
* Call the triggering methods
CALL METHOD: obj->trig1,
obj->trig2.
Output