Show TOC

Process documentationRegistering and Processing Events Locate this document in the navigation structure

 

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

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

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

  3. You must now send the event table to the frontend so that it knows which events it has to direct to the backend.

    Syntax Syntax

    1. CALL METHOD my_control->set_registered_events
      	events = events.
    End of the code.

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

    Syntax Syntax

    1. CLASS lcl_event_receiver DEFINITION.
      PUBLIC SECTION.
      METHODS Event_Handler
      	FOR EVENT event_name OF cl_gui_xyz
      	IMPORTING event_parameter sender.
      ENDCLASS.
    End of the code.
  2. Register the handler methods with the ABAP Objects Control Framework for the events.

    Syntax Syntax

    1. DATA event_receiver TYPE REF TO lcl_event_receiver.
      CREATE OBJECT event_receiver.
      SET HANDLER event_receiver->Event_Handler
      	FOR my_control.
    End of the code.
Processing an Event Using a Static Method
  1. 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).

    Syntax Syntax

    1. CLASS lcl_event_receiver DEFINITION.
      PUBLIC SECTION.
      CLASS-METHODS Event_Handler
      	FOR EVENT event_name OF cl_gui_xyz
      	IMPORTING event_parameter sender.
      ENDCLASS.
    End of the code.
  2. Register the handler methods with the ABAP Objects Control Framework for the events.

    Syntax Syntax

    1. SET HANDLER lcl_event_receiver=>Event_Handler
      	FOR my_control.
    End of the code.
Processing Control Events
  1. You define how you want the system to react to an event in the implementation of the handler method.

    Syntax Syntax

    1. CLASS lcl_event_receiver IMPLEMENTATION.
      METHOD Event_Handler.
      * Event processing
      ENDMETHOD
      ENDCLASS.
    End of the code.
  2. 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.