Exercise 2: Registering an Application Event
Usage
So that you can respond to events, you must first register the events for the control instance and consequently on the frontend. When the control is set to its initial state, the SAPGUI filters all events.
In this exercise, you register event
DBLCLICK in the textedit control as an application event. Initially, you only want to display a text for the event triggered on the screen.Procedure
DATA events TYPE cntl_simple_events.
DATA wa_events TYPE cntl_simple_event.
Insert the following lines of code into the
IF block of the PBO module after the control is created.wa_events-eventid = cl_gui_textedit=>event_double_click.
wa_events-appl_event = 'X'.
APPEND wa_events TO events.
CALL METHOD editor->set_registered_events
EXPORTING events = events.

This method is provided by all controls. Depending on the control, there may be additional methods that you can use to register individual events.
WHEN OTHERS.
CALL METHOD CL_GUI_CFW=>DISPATCH.
Check Your Work
If you double-click in the text window of the editor, the text of text element
text-002 is displayed on the screen.Discussion
Registering event
DBLCLICK means that the frontend transfers double-clicks of the user to the backend by means of the OK code. Since you registered this event as an application event, the Control Framework processes the PAI module of the screen concerned. You use method DISPATCH to determine when the event is triggered by ABAP Objects. The runtime environment then executes method CATCH_DBLCLICK and continues processing after the DISPATCH call.
The DISPATCH call is globally valid for all control instances of the main program created.
Advantages
Disadvantages
When you use application events, you may encounter problems when you check entries using the
FIELD or CHAIN statement. If entries are not correct, the user may be forced to re-enter the data. However, in doing this, the user may trigger other events in the control. This way, events could be lost.
Using method