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

ABAP - OOPS: More Than One Event Handler Method For Same Event.

REPORT YSUBOOPS7 .

CLASS c1 DEFINITION.
PUBLIC SECTION.
* Creating event : E1
EVENTS: E1.
* Creating an event handling method.
METHODS: M1 FOR EVENT E1 OF c1.
* Method to raise the event
METHODS : T1.
ENDCLASS.

CLASS C2 DEFINITION.
PUBLIC SECTION.
* Creating an event handling method.
METHODS: M2 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.
* Method : M1 will be called when the event is raised
METHOD : M1.
write:/5 ' I am the event handler method M1 in c1'.
ENDMETHOD.
ENDCLASS.

class c2 implementation.
* Method : M2 will be called when the event is raised
METHOD : M2.
write:/5 ' I am the event handler method M2 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 oref1->M1 FOR oref1 .
* Calling the event which will raise the event.
call method oref1->T1.
* De-Registering the earlier event handler method
SET HANDLER oref1->M1 FOR oref1 ACTIVATION space .
* Registering the new event handler method
SET HANDLER oref2->M2 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 M1 in c1
I am T1, going to raise event E1
I am the event handler method M2 in c2

No comments:

Post a Comment