Skip to Content
Author's profile photo François Henrotte

Refresh the display using class CL_GUI_TIMER

There are a lot of new tools with a nice User Interface, but the “good old” ABAP can also be used for developing overviews and monitors. In the beginning of ABAP it was very difficult to refresh the display at a given interval, but since the OO turn (early 2000’s) we have an easy way to do it, namely the class CL_GUI_TIMER.

You have to create an instance of this class, and initialize it by telling which interval you want.

Then you just have to call the method RUN.

DATA: o_timer TYPE REF TO cl_gui_timer,
      o_event TYPE REF TO lcl_event.
IF o_timer IS INITIAL.

*   create timer
    CREATE OBJECT o_timer.

*   event handler
    CREATE OBJECT o_event.
    SET HANDLER o_event->m_timer_finished FOR o_timer.

*   set interval in seconds
    MOVE 60 TO o_timer->interval.


o_timer->run( ).

Of course, you need a listener for the event M_TIMER_FINISHED.

Let’s look at the way to define and implement the listener.

The method must be defined according to the event to be listened.



    METHODS m_timer_finished FOR EVENT finished OF cl_gui_timer.

ENDCLASS.                    "lcl_event DEFINITION

In the implementation, you have to refresh the data to be displayed but also to make understand to the system that you want to update the current display. As ABAP is an event-driven language, you will have to generate an OK-code in the current screen. This is done by calling standard function module SAPGUI_SET_FUNCTIONCODE. If the data is displayed in ALV grid you should call directly the method to refresh the display.


  METHOD m_timer_finished.
*   refresh selection
    get_data_somewhere( ).
*   trigger PAI to force refresh of overview
        OTHERS = 0.
  ENDMETHOD.                    "handle_finished

ENDCLASS.                    "lcl_event IMPLEMENTATION

Note: the timer will continue running until you call the method CANCEL.


This technic is pretty straight-forward. The only constraint is that, as all GUI objects, it cannot be used in the background. So you should always verify that the program is not used in background before you instantiate a timer object.

Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Shai Sinai
      Shai Sinai

      Useful guide.

      Please take into account there is one significant drawback in class CL_GUI_TIMER (as described in Note 2679117 - CL_GUI_TIMER: Timer is aborted when a dialog is opened in SAP GUI):

      The timer is aborted as soon as a modal dialog is opened in SAP GUI.