Events and Event HandlersLocate this document in the navigation structure

You can define events for a component controller to allow cross-controller communication. These events can then be triggered using the predefined method FIRE_<MY_EVENT>_EVT. Once the event is triggered, the corresponding event handler is automatically called in another controller by the runtime.

A usage of the component controller must be entered in the current controller to handle an event of a component controller. (The usage of the component controller within a view controller is automatically created.)

The following graphic shows an example in which a method of the component controller triggers the event MY_EVENT.

The event handler MY_HANDLER of a view controller responds to the event MY_EVENT, because this event of the component controller is assigned to this event handler. It has been assigned on the Methods tab of the view controller.

Cross-Component Events

You can use one or more events of the component controller and use them as cross-component events. Check the Interface checkbox of the Events tab of the component controller in the table. The corresponding event is passed to the component interface and can be accessed by an event handler of another component (see Cross-Component Programming).

Parameter of Events

Events can pass mandatory or optional parameters. You can enter these parameters on the Events tab of the component controller and specify the type. When you then create an event handler in a used controller and assign an event of the component controller to it, the corresponding parameters are automatically added to the signature of the event handler method.

Example:

Component Controller

An event is triggered in a method of the component controller and the created parameter is passed.

Events tab

Event

MY_EVENT

Parameter

MY_PARAMETER         type        WDY_BOOLEAN

Note WDY_BOOLEAN is an ABAP Dictionary type and has the function of a real Boolean variable.
Note The value of WDY_BOOLEAN is either 'X' for true or ' ' for false.

Methods tab:

MY_CONTROLLER_METHOD

 
method MY_COMP_CONTROLLER_METHOD .
 
WD_THIS->FIRE_MY_EVENT_EV( MY_PARAMETER = 'X' ).
 
endmethod.
 

View Controller

An event handler is created in a view controller and assigned to the event MY_EVENT. The response of the event handler is according to parameter MY_PARAMETER

Methods tab:

Method Method Type Event Controller
MY_EVENT_HANDLER Event handler MY_EVENT Component controller

MY_EVENT_HANDLER

Parameter Declaration Type Reference Type
WDEVENT Importing CL_WD_CUSTOM_EVENT
MY_PARAMETER Importing WDY_BOOLEAN
method MY_EVENT_HANDLER .
.
.
.
endmethod.

More Concepts: Passing Parameters Using an Event Object

Each event handler method is automatically known to parameter WDEVENT of the type CL_WD_CUSTOM_EVENT. The class interface CL_WD_CUSTOM_EVENT contains the attribute PARAMETERS of the type WD_EVENT_PARAMETER and several methods to read this parameter.

Instead of statically specifying a parameter for an event and automatically add this parameter to the signature of the event handler method of the event handler, you can also dynamically specify the parameter using the event object.

This means that if the parameter is not to be statically specified at design time, it can be read from the event object of the event handler method. For more information, see Dynamically Working with Parameter Mappings in the third part of the programming manual.