Event Handling
Use
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.
Integration
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.
-
System events are triggered before any automatic field checks (for example, required fields) have taken place on the screen, and before any field transport. The PAI and PBO events are not triggered. Consequently, you cannot access any values that the user has just changed on the screen. Even after the event there is no field transport to the screen. For this reason, values that you changed in event handling are not updated on the screen.
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. You can evaluate the contents of the OK_CODE field as normal in a PAI module
-
Application events are triggered automatically at the end of the PAI event. Consequently, all fields were checked and transported. If you want the event handler method to be called at a particular point during PAI processing, you must trigger the event handler using the static method CL_GUI_CFW=>DISPATCH.
You must set a handler method for the event in your application program using the ABAP statement SET HANDLER. The handler method must be created in your application program as a method of a (local) class. You can create the handler method as an instance method or as a static method.
Features
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, which is passed 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.