Start of Content Area

Background documentationLesson 2: Event Handling  Locate the document in its SAP Library structure

Task

You previously added a function to your editor that allows you to load the contents of an internal table into the text window. Now, you implement a function that converts a text line into a comment line when you double-click the line.

Overview: Objectives

In this lesson, you learn how to:

Basics

The event handling of controls is based on that of ABAP Objects. Generally, you use events in ABAP Objects to inform objects that a specific state has occurred.

Example

For example, an object may use an event to indicate that:

The following graphic shows how you can use events in your programs:

This graphic is explained in the accompanying text

An event is a component of a class or an interface. Within the methods of the class, you can trigger defined events using RAISE EVENT .

To be able to respond to an event, you must define a method and link it to the event. It is then sufficient to trigger the event in order to handle it. These methods are also called event handler methods. By defining a second class, you can separate these methods from the object that triggers the event. This way, you can also group together handler methods of a specific type in a class.

Note

In the above graphic, the event handler method is defined as an instance method. In this case, you must first instantiate an object of the class to enable the system to call the method. You can also define the method as a static method of the class. In this case, you do not need to generate the handler object.

Once the objects have been instantiated, you use the SET HANDLER statement to link the event handling method to the object in which the event is defined. The runtime environment then ensures that the method implemented is automatically called at this event.

For more information on event handling, see ABAP Objects.

To Continue

Lesson 3: Flush Optimization describes how you use flush calls and how methods are buffered before they are transferred to the frontend.