Thursday, April 4, 2013

Events with Handler Method in Same Class


Event handler method can be used in the same class by declaring the event and the handler method with the triggering method. Here the triggering method will raise or trigger the event in the implementation part.

The program below contains a class cls which contains data and constant in the public section. It contains events evnt1 and evnt2 here. And also it has event handler methods evnthand1 and evnthand2. It also contains triggering methods trig1 and trig2.

Now at the time of implementation we implement the event handler methods evnthand1 and evnthand2 with general statement. After that we implement the triggering of event method trig1 and trig2 with RAISE EVENT statement.

Finally in the start of selection we set handler method evnthand1 and evnthand2 by the object. Then we call triggering method trig1 and trig2. 

In the debugging mode when the program controller is at CALL METHOD: obj->trig1 then it calls the method trig1 and as the controller goes to RAISE EVENT evnt1 then it goes to event handler method evnthand1. There it follows the general statement. After finishing of that the controller comes back to the triggering method trig1 and end this method. Then it will go for the next triggering method trig2 and next steps will be similar. Here raise event will be evnt2 and event handler method is evnthand2.


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

REPORT  zsr_test.

*----------------------------------------------------------------------*
*       CLASS cls DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls DEFINITION.
  PUBLIC SECTION.
    DATA v_txt TYPE char50.
   CONSTANTS c_das TYPE char50 VALUE '--------------------------------'.
    EVENTS: evnt1, evnt2.
    METHODS: evnthand1 FOR EVENT evnt1 OF cls,
             evnthand2 FOR EVENT evnt2 OF cls,
             trig1,
             trig2.
ENDCLASS.                    "cls DEFINITION

*----------------------------------------------------------------------*
*       CLASS cls IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cls IMPLEMENTATION.
  METHOD evnthand1.
    v_txt = 'First Event Handler Method'.
    WRITE / v_txt.
    SKIP 2.
  ENDMETHOD.                                                "evnthand1

  METHOD evnthand2.
    v_txt = 'Second Event Handler Method'.
    WRITE / v_txt.
    SKIP 2.
  ENDMETHOD.                                                "evnthand2

  METHOD trig1.
    v_txt = 'First Event is being Triggered:'.
    WRITE: / v_txt,
           / c_das.
    RAISE EVENT evnt1.
  ENDMETHOD.                                                "trig1

  METHOD trig2.
    v_txt = 'Second Event is being Triggered:'.
    WRITE: / v_txt,
           / c_das.
    RAISE EVENT evnt2.
  ENDMETHOD.                                                "trig2
ENDCLASS.                    "cls IMPLEMENTATION

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

  SET HANDLER: obj->evnthand1 FOR obj,
               obj->evnthand2 FOR obj.
  CALL METHOD: obj->trig1,
               obj->trig2.


The output is following:

4 comments:

Bhavya Kumar said...

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

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!!!!!!