- SAP ABAP - Web Dynpro
- SAP ABAP - Business Add-Ins
- SAP ABAP - User Exits
- SAP ABAP - Customer Exits
- SAP ABAP - SAPscripts
- SAP ABAP - Smart Forms
- SAP ABAP - Dialog Programming
- SAP ABAP - Report Programming
- SAP ABAP - Object Events
- SAP ABAP - Interfaces
- SAP ABAP - Encapsulation
- SAP ABAP - Polymorphism
- SAP ABAP - Inheritance
- SAP ABAP - Classes
- SAP ABAP - Objects
- SAP ABAP - Object Orientation
- SAP ABAP - Deleting Internal Tables
- SAP ABAP - Reading Internal Tables
- SAP ABAP - Copying Internal Tables
- ABAP - Populating Internal Tables
- SAP ABAP - Creating Internal Tables
- SAP ABAP - Internal Tables
- SAP ABAP - Native SQL Overview
- SAP ABAP - Open SQL Overview
- SAP ABAP - Include Programs
- SAP ABAP - Function Modules
- SAP ABAP - Macros
- SAP ABAP - Subroutines
- SAP ABAP - Modularization
- SAP ABAP - Lock Objects
- SAP ABAP - Search Help
- SAP ABAP - Views
- SAP ABAP - Structures
- SAP ABAP - Tables
- SAP ABAP - Data Elements
- SAP ABAP - Domains
- SAP ABAP - Dictionary
- SAP ABAP - Exception Handling
- SAP ABAP - Formatting Data
- SAP ABAP - Date & Time
- SAP ABAP - Strings
- SAP ABAP - Decisions
- SAP ABAP - Loop Control
- SAP ABAP - Operators
- SAP ABAP - Constants & Literals
- SAP ABAP - Variables
- SAP ABAP - Data Types
- SAP ABAP - Basic Syntax
- SAP ABAP - Screen Navigation
- SAP ABAP - Environment
- SAP ABAP - Overview
- SAP ABAP - Home
SAP ABAP Useful Resources
- SAP ABAP - Discussion
- SAP ABAP - Useful Resources
- SAP ABAP - Quick Guide
- SAP ABAP - Questions Answers
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
SAP ABAP - Object Events
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 pnk between a trigger and its handler method is actually decided dynamically at run-time.
In a normal method call, a calpng 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 handpng, 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 pnked 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 handpng 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: handpng_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→handpng_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 handpng_CUTOFF. WRITE: Handpng the CutOff . WRITE: / Event has been processed . ENDMETHOD. ENDCLASS.
The above code produces the following output −
Handpng the CutOff Event has been processedAdvertisements