Event parameters in ABAP Objects
Page 1 of 1
Event parameters in ABAP Objects
Like methods parameters can be passed to events, events can only have input parameters;
any no of parameters can be passed to an event. As we know an event does not have any functionality, (the functionality associated with an event is carried out by the event handler method that has been assigned to it) then the question is what does the event do with the input parameters?
The parameters that are passed to the events is actually utilized by the handler methods that are registered to the events, the handler methods have the liberty to decide on the number of input parameters passed by the events .The number of input parameters for the handler methods has to be defined explicitly. However, an event handler method is not obliged to handle all of the actual parameters that are passed to it.
As well as the explicitly defined parameters, each instance event also contains the implicit EXPORTING parameter SENDER. This has the type of a reference variable referring to the class or interface in which the event is declared. If you include the SENDER parameter in the IMPORTING parameter list of the handler method, the method receives a reference to the triggering object. Remember, however, that teh type of the reference variable is not necessarily the class of the sending object. If the event is declared in a superclass of the class of the sender, or in an interface implemented by it, the type of the reference variable will refer to the superclass or interface instead. Static events do not have a SENDER parameter.
Few points to note
Event parameters
are always passed by VALUE
Must always have a type specification (TYPE, LIKE)
Can be optional (OPTIONAL, DEFAULT)
- Code:
Let’s take an example
CLASS evt_container DEFINITION.
PUBLIC SECTION.
METHODS event_trigger.
EVENTS my_event EXPORTING VALUE(PAR1) TYPE I
VALUE(PAR2) TYPE I OPTIONAL
VALUE(PAR3) TYPE I DEFAULT 3.
ENDCLASS.
CLASS class_evt_handler_method DEFINITION.
PUBLIC SECTION.
METHODS handler_for_event FOR EVENT my_event OF evt_container IMPORTING
SENDER PAR3.
ENDCLASS.
CLASS evt_container IMPLEMENTATION.
METHOD evt_trigger.
RAISE EVENT my_event EXPORTING PAR1 = 1.
ENDMETHOD.
ENDCLASS.
CLASS class_event_handler_method IMPLEMENTATION.
METHOD handler_my_event.
Write :/ ‘ this is event handler method’.
ENDMETHOD.
ENDCLASS.
*************** main program *******************************
DATA:ref_obj1 TYPE REF TO evt_container,
Ref_obj2 TYPE REF TO class_evt_handler_method.
Create object : ref_obj1,
Ref_obj2.
SET HANDLER ref_obj2->handler_for_event FOR evt_container.
Call method ref_obj1->evt_trigger. “ this will raise the event.
“event handler method will be called automatically
*************** out put ***********************************
this is event handler method
Uma_ABAP- Posts : 56
Join date : 2012-03-31
Similar topics
» Importing parameters in ABAP Objects
» Exporting parameters in ABAP Objects
» Setting the handler for the event in ABAP Objects (registering the event)
» Raising the event in ABAP Objects
» Event handler method in ABAP Objects
» Exporting parameters in ABAP Objects
» Setting the handler for the event in ABAP Objects (registering the event)
» Raising the event in ABAP Objects
» Event handler method in ABAP Objects
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|
Mon Aug 20, 2012 4:37 pm by Admin
» Difference between Type and Like
Thu Jun 07, 2012 2:40 pm by Admin
» How to handle table control fields in Module Pool program?
Wed May 09, 2012 2:41 am by govind
» Three tables inner join in SAP
Thu May 03, 2012 4:47 pm by Uma_ABAP
» Creating table type in ABAP
Sat Apr 28, 2012 9:03 pm by Uma_ABAP
» Creating user defined types and structures in ABAP
Sat Apr 28, 2012 8:55 pm by Uma_ABAP
» Creating Dynamic Internal Table and Dynamic Field catalog in SAP-ABAP
Fri Apr 27, 2012 11:00 am by Admin
» Copy Custom PF-Status from Standard program to Custom Program in ALV
Thu Apr 26, 2012 9:52 pm by Uma_ABAP
» Calculate/find number of working days between two dates in SAP
Tue Apr 24, 2012 2:06 pm by Uma_ABAP