01-06-2013 4:05 AM
Hi Friends,
I searched many threads in sdn and i am not able to understand that event handling problem that is i am registering method m3 and m2 but it is raising events e1 and e2 and when i am trying for single event e1 for both the methods m2 ,m3 it is raising based on registration.
class abc definition.
public section.
events : e1 , e2.
methods : m1,
m2 for event e1 of abc,
m3 for event e2 of abc.
endclass.
class abc implementation.
method m1.
raise event e1.
raise event e2.
endmethod.
method m2.
write : / 'Event Handler method m2 '.
endmethod.
method m3.
write : 'Eventhandler method m3'.
endmethod.
endclass.
start-of-selection.
data : obj_abc type ref to abc.
create object obj_abc.
set handler obj_abc->m3 for obj_abc.
set handler obj_abc->m2 for obj_abc.
call method obj_abc->m1.
Thanks,
Raghunadh.K
01-07-2013 5:49 PM
I didn't follow your question.
Based on your sample code, it would call both methods M2 & M3 as you are raising events E1 and E2 within M1. Can you point, what exactly you are not able to understand.
Regards,
Naimesh Patel
01-08-2013 10:52 AM
Hi Naimesh ,
what my problem is: check the code here i am taking only one event and raising in m1 and after that i am registering m3 and m2 so my o/p is
'method m3 for event e1'.
'method m2 for event e1'.
and it is executing based on registration
but when i am taking two events it is not executing based on registration and it is based up on raising the events in m1. why?
class abc definition.
public section.
events e1.
methods : m1,
m2 for event e1 of abc,
m3 for event e1 of abc.
endclass.
class abc implementation.
method m1.
raise event e1.
endmethod.
method m2.
write : / 'Method m2 for event e1'.
endmethod.
method m3.
write : / 'method m3 for event e1'.
endmethod.
endclass.
start-of-selection.
data : obj_abc type ref to abc.
create object obj_abc.
set handler obj_abc->m3 for obj_abc.
set handler obj_abc->m2 for obj_abc.
call method obj_abc->m1.
Please guide me.
Thanks,
Raghunadh.K
01-08-2013 3:06 PM
When you have more than one event handler for a single event, system will try to process the events in the sequence in which they were registered. However, system wont guarantee the execution in that sequence.
So when you have, code like this it would execute in the sequence it was registered.
set handler obj_abc->m3 for obj_abc.
set handler obj_abc->m2 for obj_abc.
Triggering and Handling Events (SAP Library - ABAP Programming (BC-ABA))
Handler methods are executed in the order in which they were registered. Since event handlers are registered dynamically, you should not assume that they will be processed in a particular order. Instead, you should program as though all event handlers will be executed simultaneously.
Regards,
Naimesh Patel
01-15-2013 11:13 AM