By triggering an event, an object or a class announces a change of state, or that a certain state has been achieved.In the above example, the airplane class triggers the event ‘touched_down’. Other classes subscribe to this event and process it. The air-traffic controller marks the plane as landed on the list, the pilot breathes a sigh of relief and the passenger, Mr. Miller, applauds.

The events discussed here are not ABAP events such as INITIALIZATION,START-OF-SELECTION, and so on.Events link objects or classes more loosely than direct method calls do. Method calls establish precisely when and in which statement sequence the method is called. However, with events, the reaction of the object to the event is determined by the triggering of the event itself.

Events are most often used in GUI implementations.Other external object models, such as COM, ActiveX Controls etc, also provide events.At the moment of implementation, a class defines its ­ instance events (using the statement EVENTS) and ­ static events (using the statement CLASS-EVENTS)

Classes or their instances that receive a message when an event is triggered at runtime and want to react to this event define event handler methods.


These classes or their instances register themselves at runtime to one or more Events.

Statement : SET HANDLER FOR . (for instance events)
SET HANDLER . (for static events).

A class or an instance can trigger an event at runtime using the statement RAISE EVENT.

Both instance and static events can be triggered in instance methods.

Only static events can be triggered in static methods.

Events can only have EXPORTING parameters which must be passed by value.

Triggering an event using the statement RAISE EVENT has the following effect:
­ the program flow is interrupted at that point
­ the event handler methods registered to this event are called and processed
­ once all event handler methods have been executed, the program flow starts again.

If an event handler method in turn triggers an event, then the program flow is again interrupted and all event handler methods are executed (nesting).

Events are registered using the command SET HANDLER. Registration is only active at program runtime. Events cannot be persistent.

You want to register an object to an event belonging to another object. The SET HANDLER... statement enters the registration in that object’s list. All handlers for one event are entered in this list.

When the event is triggered, the list shows which event handler methods need to be called.

Event handler methods are triggered by events (RAISE EVENT), although they can also be called like normal methods (CALL METHOD).

The interface of the event handler method consists solely of IMPORTING parameters. Only parameters from the definition of the corresponding event (event interface) can be used.
An event interface only has EXPORTING parameters and is defined using the EVENTS statement in the declaration of the event.

The parameters are typed in the event definition and the typing is passed to the event handler method, that is, the interface parameters of the event handler method cannot be typed in the definition of the event handler method.

In addition to the explicitly defined event interface parameters, the implicit parameter SENDER can also be listed as an IMPORTING parameter for instance events. This passes on a reference to the object that triggered the event.

When an event is triggered, only those event handler methods that have registered themselves using SET HANDLER by this point at runtime are executed.

You can register an event using Activation ‘X‘ (see above example), and deregister it using Activation ‘SPACE‘ (see next slide). You can also register and deregister using a variable , which is filled with one of these two values. If you do not specify a value for Activation, then the event is registered (default setting).

You can register several methods in one SET-HANDLER statement:




Every object that has defined events has an internal table: the handler table. All objects that have registered for events are entered in this table together with their event handler methods.

Objects that have registered themselves for an event that is still “live” also remain “live”. The methods of these objects are called when the event is triggered, even if they can no longer be reached using main memory references.

If several objects have registered themselves for an event, then the sequence in which the event handler methods are called is not defined, that is, there is no guaranteed algorithm for the sequence in which the event handler methods are called.

If a new event handler is registered in an event handler method for an event that has just been triggered, then this event handler is added to the end of the sequence and is then also executed when its turn comes.

If an existing event handler is deregistered in an event handler method, then this handler is deleted from the event handler method sequence.

Events are also subject to the visibility concept and can therefore be either public, protected or private. Visibility establishes authorization for event handling
­ all users
­ only users within that class or its subclasses
­ only users in that class.

Event handler methods also have visibility characteristics. Event handler methods, however, can only have the same visibility or more restricted visibility than the events they refer to.

The visibility of event handler methods establishes authorization for SET-HANDLER statements: SET HANDLER statements can be made

in that class and its subclasses
only in that class




No comments :

Post a Comment