GoodleAds

OOPS ABAP- EVENTS



                                            EVENTS IN OOPS ABAP

EVENT

1. Events are like actions performed by the user.
2. Each event must be linked to a method for writing the corresponding business logic for the action/event raised by the user.

                                        STEPS FOR USING AN EVENT IN CLASS

        DEFINE AN EVENT.(ACTION MUST BE DEFINED).
        DEFINE THE METHOD.(WRITING THE DESIRED LOGIC AS PER REQUIREMENT)
        LINK THE EVENT AND METHOD.(AND COVERT THE METHOD INTO EVENT HANDLER METHOD)
        RASIE AN EVENT.(IN ANY METHOD IMPLEMENTATION)
        USE SET HANDLER and register event handler method to a particular instance
 in the program.

SET HANDLER

        It is the keyword which is used to register event handler method to a particular instance of class where the event is raised.

FOR ALL INSTANCE

        Sometimes we want to execute event handler methods not to a particular instance of class, but for all the instances of the class, then we use FOR ALL INSTANCES. 


                       EXAMPLE ON EVENTS

1.Go to SE24, provide class name as zcl_event

 

Steps for creating and using event in SAP classes
         DEFINE AN EVENT.
         DEFINE THE METHOD.
         LINK THE EVENT AND METHOD.
         RASIE AN EVENT.
         USE SET HANDLER.
Define an event
Go to Events tab and add a event as below.

 




Define a method
Go to Methods tab and create a method as below


Save, double click on the method and add some code.


 

Save and activate immediately.

Link event and method and convert the method into event-handler method.
Now we have to link the method to event to make the method as event handler.


Create a triggering method which will raise the event

 


Event handler method is created, now we have to trigger that event, the vent can be triggered by using below syntax.


PARAMETERS



Use set handler and register event handler method to a particular instance in the program
Now we have to register this event in our SE38 program, to register a event handler method we use below syntax.



 

Now execute the program without giving any input, the result will be



No comments:

Post a Comment