Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Calling and leaving program units →  Calling Processing Blocks →  Call Event Handler →  SET HANDLER 

SET HANDLER - static_event

Quick Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


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

Addition

... ACTIVATION act

Effect

This statement registers the event handlers handler1 handler2 ... for the associated static events. The addition ACTIVATION can be used to deregister event handlers or perform a dynamic registration.

An event handler is executed if the associated static event is raised using RAISE EVENT. The list handler1 handler2 ... has the same form as for instance events, but can only contain event handlers for static events declared using CLASS EVENTS.

Events that can be handled by an event handler for static events are defined uniquely by their definition in the statement [CLASS-] METHODS. The addition FOR (required when registering or deregistering instance event handlers to determine the raising instances) cannot be specified. An event handler for static events is registered or deregistered independently of the instance and this applies globally to the current internal session.

Addition

... ACTIVATION act

Effect

The same applies to the syntax and semantics of the addition ACTIVATION as to the statement SETHANDLER for instance events.


Note

As long as the registration of an instance method as an event handler for a static event is not canceled using ACTIVATION " ", the associated object cannot be deleted by the garbage collector. This is because it is still used by the runtime environment.


Example

Registering a static handler for a static event. After the event has been triggered, the handling takes place.

CLASS cls DEFINITION. 
  PUBLIC SECTION. 
    CLASS-EVENTS evt 
      EXPORTING VALUE(p) TYPE string DEFAULT `nop`. 
    CLASS-METHODS meth. 
ENDCLASS. 

CLASS cls IMPLEMENTATION. 
  METHOD meth. 
    RAISE EVENT evt EXPORTING p = `Ping!`. 
  ENDMETHOD. 
ENDCLASS. 

CLASS hdl DEFINITION. 
  PUBLIC SECTION. 
    CLASS-METHODS meth FOR EVENT evt OF cls 
      IMPORTING p. 
ENDCLASS. 

CLASS hdl IMPLEMENTATION. 
  METHOD meth. 
    cl_demo_output=>display( p ). 
  ENDMETHOD. 
ENDCLASS. 

START-OF-SELECTION. 
  SET HANDLER hdl=>meth ACTIVATION 'X'. 
  cls=>meth( ).