Monday, April 8, 2013

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:

6 comments:

yektek training said...

your post is easy to understand thanks thara

Bhavya Kumar said...

Best blog.Got to learn new things.Thanks for this Blog SAP Success Factors Training in Chennai

Shruti Ramalingam said...

From My search…Creating Experts provides Best SAP Training with real time projects assistance.

Most of the modules are equipped with advance level topics which the student can learn from the basics to the advance level stage.

They also provide placement assistance in leading MNC companies across the globe according to the current requirements.

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

And these are the Best SAP training institute which provides Real Time Hands on Training…

codedion Technologies-9003085882

creating Experts-8122241286

http://thecreatingexperts.com/sap-mm-training-in-chennai/

Priya Kannan said...

SAP Success Factors Real Time Hands on Training in Chennai…

Don’t always Depend on Training Institute alone.Please aware of Best Trainers too..

http://thecreatingexperts.com/sap-successfactors-training-in-chennai/

If You need a Best Trainer in SAP Success Factors??? Then be ready for a DEMO From the Trainer MR.Karthick
CONTACT:8122241286
http://thecreatingexperts.com/sap-mm-training-in-chennai/

Both Classroom/Online Training is Available!!!!!!

gilledashivani said...

Thanks for sharing valuable information through your post. The information provided is of great use.
SAP ABAP TRAINING IN HYDERABAD

calfre services said...

hi your blog Article is very nice & thanks for sharing the informationsap hr abap online classes