SAP SET HANDLER ABAP Statements



Get Example source ABAP code based on a different SAP table
  


ID SET-HANDLER
• SET HANDLER ABAP Statement

SET HANDLER
Short Reference

ABAP_SYNTAX_FORMS

Register Instance Event Handlers
1 SET HANDLER handler1 handler2 ... FOR oref$|${ALL INSTANCES$}
$[ACTIVATION act$].

Register Static Event Handlers
2 SET HANDLER handler1 handler2 ... $[ACTIVATION act$].

What does it do?
This statement registers or deregisters the event handlers handler for the corresponding instance events or static events.
System Fields sy-subrcMeaning 0 All specified handlers could be registered or deregistered. 4 At least one of the specified handlers could not be registered, as it is already registered for the same event. 8At least one of the specified handlers could not be deregistered, as it is not registered for the event in question.



Latest notes:

The statement SET HANDLER internally manages different system tables that relate the event raisers and event handlers to each other in single registrations, mass registrations, and registrations of static events. Each registration represents one line in one of the system tables assigned to the trigger. A handler can only occur once in a particular system table but can appear in multiple system tables, that is, it can be registered for different events. When an event is raised using RAISE EVENT, the system evaluates the corresponding system tables and calls the event handlers registered there.
The order of the calls of registered event handlers is not defined and can change at program runtime. To get a fixed order of different method calls, these can be called in one event handler.
When an instance method is registered, a reference to the corresponding object is added in the relevant table and then deleted again when deregistering. With respect to the Garbage Collector, such a reference has the same effect as a reference in a reference variable. Objects registered as handlers are therefore not deleted as long as they are registered, that is, they are not deregistered using the addition ACTIVATION. If a triggering instance is deleted by the Garbage Collector, the corresponding system table is also deleted and, as a result, its registrations are removed.
If the statement SET HANDLER registers the current handler again for the current event that has just been handled, it is not defined whether the registration is ignored by the current event handler. This can produce endless recursions and should be avoided.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
Registration of event handlers for two instance events and a static event. In the first statement SET HANDLER , a static event handler h1 and an instance method h2, are registered for the instance events e1 and e2 of the object referenced by the reference variable trigger. In the second statement SET HANDLER, an instance method h3 is registered for the static event ce1 of the class c1.
ABEXA 01689
ABAP_EXAMPLE_END



Runtime Exceptions


Non-catchable Exceptions
Reason for error:
Unable to register any more handlers.
Runtime error:
SET_HANDLER_DISP_OVERFLOW
Reason for error:
Handlers of instance methods need the FOR addition.
Runtime error:
SET_HANDLER_E_NO_FOR
Reason for error:
Event handler was registered for a static event.
Runtime error:
SET_HANDLER_FOR_CE
Reason for error:
The raiser of an event must not be NULL.
Runtime error:
SET_HANDLER_FOR_NULL
Reason for error:
The handler of an event must not be NULL.
Runtime error:
SET_HANDLER_HOBJ_NULL
ABAP_NONCAT_END

Return to menu