Registering and Processing Events

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 .

    DATA my_control TYPE REF TO cl_gui_xyz.

    Registering Events with the Control Framework

  2. Define an internal table (type cntl_simple_events ) and a corresponding work area (type cntl_simple_event ).

    DATA events TYPE cntl_simple_events.
    DATA wa_events TYPE  cntl_simple_event.

  3. 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.

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

    Processing an Event Using an Instance Method

  5. 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.

    CLASS lcl_event_receiver DEFINITION.
    PUBLIC SECTION.
    METHODS
    Event_Handler
       FOR EVENT
    event_name OF cl_gui_xyz
       IMPORTING event_parameter
                 sender
    .
    ENDCLASS.

  6. 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

  7. 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.

  8. 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

  9. 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.

  10. 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.