EVENTS

Basic form

EVENTS evt.

Extras:

1. ... EXPORTING
       VALUE(p1) TYPE type | LIKE f [OPTIONAL|DEFAULT g]
       ...
       VALUE(pn) TYPE type | LIKE f [OPTIONAL|DEFAULT g]

Effect

Declaration of instance events in a Class or a interface in ABAP Objects.

You can use this statment only in the declaration part of aclass declaration (see CLASS) or in an interface definition (seeINTERFACE) Instance events belong to the components of a class.

You can use the RAISE EVENT statement to trigger an instance event from the instance methods of the same class. You can declare event handler methods for this event in any class using the FOR EVENT evt OFaddition of the METHODS or CLASS-METHODS statements. Triggers and handlers are then assigned dynamically at runtime using the SET HANDLER statement.

Addition 1

... EXPORTING     VALUE(p1) TYPE type | LIKE f [OPTIONAL|DEFAULT g]
    ...
    VALUE(pn) TYPE type | LIKE f [OPTIONAL|DEFAULT g]

Effect

This addition defines the interface for the evt event. The event is declared from the viewpoint of the trigger using the exclusive definition of EXPORTING parameters. When the event is triggered, the interface parameters are passed to the interface of the event handler method using the EXPORTING addition of the RAISE EVENT statement. The interface of an event handler method consists of a list of IMPORTING parameters, whose names are identical with those in the EXPORTING list and which are automatically created from the interface of the event. Each handler method can however specify which event parameters it wants to handle and which it does not.


The parameter properties are defined in the interface definition of the EVENTS statement as follows:

Event parameters

Optional parameters do not necessarily have to be passed when the event is triggered with the RAISE EVENT statement.

In addition to the explicitly defined parameters, each instance event contains the implicit EXPORTING parameter SENDER. If a handler method calls the IMPORTING parameter SENDER, it automatically receives a reference to the triggering object from the RAISE EVENT statement. Note that the type of the reference variable is neither determined by the class of the sending object nor by the class or interface in which the event is declared. The type of the reference variable SENDER refers to exactly the class or interface cif that is listed in the definition of the handler method using the statement METHODS ... FOR EVENT OF.


Example

CLASS c1 DEFINITION.
  PUBLIC SECTION.
    EVENTS e1 EXPORTING value(p1) TYPE i.
    METHODS m1.
    DATA a1 TYPE i VALUE 7.
ENDCLASS.

CLASS c1 IMPLEMENTATION.
  METHOD m1.
    RAISE EVENT e1 EXPORTING p1 = a1.
  ENDMETHOD.
ENDCLASS.

This example shows an instance event e1 being declared in the class c1 and this event being triggered in the instance method of the same class.

Related

CLASS

PUBLIC SECTION

PROTECTED SECTION

PRIVATE SECTION

ENDCLASS

CLASS-DATA

CLASS-METHODS

CLASS-EVENTS

METHODS

EVENTS

INTERFACES

ALIASES

METHOD

ENDMETHOD

INTERFACE

ENDINTERFACE

CREATE OBJECT

CALL METHOD

RAISE EVENT

SET HANDLER

Special variants of other keywords

Additional help

Triggering and Handling Events