The SAP Toolbar can trigger events when the user either chooses a function or requests a menu. In order to process these events in your program, you must
Create a special method called a handler method, which is called when the event occurs
Register the events
With the Control Framework
As ABAP Objects events.
For further information, refer to Event Handling .
You must have instantiated the SAP Toolbar.
You should be familiar with the concept of events in ABAP Objects.
Declare an internal table with the type cntl_simple_events and a work area with the type cntl_simple_event . You need these to register the events with the Control Framework
Create a local class in which you define a method as an event handler. This contains the processing logic that will be executed when the event occurs. The event handler may be either a static method or an instance method.
Fill the events table you defined in step 1 with the events you want to register. The eventid field identifies the event. The appl_event field specifies whether the event should be an application event (PAI is triggered) or a system event (PAI is not triggered).
Call the method set_registered_events and pass to it the table you filled in step 3.
Register the event handler methods of your local class using the SET HANDLER statement.
The following example registers the event function_selected of the SAP Toolbar as a system event:
DATA: event TYPE cntl_simple_event, events TYPE cntl_simple_events. CLASS lcl_toolbar_handler DEFINITION. CLASS-METHODS: on_function_selected FOR EVENT function_selected OF cl_gui_toolbar IMPORTING fcode. ENDCLASS. CLASS lcl_toolbar_handler IMPLEMENTATION. METHOD on_function_selected. CASE fcode. WHEN <f1>. * Process function WHEN <f2>. * Process function ... ENDCASE ENDMETHOD. ENDCLASS. event-eventid = cl_gui_toolbar=>m_id_function_selected. event-appl_event = ' '. APPEND event TO events. CALL METHOD toolbar->set_registered_events EXPORTING events = events. SET HANDLER lcl_toolbar_handler=>on_function_selected FOR toolbar.