Monday, December 14, 2015

OO ABAP: Events

Events

Raising events in Object Oriented Programming is a mechanism by which methods of one class can call methods of same/other classes.

5 simple steps for Raising & Handling an event

1. Define an Event in a class


2. Define a method in same class or other class




3. Link event and method to convert the method into an event handler method. Click the above 'Detail view' button for linking.


4. Create a triggering method which will raise the event



5. Use SET HANDLER and register the event handler method for a particular instance in the program. ie, we inform the system that the method will be triggered by an event.


Sample Program 

REPORT  zdil_blog_event_demo.

DATA: lo_class1 TYPE REF TO zdil_blog_class1,
      lo_class2 TYPE REF TO zdil_blog_class2.

START-OF-SELECTION.

  CREATE OBJECT lo_class1.
  CREATE OBJECT lo_class2.

  SET HANDLER lo_class2->event_handling_method FOR lo_class1.

  lo_class1->event_triggering_method( ).

Output

4 comments: