We can use the Static events in a class but the triggering methods must be static in this class. At the time of registration, the FOR clause with object name is not required.
The following program contains a class ABC in which we have two static events evnt1 and evnt2 with two static triggering methods trig1 and trig2. We also have two handler methods evnthand1 and evnthand2. Now in the implementation we displaying some text in handler methods as well as triggering methods.
Next, in the start of selection, we have registered the handler method with an object but there is no need to use the FOR clause with object name because this registration is for static events. Finally, we call the two static triggering methods as well.
REPORT zevent_statichandler.
*----------------------------------------------------------------------*
* CLASS ABC DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS abc DEFINITION.
PUBLIC SECTION.
DATA v_txt TYPE char50.
CLASS-DATA v_abc TYPE char50.
CLASS-EVENTS:
evnt1,
evnt2.
METHODS:
evnthand1 FOR EVENT evnt1 OF abc,
evnthand2 FOR EVENT evnt2 OF abc.
CLASS-METHODS:
trig1,
trig2.
ENDCLASS. "ABC DEFINITION
*----------------------------------------------------------------------*
* CLASS ABC IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS abc IMPLEMENTATION.
METHOD evnthand1.
v_txt = 'Static Event - Handler Method One'.
WRITE / v_txt.
SKIP.
ENDMETHOD. "evnthand1
METHOD evnthand2.
v_txt = 'Static Event - Handler Method Two'.
WRITE / v_txt.
SKIP.
ENDMETHOD. "evnthand2
METHOD trig1.
v_abc = 'Triggering Static Method One:'.
WRITE / v_abc.
RAISE EVENT evnt1.
ENDMETHOD. "trig1
METHOD trig2.
v_abc = 'Triggering Static Method Two:'.
WRITE / v_abc.
RAISE EVENT evnt2.
ENDMETHOD. "trig2
ENDCLASS. "ABC IMPLEMENTATION
* Start of selection
START-OF-SELECTION.
* Data Declaration
DATA obj TYPE REF TO abc.
* Object creation
CREATE OBJECT obj.
* Set the handler
SET HANDLER: obj->evnthand1,
obj->evnthand2.
* Trigger the events
CALL METHOD: obj->trig1,
obj->trig2.
Output