2013 Oct 21 10:13 PM
Hello Guyz,
I am developing online examination system in ABAP using screen painter for taking online exams. At main screen i want to show decrementing timer for time duration of test whenever i click start test button. for e.g if duration of test is 20 minutes then it show timer starting from 20 minutes and it should decrement it by 1 second & whenever it reaches 0 , it should exit the whole program.
I have developed the simple executable program to decrease the timer but i do not know how to use it screens. Please help me attaching timer to screen.
Here is sample code which i have created for decrementing timer.
PARAMETERS : p_time type t DEFAULT 1200.
*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.
CALL METHOD timer->run.
call method CL_GUI_CFW=>SET_NEW_OK_CODE
EXPORTING
new_code = 'OK_CODE'.
ENDMETHOD.
ENDCLASS.
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.
plelase help guyz , i need it urgently.
Thanks & regards ,
kapil.
2013 Oct 22 4:03 PM
Usually I use some code for auto-refresh looking like
* TOP include
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
on_finished FOR EVENT finished OF cl_gui_timer.
* IMPORTING sender.
PRIVATE SECTION.
ENDCLASS. "lcl_event_receiver DEFINITION
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD: on_finished.
* CASE sender.
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = 'CLOCK'.
* ENDCASE.
ENDMETHOD. " on_finished
ENDCLASS. "lcl_event_receiver IMPLEMENTATION
DATA: go_alarm TYPE REF TO lcl_event_receiver,
go_clock TYPE REF TO cl_gui_timer.
* PBO module of screen dynpro
IF go_clock IS INITIAL.
CREATE OBJECT: go_clock.
ENDIF.
IF go_alarm IS INITIAL.
CREATE OBJECT: go_alarm.
SET HANDLER go_alarm->on_finished FOR go_clock.
ENDIF.
go_clock->interval = 1.
CALL METHOD go_clock->run.You should not decrement time in the event, as user can trigger PAI/PBO cycles too, so better store start time before first screen with a GET RUN TIME, and another statement in PBO to get curret time and perform a subtraction.
Regards,
Raymond
Usually I use some code for auto-refresh looking like
* TOP include
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
on_finished FOR EVENT finished OF cl_gui_timer.
* IMPORTING sender.
PRIVATE SECTION.
ENDCLASS. "lcl_event_receiver DEFINITION
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD: on_finished.
* CASE sender.
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = 'CLOCK'.
* ENDCASE.
ENDMETHOD. " on_finished
ENDCLASS. "lcl_event_receiver IMPLEMENTATION
DATA: go_alarm TYPE REF TO lcl_event_receiver,
go_clock TYPE REF TO cl_gui_timer.
* PBO module of screen dynpro
IF go_clock IS INITIAL.
CREATE OBJECT: go_clock.
ENDIF.
IF go_alarm IS INITIAL.
CREATE OBJECT: go_alarm.
SET HANDLER go_alarm->on_finished FOR go_clock.
ENDIF.
go_clock->interval = 1.
CALL METHOD go_clock->run.You should not decrement time in the event, as user can trigger PAI/PBO cycles too, so better store start time before first screen with a GET RUN TIME, and another statement in PBO to get curret time and perform a subtraction.
Regards,
Raymond
2013 Oct 21 10:28 PM
Good question, I'm also interested to know. Is data binding like that even possible via SAPGUI?
2013 Oct 22 12:19 AM
Timer can be decremented on PBO, and screen can show the timer value in read-only mode.
Screen elements are:
Screen flow logic PBO has MODULE status_0100.
Here is the code snippet.
DATA p_time TYPE t VALUE 10.
*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. "my DEFINITION
DATA timer TYPE REF TO cl_gui_timer.
DATA myh TYPE REF TO my.
*----------------------------------------------------------------------*
* CLASS my IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS my IMPLEMENTATION.
METHOD run_handler.
CHECK p_time IS NOT INITIAL.
CALL METHOD timer->run.
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = 'OK_CODE'.
ENDMETHOD. "run_handler
ENDCLASS. "my IMPLEMENTATION
*at SELECTION-SCREEN OUTPUT.
*p_time = P_time - 1.
START-OF-SELECTION.
CREATE OBJECT timer.
CREATE OBJECT myh.
timer->interval = '1'.
CALL METHOD timer->run.
SET HANDLER myh->run_handler FOR ALL INSTANCES.
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
* SET PF-STATUS 'xxxxxxxx'.
* SET TITLEBAR 'xxx'.
p_time = p_time - 1.
ENDMODULE. " STATUS_0100 OUTPUT
Note: Your timer does not stop when timer reaches zero. I have added an exit condition in method implementation.
2013 Oct 22 4:42 AM
hello Manish i have implement ur code. but its not working.please help me.. ur code seems to be fine but m not able to detect where the error is. its not showing any error while activation. still its not showing any progress.
Please help me out ur help will be aapreciated.
thanks & regards,
kapil
2013 Oct 22 5:29 AM
The type of p_time variable is t in program, and when i created p_time I/O field in screen, its default type was char. It didn't work initially, and started working when i manually changed screen field type to TIMS. Maybe this is the issue at your end.
If not, I would like you to post code, screen flow logic and screenshot of screen elements.
2013 Oct 22 1:54 PM
Yes Manish , issue was exactly as u are saying.. i detected it on my own but wasn't able to post the result. But one more thing it showing the clock on I/O filed but its not decrementing automatically . Its showing only 9 i.e only one decrementing value.please put some light on this.
Thanks & Regards
kapil
2013 Oct 22 2:12 PM
Could you paste the code and screen related screenshots?
It would be easier that way to pinpoint the issue. Same code is working for me.
2013 Oct 22 2:40 PM
Manish , I guess ur code is ok. Its displaying timer in I/O filed but its not decrementing automatically , its decrementing whenever it click push button START. Whether it should decrement automatically by 1s. or atleast whenever i click the push button it should show the current state of time.
For e.g suppose i executes my program , it should start decrementing time on screen or if its cant happen it should show current status after push button. i.e how much time is left after clicking button.
Here is code & screen shot
DATA p_time TYPE t VALUE 10.
*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. "my DEFINITION
DATA timer TYPE REF TO cl_gui_timer.
DATA myh TYPE REF TO my.
*----------------------------------------------------------------------*
* CLASS my IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS my IMPLEMENTATION.
METHOD run_handler.
CHECK P_Time IS NOT INITIAL.
CALL METHOD timer->run.
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = 'save_code'.
ENDMETHOD. "run_handler
ENDCLASS. "my IMPLEMENTATION
*at SELECTION-SCREEN OUTPUT.
*p_time = P_time - 1.
START-OF-SELECTION.
CREATE OBJECT timer.
CREATE OBJECT myh.
timer->interval = '1'.
CALL METHOD timer->run.
SET HANDLER myh->run_handler FOR ALL INSTANCES.
CALL SCREEN 3000.
MODULE STATUS_3000 OUTPUT.
SET PF-STATUS 'STATUS'.
* SET TITLEBAR 'xxx'.
p_time = p_time - 1.
case p_time.
when 0.
leave PROGRAM.
ENDCASE.
ENDMODULE. " STATUS_3000 OUTPUT
screen shots
After Ist execution , it shows only one decremented timr i.e 9sec & dont decrement at all.
Now its got decrement whenever i clicks start button otherwise its keep still
2013 Oct 22 3:18 PM
I believe you have not uncommented the PBO code in screen flow logic.
My Screen flow logic is:
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
*
PROCESS AFTER INPUT.
* MODULE USER_COMMAND_0100.
Yours would probably be:
PROCESS BEFORE OUTPUT.
* MODULE STATUS_3000.
*
PROCESS AFTER INPUT.
* MODULE USER_COMMAND_3000.
So, your screen gets called, timer get triggered every 1 second, Module Status_3000 is present in code, but not really linked to screen 3000 flow logic. As a result, value does not get decremented.
Try double clicking on module and see if it takes your to screen.
Try double clicking on module call in screen flow logic and see if it navigated to correct module code.
Correct me if I am wrong.
2013 Oct 22 3:40 PM
2013 Oct 22 4:02 PM
Well same code is working for me. The counter is decrementing, and screen is updating every second automatically.
My last suggestion would be to paste the code in fresh program, create screen by double clicking, add elements like screenshot, uncomment PBO module and double click to create, and activate.
2013 Oct 22 4:28 PM
Ok i will try to do the same but i guess problem is that decrementing is associated with 'OK_CODE' that why its decrement only when i clicks any button is clicked as shown in code.
CLASS my IMPLEMENTATION.
METHOD run_handler.
CHECK p_time IS NOT INITIAL.
CALL METHOD timer->run.
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = 'OK_CODE'.
ENDMETHOD. "run_handler
ENDCLASS. "my IMPLEMENTATION
so , whats ur take on this , is the way am thinking is correct. please help me if u have any knowledge on this i have to submit this project by tommorrow only.
2013 Oct 22 4:31 PM
one more thing i want to convey that i want timer to be start when i click on start button not by default calling of screen.
2013 Oct 22 3:10 AM
Hi Kapil,
Try with changing the
new_code = 'OK_CODE'. to new_code = ‘REFR’.
Check the below link for more info.
http://sapignite.com/how-to-make-a-timer-in-sap-abap/
Regards,
Rajesh
2013 Oct 22 4:03 PM
Usually I use some code for auto-refresh looking like
* TOP include
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
on_finished FOR EVENT finished OF cl_gui_timer.
* IMPORTING sender.
PRIVATE SECTION.
ENDCLASS. "lcl_event_receiver DEFINITION
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD: on_finished.
* CASE sender.
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = 'CLOCK'.
* ENDCASE.
ENDMETHOD. " on_finished
ENDCLASS. "lcl_event_receiver IMPLEMENTATION
DATA: go_alarm TYPE REF TO lcl_event_receiver,
go_clock TYPE REF TO cl_gui_timer.
* PBO module of screen dynpro
IF go_clock IS INITIAL.
CREATE OBJECT: go_clock.
ENDIF.
IF go_alarm IS INITIAL.
CREATE OBJECT: go_alarm.
SET HANDLER go_alarm->on_finished FOR go_clock.
ENDIF.
go_clock->interval = 1.
CALL METHOD go_clock->run.You should not decrement time in the event, as user can trigger PAI/PBO cycles too, so better store start time before first screen with a GET RUN TIME, and another statement in PBO to get curret time and perform a subtraction.
Regards,
Raymond
2013 Oct 22 4:40 PM
Hello Raymond ,
I didn't understand ur answer as am new to classes. Can u elaborate with reference to my code and guide where to use which code. Ur help will be appreciated as i have to submit the project by tomorrow only.
2013 Oct 22 5:42 PM
Thanks Manish & Raymond , you guyz helped me a lot.
With the help of ur code raymond my timer is auto decrementing.
Thanks a ton. You guyz just saved me.
Thanks & Regards,
kapil
2015 Jan 08 4:32 PM
Hello Kapil,
Even I'm working on developing online exam in ABAP screen painter.
Could you please share me the abap code.
Thanks.
2023 Jun 30 2:07 AM
*&---------------------------------------------------------------------*
*& Report Y_TIMERSCREEN 0100

| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |