0% found this document useful (0 votes)
5 views8 pages

Sap Ooabap

The document explains the use of events in Object-Oriented Programming (OOP) with ABAP, detailing the steps to create an event handler and trigger events between classes. It outlines the process of creating a program that prompts users for input and handles cases where no input is provided. The document includes a code example demonstrating the implementation of event handling in ABAP.

Uploaded by

bbdey1953
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views8 pages

Sap Ooabap

The document explains the use of events in Object-Oriented Programming (OOP) with ABAP, detailing the steps to create an event handler and trigger events between classes. It outlines the process of creating a program that prompts users for input and handles cases where no input is provided. The document includes a code example demonstrating the implementation of event handling in ABAP.

Uploaded by

bbdey1953
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

🔟

Events in OOPS ABAP


Using Events in Object Oriented Programing, Method of one class can call
method of another class.

For events we will have to raise the event and then we will handle the event.

Steps For Event Handler :-


1. Triggering Method :- A method which will raise the event OR a method which
will be raising the event will be called as triggering method.

2. Event Handler Method :- A method which will handle the event.

3. Register the event handler method using SET Handler statement.

Syntax :-
SET HANDLER lo_object1→ EVENT_HANDLER for lo_object2.

where lo_object1 = Class Object in which event handler method is defined.

EVENT_HANDLER = event handler method name.

lo_object2 = Class Object in which triggering method is defined.

let’s create a program to understand it.

Requirement :-
We will create a executable program where we will pass a input parameter for
user.

And if user do not pass any input, We will give a message on the Selection
screen to pass the input to the parameter.

Events in OOPS ABAP 1


And we will achieve this requirement using events.

Solution :-
Step 1 :- Go to ABAP Editor ( SE38 ) and create a executable program.

Step 2 :- Now we need to create few fields from VBAK as a local variable in
which we will get the details on the basis of Sales document number provided
by user as a input.

Events in OOPS ABAP 2


Step 3 :- Create a class with one method and one event.

Step 4 :- Now we need to implement the method and raise the event of the
above class.

Step 5 :- Now we will create a class which will handle the event of the Class1
which we have created above.

Step 6 :- In Start of selection create the object of both classes.

Events in OOPS ABAP 3


Step 7 :- Handle the event.

Step 8 :- call method display and use the write statement to display the output.

Code :-
*&--------------------------------------------------------------
*& Report ZAR_OOPS_EVENTS
*&--------------------------------------------------------------
*&
*&--------------------------------------------------------------
REPORT zar_oops_events.

Events in OOPS ABAP 4


DATA : perdat TYPE erdat,
perzet TYPE erzet,
pernam TYPE ernam,
pvbtyp TYPE vbtypl.

PARAMETERS : pvbeln TYPE vbeln_va.

CLASS class1 DEFINITION.


PUBLIC SECTION.
METHODS display IMPORTING pvbeln TYPE vbeln_va
EXPORTING perdat TYPE erdat
perzet TYPE erzet
pernam TYPE ernam
pvbtyp TYPE vbtypl.
EVENTS : no_input.
ENDCLASS.

CLASS CLASS1 IMPLEMENTATION.


METHOD DISPLAY.
if pvbeln is INITIAL.
raise event no_input.
else.
Select single erdat erzet ernam vbtyp
from vbak into ( perdat, perzet, pernam, pvbtyp ).

endif.
ENDMETHOD.
ENDCLASS.

CLASS CLASS2 DEFINITION.


PUBLIC SECTION.
METHODS MESSAGE FOR EVENT no_input of class1.

ENDCLASS.

Events in OOPS ABAP 5


class class2 IMPLEMENTATION.
method message.
WRITE : 'Please enter Sales Document Number'.

ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
DATA(lo_obj1) = new CLASS1( ).
DATA(lo_obj2) = new CLASS2( ).

SET HANDLER lo_obj2->message for lo_obj1.

lo_obj1->display( EXPORTING pvbeln = pvbeln


IMPORTING perdat = perdat
perzet = perzet
pernam = pernam
pvbtyp = pvbtyp ).

write :/ perdat, perzet, pernam, pvbtyp.

*&--------------------------------------------------------------
*&End Of Program
*&--------------------------------------------------------------

Execute the program :-

Events in OOPS ABAP 6


Press F8 without giving any input.

Now go back and enter some value of Sales Document number.

Press F8.

Events in OOPS ABAP 7


Events in OOPS ABAP 8

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy