sapdev logo background
sapdev logo sapdev logo
Comments

ABAP METHODS EVENT HANDLER Statement syntax, information and example SAP source code



Return to Statement index



METHODS - FOR EVENT

Short Reference

ABAP Syntax_4 METHODS meth [ABSTRACT|FINAL]
FOR EVENT evt OF {class|intf}
[IMPORTING p1 p2 ... [sender]].

ABAP_ADDITIONS:
1 ... IMPORTING p1 p2 ... [sender]
2 ... ABSTRACT
3 ... FINAL

What does it do? This statement declares the instance method meth as an event handler for the event
evt of class class or interface intf . For class and intf , you can specify all classes and interfaces which are visible in this position and which contain an event evt as a component that is visible here.
The visibility section of the event handler cannot be more general than the visibility section of the event. Otherwise properties of the method would be defined in a visibility section more restricted than the method itself.
If the event evt is an instance event, the event handler
meth can handle it for all objects whose classes match class or that are subclasses of class or which implement the interface intf directly or by using a superclass. If the event is a static event , the event handler meth
can handle it for the class class and its subclasses or for all classes that implement the interface intf .

Latest notes: To ensure that an event handler handles a triggered event, it must be registered with the statement SET HANDLER .

In event handlers, no class-based exceptions can be declared using
RAISING . See Class-Based Exceptions in Event Handlers .

When you declare event handlers for static events, remember that these events are generally triggered in static methods as well. In a method of this type, the class in which the method is declared is always the trigger, and not the subclass in which the method was called (or called using the name of the subclass).

ABAP_ADDITION_1 ... IMPORTING p1 p2 ... [sender]

What does it do? The addition IMPORTING defines the input parameters of the event handler. For p , you can specify only those names of formal parameters that are defined as output parameters of the event by using the addition EXPORTING of the statement EVENTS or
CLASS-EVENTS . This is done in the declaration of the event evt
in the class class or in the interface intf . The additions TYPE or LIKE and OPTIONAL or DEFAULT
are not possible. The typing of the input parameters, whether they are optional, and any replacement parameters are all defined in the declaration of the event. Not all output parameters of the event need to be specified.
If evt is an instance event, a formal parameter called
sender can be defined as an input parameter of an event handler, in addition to the explicitly defined output parameters of the event. The formal parameter sender is an implicit output parameter of every instance event. It is fully typed as a reference variable, which itself has the class class or the interface intf as a static type, as specified in the declaration of the event handler after
EVENT evt OF . If the event handler is called by an instance event, a reference to the triggering object is passed to it in sender .
Latest notes: Each event handler determines the type of its formal parameter sender .

Example ABAP Coding The class picture contains an event handler
handle_double_click for the instance event picture_dblclick of the global class cl_gui_picture . The event handler inherits two explicit output parameters of the event and the implicit parameter sender as input parameters.
CLASS picture DEFINITION.
PUBLIC SECTION.
METHODS handle_double_click
FOR EVENT picture_dblclick OF cl_gui_picture
IMPORTING mouse_pos_x mouse_pos_y sender.
ENDCLASS.

CLASS picture IMPLEMENTATION.
METHOD handle_double_click.
...
ENDMETHOD.
ENDCLASS.

ABAP_ADDITION_2 ... ABSTRACT

ABAP_ADDITION_3 ... FINAL

What does it do? Using the additions ABSTRACT and FINAL , event handlers can either be made abstract or final just like general methods .
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved




METHODS_CONSTRUCTOR
METHODS_FUNCTIONAL




comments powered by Disqus