Registering and Processing Events
Use
The event mechanism of the Control Framework allows you to use handler methods in your programs to react to events triggered by the control (for example, a double-click).
Prerequisites
The following description has been generalized to apply to all custom controls. For more information specific to a particular control, refer to that control's documentation.
Process
-
Assume you are working with a custom control that has the ABAP wrapper cl_gui_xyz.
DATA my_control TYPE REF TO cl_gui_xyz.
Registering events in the Control Framework
-
Declare an internal table with the type cntl_simple_events and the corresponding work area (type cntl_simple_event).
DATA events TYPE cntl_simple_events. DATA wa_events TYPE cntl_simple_event.
-
Now fill the event table with the relevant events. To do this, you need the event ID (event_id field). You can find this information in the Class Browser by looking at the attributes of the class cl_gui_xyz. You must also decide whether the event is to be a system event (appl_event = ' ') or an application event (appl_event = 'X').
wa_events-eventid = event_id. wa_events-appl_event = appl_event. APPEND wa_events TO events.
-
In the next step, the event table must be sent to the frontend so that the relevant events from the frontend are forwarded to the backend.
CALL METHOD my_control->set_registered_events events = events.To react to the events of you custom control, you must now specify a handler method for it. The event handler may be either an instance method or a static method:
Processing an Event Using an Instance Method
-
Define the (local) class definition for the event handler. To do this, specify the name of the handler method (Event_Handler). You need to look at the class for the custom controlcl_gui_xyz in the Class Browser to find out the name of the event (event_name) and its parameters (event_parameter). There is also a default event parameter sender, which is passed by all events. This contains the reference to the control that triggered the event.
CLASS lcl_event_receiver DEFINITION. PUBLIC SECTION. METHODS Event_Handler FOR EVENT event_name OF cl_gui_xyz IMPORTING event_parameter sender. ENDCLASS. -
Register the handler methods with the ABAP Objects Control Framework for the events.
DATA event_receiver TYPE REF TO lcl_event_receiver. CREATE OBJECT event_receiver. SET HANDLER event_receiver->Event_Handler FOR my_control.
Processing an Event Using a Static Method
-
Define the (local) class definition for the event handler. To do this, specify the name of the handler method (Event_Handler). You need to look at the class for the custom control cl_gui_xyz in the Class Browser to find out the name of the event (event_name) and its parameters (event_parameter).
CLASS lcl_event_receiver DEFINITION. PUBLIC SECTION. CLASS-METHODS Event_Handler FOR EVENT event_name OF cl_gui_xyz IMPORTING event_parameter sender. ENDCLASS. -
Register the handler methods with the ABAP Objects Control Framework for the events.
SET HANDLER lcl_event_receiver=>Event_Handler FOR my_control.
Processing Control Events
-
You define how you want the system to react to an event in the implementation of the handler method.
CLASS lcl_event_receiver IMPLEMENTATION. METHOD Event_Handler. * Event processing ENDMETHOD ENDCLASS.
-
If you registered your event as an application event, you need to process it using the method CL_GUI_CFW=>DISPATCH. For further information, refer to Event Handling.