Simple event handling in ABAP OOPS Part 3
Hello all,
This is the 3rd part of event handling in ABAP OOPS. In my previous documents ( Simple event handling in ABAP OOPS / Simple event handling in ABAP OOPS Part 2 ), I showed about the working of global events and local event.
In first document I showed how to handle the global events and in second documents I showed how to create a local event in a local class and how to handle it internally. So, in this document I will show how to create an event globally and how to handle it.
I know it’s a basic thing to learn but it is very important to clear the basics. And event play a very helpful role in our working.
For this document the flow will be like this –
- Create a global class in SE24
- Create a method in it and an event
- Raise the event at a particular condition in our method
- Create a report in SE38
- Create a local class and a method to handle the global event
Create a class in SE24 as shown above. Inside the class create a method INPUT_CHECK which will raise the event. We will not make it static method ( it depends on your choice ). It will take the input number and check for a particular scenario, in our case the input number should be between 1 and 7. Click on ‘Parameters’ button and give the parameters.
In this method we will raise the event .
In the ‘EVENTS’ tab we will declare our event which will be triggered in our method.
Create a report in SE38. Create a local class which will contain a method and this method will be used to handle the event of our global class.
According to the code flow of our report, we the user will pass the give the value as input.
We will pass the value to the global class method Input_Check which we have created. Internally if the value is with in range it will give output message otherwise an event will be raised and that will be handled by our local class method Handle_Event which is registered as an event handler in our code by
Set Handler Keyword.
Output –
When the input value is in range
When the input value is out of range
If you have seen my previous documents, you will find it very easy to understand the working and handling of events in OOPS.
Happy Learning..!!!
And what exactly is the difference between the two docs -
Simple event handling in ABAP OOPS Part 2
Simple event handling in ABAP OOPS Part 3
Except event handling via local & global classes?
The difference I will say is that the event is created in global class while in part 2 it was all local.
This is to show that how the events are created globally like they are given in standard classes and how we can handle it.
I'm actually quite confused by the whole series... Why all this? 😕
Confused by the whole series.. , I just wrote all that to target those who are new to ABAP.
I agree that these are very basic things But it is also not necessary that everyone should know all.
While I was new in this field, I felt bit difficult to understand those concepts. That's why I wrote this series so that those who feel difficulty like I did can understand these concepts in the most easiest way.
But if u feel that it's not up to the mark then I am not having any problem. I will scrap it down.
Although we appreciate your idea to educate the beginners about basic topics, unfortunately SDN is not a tutorials forum!
While you're at the OO-event handling topic, a better post would have been for e.g., "How to handle exceptions in event handlers?"
Tbh, I don't see the point of segregating the event handling via local & global classes. What is the difference between the two? Have you somewhere highlighted it?
Thank you for appreciation sir.
You are right, i missed that difference regarding local & global class. I will try to make this document and my future blogs / documents better.
Unfortunately, the style chosen rather encourages mindless repetition and copy-pasting than actual understanding of concepts. I hope you can see this as an opportunity for improvement. Educating others is the whole another skill set.