Software Development Exam  >  Software Development Notes  >  Learn and Master SAP ABAP  >  SAP ABAP - Object Events

SAP ABAP - Object Events | Learn and Master SAP ABAP - Software Development PDF Download

An event is a set of outcomes that are defined in a class to trigger the event handlers in other classes. When an event is triggered, we can call any number of event handler methods. The link between a trigger and its handler method is actually decided dynamically at run-time.
In a normal method call, a calling program determines which method of an object or a class needs to be called. As fixed handler method is not registered for every event, in case of event handling, the handler method determines the event that needs to be triggered.
An event of a class can trigger an event handler method of the same class by using the RAISE EVENT statement. For an event, the event handler method can be defined in the same or different class by using the FOR EVENT clause, as shown in the following syntax −

FOR EVENT <event_name> OF <class_name>.

Similar to the methods of a class, an event can have parameter interface but it has only output parameters. The output parameters are passed to the event handler method by the RAISE EVENT statement that receives them as input parameters. An event is linked to its handler method dynamically in a program by using the SET HANDLER statement.
When an event is triggered, appropriate event handler methods are supposed to be executed in all the handling classes.

Example

REPORT ZEVENT1. 

CLASS CL_main DEFINITION. 

PUBLIC SECTION. 

DATA: num1 TYPE I. 

METHODS: PRO IMPORTING num2 TYPE I. 

EVENTS: CUTOFF. 

ENDCLASS. 

CLASS CL_eventhandler DEFINITION. 

PUBLIC SECTION. 

METHODS: handling_CUTOFF FOR EVENT CUTOFF OF CL_main. 

ENDCLASS. 

START-OF-SELECTION. 

DATA: main1 TYPE REF TO CL_main. 

DATA: eventhandler1 TYPE REF TO CL_eventhandler. 

CREATE OBJECT main1. 

CREATE OBJECT eventhandler1. 

SET HANDLER eventhandler1→handling_CUTOFF FOR main1. 

main1→PRO( 4 ).

CLASS CL_main IMPLEMENTATION.

METHOD PRO.

num1 = num2.

IF num2 ≥ 2. 

RAISE EVENT CUTOFF.

ENDIF. 

ENDMETHOD.

ENDCLASS.

CLASS CL_eventhandler IMPLEMENTATION.

METHOD handling_CUTOFF.

WRITE: 'Handling the CutOff'. 

WRITE: / 'Event has been processed'. 

ENDMETHOD. ENDCLASS.

The above code produces the following output −

Handling the CutOff 

Event has been processed

The document SAP ABAP - Object Events | Learn and Master SAP ABAP - Software Development is a part of the Software Development Course Learn and Master SAP ABAP.
All you need of Software Development at this link: Software Development
73 videos|68 docs

Top Courses for Software Development

73 videos|68 docs
Download as PDF
Explore Courses for Software Development exam

Top Courses for Software Development

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Important questions

,

Sample Paper

,

MCQs

,

shortcuts and tricks

,

Summary

,

mock tests for examination

,

Extra Questions

,

Semester Notes

,

study material

,

SAP ABAP - Object Events | Learn and Master SAP ABAP - Software Development

,

Objective type Questions

,

video lectures

,

Free

,

Viva Questions

,

SAP ABAP - Object Events | Learn and Master SAP ABAP - Software Development

,

past year papers

,

SAP ABAP - Object Events | Learn and Master SAP ABAP - Software Development

,

practice quizzes

,

Previous Year Questions with Solutions

,

pdf

,

ppt

,

Exam

;