Friday, April 5, 2013

Static Events are Triggered by Static Methods

We can use the Static events in a class but the triggering methods must be static in this class. At the time of registration the FOR clause with object name is not required.

The following program contains a class cls in which we have two static events evnt1 and evnt2 with two static triggering methods trig1 and trig2. We also have two handler methods evnthand1 and evnthand2. Now in the implementation we displaying some text in handler methods as well as triggering methods.

Next in the start of selection we have registered the handler method with object but there is no need to use the FOR clause with object name because this registration is for static events. Finally we call the two static triggering methods as well.


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

REPORT  zsr_test.

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

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

  METHOD evnthand2.
    v_txt = 'Static Event - Handler Method Two'.
    WRITE / v_txt.
    SKIP.
  ENDMETHOD.                                                "evnthand2

  METHOD trig1.
    v_cls = 'Triggering Static Method One:'.
    WRITE / v_cls.
    RAISE EVENT evnt1.
  ENDMETHOD.                                                "trig1

  METHOD trig2.
    v_cls = 'Triggering Static Method Two:'.
    WRITE / v_cls.
    RAISE EVENT evnt2.
  ENDMETHOD.                                                "trig2
ENDCLASS.                    "cls IMPLEMENTATION

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

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


Output is as follows:

6 comments:

Yuva Thulasi said...
This comment has been removed by the author.
Yuva Thulasi said...

Hi, We can access the static events in Instance methods also.(Not only specific to static methods..
)

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/

Anonymous said...

can static event trigger any event ?

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