Copyright 2024 - BV TallVision IT

Timer, clock, animations, automatic refresh, trigger - just some hype words that would help you find this article. If you want to refresh something or you want to ensure a certain task is not on the screen for too long - you will have to wonder: Business Application Relevant ? If it is: here's how

The system has a class that will help you set up a timer, which can be repeated every second (or slower, more seconds). It's class CL_GUI_TIMER that can be used to create a running clock (which will skip a second, nearly every time..). The example should explain how:

REPORT ZABAPCADABRA_TIMER_DEMO NO STANDARD PAGE HEADING.
DATA: rf_gui_timer TYPE REF TO cl_gui_timer,
      gv_clock type c length 8.

CLASS lcl_event_handler DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS: on_finished FOR EVENT finished OF cl_gui_timer
     IMPORTING sender.
ENDCLASS.

CLASS lcl_event_handler IMPLEMENTATION.

  METHOD: on_finished.
    get time. "This will reset the SY-UZEIT value
* Refresh the field
    write sy-uzeit to gv_clock using edit mask '__:__:__'.
    MODIFY LINE 1 FIELD VALUE gv_clock FROM gv_clock.
* "Schedule" the next round:
    sender->run( ).
  ENDMETHOD. "on_finished
ENDCLASS.                    "lcl_event_handler IMPLEMENTATION

START-OF-SELECTION.
* Create an instance of the Timer
  CREATE OBJECT rf_gui_timer.
* Set an event handler to capture the timer-signal
  SET HANDLER lcl_event_handler=>on_finished FOR rf_gui_timer.
* Set the interval in seconds
  rf_gui_timer->interval = 1.
* Start the times
  rf_gui_timer->run(  ).
* Produce the initial output: a clock in a report
  write: sy-uzeit to gv_clock using edit mask '__:__:__'.
  write: gv_clock.

The concept can of course be set up for many other things as well, e.g. set up your clock in an HTML container and also select other information to be displayed.

Timer demo - HTML in container

There is a standard SAP report that demonstrates the times, check out SAP_TIMER_DEMO which will throw an 'S' message repetitively. Just to carry this concept a little further, consider this example where a clock is introduced on a Dynpro in HTML format, which may look like this:

The thing to realize is this: whenever the clock is refreshed, the whole screen is refreshed. So when your end user is in the process of typing a value on a field on the screen, the whole value will be selected and the selected value will be replaced by the next character the end user would type. Ergo: don't refresh your clock too often.

Download your own copy here

The clock that is shown above is available as test-report. Note that you'll want to create dynpro 0900 as well ! Which can be done by upload into the screen painter.