Static Events are Triggered by Static Methods
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 cls 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 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 ZSR_TEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zsr_test.
*----------------------------------------------------------------------*
* CLASS cls DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls DEFINITION.
PUBLIC SECTION.
DATA v_txt TYPE char50.
CLASS-EVENTS: evnt1, evnt2.
METHODS: evnthand1 FOR EVENT evnt1 OF cls,
evnthand2 FOR EVENT evnt2 OF cls.
CLASS-DATA v_cls TYPE char50.
CLASS-METHODS: trig1, trig2.
ENDCLASS. "cls DEFINITION
*----------------------------------------------------------------------*
* CLASS cls IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls 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_cls = 'Triggering Static Method One:'.
WRITE / v_cls.
RAISE EVENT evnt1.
ENDMETHOD. "trig1
METHOD trig2.
v_cls = 'Triggering Static Method Two:'.
WRITE / v_cls.
RAISE EVENT evnt2.
ENDMETHOD. "trig2
ENDCLASS. "cls IMPLEMENTATION
START-OF-SELECTION.
DATA obj TYPE REF TO cls.
CREATE OBJECT obj.
SET HANDLER: obj->evnthand1,
obj->evnthand2.
CALL METHOD: obj->trig1,
obj->trig2.
Output is as follows:
The following program contains a class cls 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 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 ZSR_TEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zsr_test.
*----------------------------------------------------------------------*
* CLASS cls DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls DEFINITION.
PUBLIC SECTION.
DATA v_txt TYPE char50.
CLASS-EVENTS: evnt1, evnt2.
METHODS: evnthand1 FOR EVENT evnt1 OF cls,
evnthand2 FOR EVENT evnt2 OF cls.
CLASS-DATA v_cls TYPE char50.
CLASS-METHODS: trig1, trig2.
ENDCLASS. "cls DEFINITION
*----------------------------------------------------------------------*
* CLASS cls IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls 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_cls = 'Triggering Static Method One:'.
WRITE / v_cls.
RAISE EVENT evnt1.
ENDMETHOD. "trig1
METHOD trig2.
v_cls = 'Triggering Static Method Two:'.
WRITE / v_cls.
RAISE EVENT evnt2.
ENDMETHOD. "trig2
ENDCLASS. "cls IMPLEMENTATION
START-OF-SELECTION.
DATA obj TYPE REF TO cls.
CREATE OBJECT obj.
SET HANDLER: obj->evnthand1,
obj->evnthand2.
CALL METHOD: obj->trig1,
obj->trig2.
Output is as follows:
Post a Comment