banner ads

Export Parameters in Event

Event can have export parameters which are passed to the event handler method by that event. Here the handler methods need to be declared with importing parameters. The names of those importing parameters will be similar to the exporting parameters of the event. Triggering methods can only pass the value to those parameters by using RAISE EVENT statement. Hence at the time of raise event the triggering method can pass values to the parameters. 

The following program contains a class cls in which we have data v_txt, events evnt1 with export parameters txt1 & txt2 and evnt2 with export parameters txt3 & txt4 under public section. Then we have event handler methods hand1 for event evnt1 which is importing txt1 & txt2 and hand2 for events evnt2 which is importing txt3 & txt4. We also have triggering methods trig1 and trig2. 

Now in the implementation part we have implemented the hand1 by displaying 3 text. Similarly we are implementing the hand2 method also. Then we are implementing the triggering method trig1 where we have raised event evnt1 with exporting txt1 and txt2 by passing value to them. Similarly we have implemented trig2 where we have raised event evnt2 with exporting txt3 and txt4 by passing value to them.

Finally in the start of selection we have set handler methods of hand1 and hand2 by the instance of class cls and then call methods trig1 and trig2.


*&---------------------------------------------------------------------*
*& Report  ZSR_TEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zsr_test.

*----------------------------------------------------------------------*
*       CLASS cls DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls DEFINITION.

  PUBLIC SECTION.
    DATA v_txt TYPE char50.
    EVENTS: evnt1 EXPORTING value(txt1) TYPE char50
                            value(txt2) TYPE char50,
            evnt2 EXPORTING value(txt3) TYPE char50
                            value(txt4) TYPE char50.

    METHODS: hand1 FOR EVENT evnt1 OF cls IMPORTING txt1
                                                    txt2,
             hand2 FOR EVENT evnt2 OF cls IMPORTING txt3
                                                    txt4,
             trig1,
             trig2.

ENDCLASS.                    "cls DEFINITION

*----------------------------------------------------------------------*
*       CLASS cls IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls IMPLEMENTATION.
  METHOD hand1.
    v_txt = 'First Event Handler Method'.
    WRITE: / v_txt,
           / txt1,
           / txt2.
    SKIP.
  ENDMETHOD.                                                "hand1

  METHOD hand2.
    v_txt = 'Second Event Handler Method'.
    WRITE: / v_txt,
           / txt3,
           / txt4.
    SKIP.
  ENDMETHOD.                                                "hand2

  METHOD trig1.
    v_txt = 'First Triggering Method'.
    WRITE / v_txt.
    RAISE EVENT evnt1 EXPORTING txt1 = '1st Variable of 1st Event'
                                txt2 = '2nd Variable of 1st Event'.
  ENDMETHOD.                                                "trig1

  METHOD trig2.
    v_txt = 'Second Triggering Method'.
    WRITE / v_txt.
    RAISE EVENT evnt2 EXPORTING txt3 = '1st Variable of 2nd Event'
                                txt4 = '2nd Variable of 2nd Event'.
  ENDMETHOD.                                                "trig2
ENDCLASS.                    "cls IMPLEMENTATION

START-OF-SELECTION.
  DATA obj TYPE REF TO cls.
  CREATE OBJECT obj.

  SET HANDLER: obj->hand1 FOR obj,
               obj->hand2 FOR obj.
  CALL METHOD: obj->trig1,
               obj->trig2.


The output is as following:

No comments