Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Declarative statemnts →  Classes and Interfaces →  ABAP Objects - Overview 

Events

Events are generally characterized by occurring at a particular point in time. When an event is triggered, other actions can be executed as a consequence. Examples of when events can be triggered include changes in the status of an object, such as the cancellation of a posting or the generation of a new account (object). Other interested objects are informed of these situations by events.

In contrast to other object-oriented programming languages, the event concept in ABAP Objects is an integral component of the language itself. Using the statement EVENTS, objects can contain declared events as a part of their interface, and trigger them using RAISE EVENT. Using the addition FOR EVENT of the statement METHODS, other objects can also contain event handlers and therefore are able to react appropriately to an event. An object that triggers an event does not make any assumptions about which, and how many objects will handle the event, and if so, how this will be done. This means that the event concept represents a separation between the caller and the handler that must be clearly differentiated from a concept that uses callback routines, in which only one object reacts in a predefined manner. During a normal method call, a method can be called by any number of users, while the triggering of an event can lead to any number of event handlers being called. The link between the trigger and the handler is made at runtime. In a normal method call, the caller clearly defines which method he/she wants to call, and the corresponding method must exist. In events, the handler determines to which events it will react, and a handler does not have to be registered for every event.

An event handler in an object statically determines which events of which classes the object can handle. Before an object can react to relevant events, its event handlers must be dynamically registered for the events of other objects using the statement SET HANDLER. One object can be registered for the events of several other objects at the same time. This registration can be revoked at any time by users of the object or by the object itself. All registered event handlers are currently executed synchronously. This means that they are executed after the statement RAISE EVENT and before the next statement. This also applies for events that are triggered during the handling of other events.

If an object triggers an event during the execution of a method, each appropriate registered event handler method is called, and the triggering method can transfer parameters. If several event handlers are registered for one event, these are called in the sequence in which they were registered.

Event handlers can also be called directly. There can be two reasons for this: Either you want an event handler to handle an event without being registered, or to simulate the triggering of an event.

Events can have output parameters, which are defined in the same way as those of methods. An event handler can transfer these same output parameters as input parameters, whereby the transfer is always a value. In addition, there is always an implicit parameter called sender that contains a reference to the triggering object, via which the event handler gains access to this object.

Other versions: 7.31 | 7.40 | 7.54