Google Search - Blog...........

ABAP - OOPS: Events With Handler Method In The Same Class.

REPORT YSUBOOPS7 .

CLASS c1 DEFINITION.
PUBLIC SECTION.
*(1)Creating event : E1
EVENTS: E1.
*(2) Creating an event handling method. This method can belong to
* same or different class
METHODS: M1 FOR EVENT E1 OF c1.
* Method to raise the event
METHODS : T1.
ENDCLASS.

CLASS c1 IMPLEMENTATION.
* Method : M1 will be called when the event is raised
METHOD : M1.
write:/5 ' I am the event handler method'.
ENDMETHOD.
* Method : T1 will raise the event
METHOD : T1.
write:/5 'I am T1, going to raise event E1'.
raise event E1.
ENDMETHOD.
ENDCLASS.


Start-of-selection.
Data: oref type ref to c1.
Create object: oref .
* Registering the event handler method
SET HANDLER oref->M1 FOR oref .
* Calling the event which will raise the event.
call method oref->T1.


Output:

I am T1, going to raise event E1
I am the event handler method

No comments:

Post a Comment