Entering content frame

Process documentationRegistering and Processing Events Locate the document in its SAP Library structure

Purpose

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 Flow

  1. Assume you are working with a custom control that has the ABAP wrapper cl_gui_xyz .
  2. DATA my_control TYPE REF TO cl_gui_xyz.

    Registering Events with the Control Framework

  3. Define an internal table (type cntl_simple_events ) and a corresponding work area (type cntl_simple_event ).
  4. DATA events TYPE cntl_simple_events.
    DATA wa_events TYPE  cntl_simple_event.

  5. 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' ).
  6. wa_events-eventid = event_id .
    wa_events-appl_event =
    appl_event .
    APPEND wa_events TO events.

  7. You must now send the event table to the frontend so that it knows which events it has to direct to the backend.
  8. 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. This can be either an instance method or a static method.

    Processing an Event Using an Instance Method

  9. 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 ). 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.
  10. CLASS lcl_event_receiver DEFINITION.
    PUBLIC SECTION.
    METHODS
    Event_Handler
       FOR EVENT
    event_name OF cl_gui_xyz
       IMPORTING event_parameter
                 sender
    .
    ENDCLASS.

  11. Register the handler methods with the ABAP Objects Control Framework for the events.
  12. 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

  13. 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 ).
  14. CLASS lcl_event_receiver DEFINITION.
    PUBLIC SECTION.
    CLASS-METHODS
    Event_Handler
            FOR EVENT
    event_name OF cl_gui_xyz
            IMPORTING event_parameter
                      sender
    .
    ENDCLASS.

  15. Register the handler methods with the ABAP Objects Control Framework for the events.
  16. SET HANDLER lcl_event_receiver=>Event_Handler
                FOR my_control.

    Processing Control Events

  17. You define how you want the system to react to an event in the implementation of the handler method.
  18. CLASS lcl_event_receiver IMPLEMENTATION.
    METHOD Event_Handler.
    * Event processing
    ENDMETHOD
    ENDCLASS.

  19. 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 Structure link Event Handling.
Leaving content frame