Yesterday I dreamed about a Beautiful Girl. But damn I was not lucky ,again it was SAP-ABAP which took an entry in my dreamL.
A grey haired functional came to me and was explaining that he wanted a Timer on top of a Form. It should count till 5 minutes and give a popup once 5 minutes are over.
I didn’t have any idea in my dreams, so my next day to office went into doing R&D on Timer!!!!
Tick Tock Tick Tock!!!!!!
I have created a sample report: with few lines of code:
REPORT ZT_RAJ_TIMER.
PARAMETERS : p_time type t DEFAULT 300.
at SELECTION-SCREEN OUTPUT.
p_time = P_time – 1.
And when I hit Enter Button, the Timer kept reducing one second on each hitJ.
But come on, it should do it automatically. So I need to execute Process After input (in case of module pool) or somehow i need to change the Sy-ucomm after 1 second. So that it will trigger At SELECTION-SCREEN OUTPUT and it will subtract each second passed.
Now how do I trigger that event?
I tried to search a class for it and luckily I got my match!!!!!
CL_GUI_TIMER.
This Class contains an Event called FINISHED. This event is raised whenever the time interval (which is one of the attribute of this class) is zero.
We can use below code to set the interval and start the timer:
CREATE OBJECT timer.
timer->interval = ’10’.
CALL METHOD timer->run.
The last line will trigger the timer and start counting the time interval. Here we have set the interval as 10 seconds. The FINISHED Event will be raised after 10 seconds.
(I don’t want you to raise your eyebrows thinking that
“WAIT UP to 10 Seconds” syntax can be used here. if you have started thinking that option let me tell you my friend, it is not Possible!!!!!!!) Why don’t you try out yourself?
So only thing we need to work on is capturing this FINISHED event and handling it to refresh the counter. Final code for this will look like as below:
REPORTĀ ZT_RAJ_TIMER.
PARAMETERS : p_time type t DEFAULT 300.
“Class to handle the FINSHED Event Raised by CL_GUI_TIMER
CLASS my DEFINITION.
PUBLIC SECTION.
METHODS : run_handler FOR EVENT finished OF cl_gui_timer.
ENDCLASS.
DATA timer TYPE REF TO cl_gui_timer.
DATA myh TYPE REF TO my.
CLASS my IMPLEMENTATION.
METHOD run_handler.
“This method will be called whenever the time interval which is set by us as 1 “second will be over
CALL METHOD timer->run.
call method CL_GUI_CFW=>SET_NEW_OK_CODE
EXPORTING
new_code = ‘REFR’.
ENDMETHOD.
ENDCLASS. “my IMPLEMENTATION
at SELECTION-SCREEN OUTPUT.
p_time = P_time – 1.
CREATE OBJECT timer.
CREATE OBJECT myh.
timer->interval = ‘1’.
CALL METHOD timer->run.
SET HANDLER myh->run_handler FOR ALL INSTANCES.
Few points you need to make a note as:
The code: CL_GUI_CFW=>SET_NEW_OK_CODE
Is used to trigger the AT SELECTION-SCREEN OUTPUT once again.
It’s requires as the time which we displayed to the user has to be refreshed.
So this is it!!!!!
My Dream/R&D is over J. Now its time to get back to office work.f