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

ABAP - OOPS: Event With Event Handler Method In Different Class

REPORT YSUBOOPS7 .

CLASS c1 DEFINITION.
PUBLIC SECTION.
* Creating event : E1
EVENTS: E1.
* Triggering method : T1
METHODS : T1.
ENDCLASS.

CLASS C2 DEFINITION.
PUBLIC SECTION.
* Creating an event handling method.
METHODS: M1 FOR EVENT E1 OF c1.
endclass.

CLASS c1 IMPLEMENTATION.
* Method : T1 will raise the event
METHOD : T1.
write:/5 'I am T1, going to raise event E1'.
raise event E1.
ENDMETHOD.
ENDCLASS.

class c2 implementation.
* Method : M1 will be called when the event is raised
METHOD : M1.
write:/5 ' I am the event handler method in c2'.
ENDMETHOD.
endclass.

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


Output:

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

No comments:

Post a Comment