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. ENDIF. 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.
CLASS lcl_event DEFINITION. PUBLIC SECTION. 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.
CLASS lcl_event IMPLEMENTATION. METHOD m_timer_finished. * refresh selection get_data_somewhere( ). * trigger PAI to force refresh of overview CALL FUNCTION 'SAPGUI_SET_FUNCTIONCODE' EXCEPTIONS 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.