Entering content frame

Event Handling Locate the document in its SAP Library structure


In an application program, the user can trigger events in a custom control. Control then returns to the application program, which can react to the events.

Typical events are, for example, double-clicking and dragging and dropping.


As already mentioned in the Control Framework Architecture section, both the Automation Controller and the ABAP Objects Control Framework administer tables of control events. These tables have to be constructed by the application program. The event table at the frontend contains control instances and events. The event table at the backend also contains the ABAP handler method registered for the events.

You construct the tables using a special ABAP Objects Control Framework method ( control->set_registered_events ). When you register the event, you must specify whether the event is to be processed as a system event or as an application event.

The handler method that you defined for the event is called automatically by the system. However, you can use the method set_new_ok_code to set a new value for the OK_CODE field. This then triggers the PAI and PBO modules, and you can evaluate the contents of the OK_CODE field as normal in a PAI module.

You must set a handler method for the event in your application program using the ABAP statement SET HANDLER . You define the handler method in your program as a method of a (local) class. It is up to you whether you define the handler method as an instance method or a static method.

This graphic is explained in the accompanying text


When an event is triggered on a custom control, the Automation Controller checks whether the event is registered in its events table. If the event is not registered, the Automation Controller ignores it. If, on the other hand, it is registered, the Automation Controller generates an OK_CODE that it then passes to the ABAP Objects Control Framework.

The registered handler method for the event is then called - either directly (for a system event) or when you call the static method CL_GUI_CFW=>DISPATCH (for an application event). The handler method receives the event parameter sender . This contains the object reference of the control that triggered the event.

To process an application event, you must call the static method CL_GUI_CFW=>DISPATCH within a PAI module.


The OK_CODE of an event is "spent" after the method CL_GUI_CFW=>DISPATCH has been called. Consequently, you cannot trigger the handler method for a second time by calling the dispatch method twice.

You can find out whether the event was successfully passed to a handler method by querying the parameter RC of the method CL_GUI_CFW=>DISPATCH.

This graphic is explained in the accompanying text

Leaving content frame