SET HANDLER

Short Reference

Syntax Forms


Register instance events handler

1. SET HANDLER handler1 handler2 ... FOR oref|{ALL INSTANCES}
                                    [ACTIVATION act].

Register static events handler

2. SET HANDLER handler1 handler2 ... [ACTIVATION act].

Effect

This statement registers the event handlershandler for the corresponding instance events or static events.

System fields

sy-subrc Meaning
0 All specified handlers could be registriered or deregistered.
4 At least one of the specified handlers could not be registered, as it is already registered for the same event.
8 At least one of the specified handlers could not be deregistered, as it was not registered for the event in question.

Note

The statement SET HANDLER manages, for single registration, mass registration and registration for static events, internally different system tables that relate the triggers and event handlers to each other. 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 several system tables, that is, it can be registered for different events. When the system triggers an event with RAISE EVENT, it evaluates the corresponding system tables and calls the event handlers registered there in the order that they were registered. During registration of an instance method, a reference to the corresponding object is included in the corresponding system table and then deleted again during deregistration. With regard to the Garbage Collector, such a reference has the same effect as a reference in a reference variable. If a triggering instance is deleted by the Garbage Collector, the corresponding system table is also deleted and as a result, its registrations are reversed.

Example

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 referred to by the reference variable trigger. In the second statement SET HANDLER, an instance method h3 is registered for the static event ce1 of class c1.

CLASS c1 DEFINITION.
  PUBLIC SECTION.
    EVENTS e1.
    CLASS-EVENTS ce1.
ENDCLASS.

CLASS c2 DEFINITION INHERITING FROM c1.
  PUBLIC SECTION.
    EVENTS e2.
ENDCLASS.

CLASS c3 DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS  h1 FOR EVENT e1 OF c1.
          METHODS: h2 FOR EVENT e2 OF c2,
                   h3 FOR EVENT ce1 OF c1.
ENDCLASS.

...

DATA: trigger TYPE REF TO c2,
      handler TYPE REF TO c3.

SET HANDLER: c3=>h1 handler->h2 FOR trigger,
             handler->h3.

Exceptions

Non-Catchable Exceptions