Exercise 2: Registering an Application Event
Use
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
-
Declare the following variables in your main program:
-
An internal table for events that you want to register
- A structure for a line of this table:
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.
-
-
Assign the static attribute for event DBLCLICK to field eventid:
wa_events-eventid = cl_gui_textedit=>event_double_click.
-
Using field appl_event, define the event as an application event:
wa_events-appl_event = 'X'.
-
Append this line to your internal table events, and pass this table to the textedit control using method set_registered_event:
APPEND wa_events TO events. CALL METHOD editor->set_registered_events EXPORTING events = events.
-
In the PAI module, call method DISPATCH in the last query of the CASE statement:
WHEN OTHERS. CALL METHOD CL_GUI_CFW=>DISPATCH.
-
Activate and start your program.
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.