SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
ABAP Keyword Documentation → ABAP − Reference → Calling and leaving program units → Calling Processing Blocks → Call Event Handler → SET HANDLER →
SET HANDLER - FOR
Syntax
SET HANDLER handler1 handler2 ... FOR { oref |{ALL INSTANCES} }
[ACTIVATION act].
Extras:
1. ... FOR oref
2. ... FOR ALL INSTANCES
3. ... ACTIVATION act
Effect
This statement registers the event handlers handler1 handler2 ... for the associated instance events of the objects specified after FOR. The addition ACTIVATION can be used to deregister event handlers or perform a dynamic registration.
An event handler is executed if the associated instance event is triggered using RAISE EVENT in an object for which it is registered. An event handler handler can be specified as follows, where the names have the same meaning as in the explicit method call:
Methods meth can be specified from the same class or from other classes defined as instance event handlers using the addition FOR EVENT evt OF {class|intf} of the statements [CLASS-]METHODS. No event handlers for static events can be specified. At least one name must be specified.
The type class or intf specified after FOR
EVENT OF in the definition of an instance event handler defines the objects whose events it can handle. Single objects or all handleable objects can be specified after FOR.
... FOR oref
Effect
This addition registers or deregisters the event handlers of the list handler1 handler2 ... for exactly one object. oref is an object reference that must point to an object whose events can be handled by the specified event handlers. The class of the object must be class or a subclass of class, or must implement the interface intf directly or through a superclass.
oref is a functional operand position.
Example
Registers an event handler for an ALV event.
CLASS demo DEFINITION.
PUBLIC SECTION.
METHODS main.
PRIVATE SECTION.
DATA itab TYPE TABLE OF scarr.
METHODS handle_double_click
FOR EVENT double_click OF cl_salv_events_table.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
DATA alv TYPE REF TO cl_salv_table.
...
TRY.
cl_salv_table=>factory(
IMPORTING r_salv_table = alv
CHANGING t_table = itab ).
SET HANDLER handle_double_click FOR alv->get_event( ).
CATCH cx_salv_msg.
...
ENDTRY.
ENDMETHOD.
METHOD handle_double_click.
...
ENDMETHOD.
ENDCLASS.
... FOR ALL INSTANCES
Effect
This addition registers or deregisters the event handlers of the list handler1 handler2
... for all objects whose events they can handle. These are all objects whose classes are either
class or the subclass of class, or which implement
the interface intf directly or through a superclass. A registration of this
type is also valid for all triggering instances created after the statement SET HANDLER.
... ACTIVATION act
Effect
A single-character text-like field act can be specified after the addition ACTIVATION. If act has a value "X" (default value), the event handlers handler are registered; however, if act has the value " ", the registration of the event handlers handler is canceled. A single registration cannot, however, be deregistered using mass deregistration. Conversely, individual triggering objects cannot be excluded from registration after a mass registration.
Note
As long as the registration of an instance method as an event handler for an instance event is not canceled using ACTIVATION " " or all triggering instances are deleted, the associated object cannot be deleted by the garbage collector, since it is still used by the runtime environment.