METHODS - FOR EVENT

Syntax

METHODS meth [ABSTRACT|FINAL]
   FOR EVENT evt OF {class|intf}
   [IMPORTING p1 p2 ... [sender]].

Extras:

1. ... IMPORTING p1 p2 ... [sender]

2. ... ABSTRACT

3. ... FINAL

Effect

This statement declares the instance method meth as an event handler for the event evt of class class or interface intf. For class and intf, you can specify all classes and interfaces, which are visible in this position and which contain an event evt as a component that is visible here.

If the event evt is an instance event, then the event handler meth can handle it for all objects whose classes are equal to class or a subclass of class or that implement the interface intf directly or using a superclass. If the event is a static event, the event handler meth can handle it for the class class and its subclasses or for call classes that implement the interface intf.

Addition 1

... IMPORTING p1 p2 ... [sender]

Effect

The addition IMPORTING defines the input parameters of the event handler. For p you can specify only those names of formal parameters that have been defined with the addition EXPORTING of statement EVENTS or CLASS-EVENTS in the declaration of the event evt in class class or interface intf as output parameters of the event. The additions TYPE or LIKE and OPTIONAL or DEFAULT are not possible. The typing of the input parameters, the property whether they are optional, and possible replacement parameters are copied from the declaration of the event. You need not specify all output parameters of the event.

If evt is an instance event, you can, in addition to the explicitly defined output parameters, define a formal parameter named sender as input parameter of an event handler. The formal parameter sender is an implicit output parameter or every instance event. It is typed fully as a reference variable, which has the class class or the interface intf as a static type, as specified in the declaration of the event handler after EVENT evt OF. If the event handler is called by an instance event, a reference to the triggering object is passed to it in sender.

Before release 6.10, the static type of the formal parameter sender was determined by the class or interface, in which the event was declared with the EVENTS statement. As of release 6.10, the event handler itself determines the type of its formal parameter.

Addition 2

... ABSTRACT

Addition 3

... FINAL

Effect

Use additions ABSTRACT and FINAL to make event handlers as in general methods either abstract or final.

Note

In event handlers, you cannot declare class-based exceptions with RAISING, because event handler and trigger are uncoupled completely. A trigger of an event does not know the handlers and therefore cannot handle their exceptions.

Example

The class picture contains an event handler handle_double_click for the instance event picture_dblclick of the global class cl_gui_picture. The event handler copies two explicit output parameters and the implicit parameter sender as input parameters.

CLASS picture DEFINITION.
  PUBLIC SECTION.
    METHODS handle_double_click
            FOR EVENT picture_dblclick OF cl_gui_picture
            IMPORTING mouse_pos_x mouse_pos_y sender.
ENDCLASS.

CLASS picture IMPLEMENTATION.
  METHOD handle_double_click.
    ...
  ENDMETHOD.
ENDCLASS.