Timer
Fire a backend event after a delay with the start_timer frontend action. Handy for dashboards, status monitors, or any case that needs a delayed or periodic update without user interaction.
Pass the event name to fire and the delay in milliseconds:
client->follow_up_action(
val = client->cs_event-start_timer
t_arg = VALUE #( ( `REFRESH` ) ( `2000` ) ) ).After 2 seconds the browser triggers a backend roundtrip with the event name REFRESH, which you handle via check_on_event like any other event.
An optional third argument keeps the busy indicator down for the tick — see Without the Busy Indicator.
Periodic Refresh
To get a repeating timer, simply re-arm it at the end of each handler:
CLASS zcl_sample_timer DEFINITION PUBLIC.
PUBLIC SECTION.
INTERFACES z2ui5_if_app.
DATA counter TYPE i.
PROTECTED SECTION.
DATA client TYPE REF TO z2ui5_if_client.
METHODS view_display.
METHODS timer_start.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_sample_timer IMPLEMENTATION.
METHOD z2ui5_if_app~main.
me->client = client.
IF client->check_on_init( ).
view_display( ).
timer_start( ). " once - a return must not start a second one
ELSEIF client->check_on_navigated( ).
view_display( ).
ELSEIF client->check_on_event( `TICK` ).
counter = counter + 1.
timer_start( ). " re-arm: the timer fires once
ENDIF.
ENDMETHOD.
METHOD view_display.
DATA(view) = z2ui5_cl_ui5_view_builder=>factory(
)->ele( n = `View` ns = `mvc`
)->a( n = `xmlns` v = `sap.m`
)->a( n = `xmlns:mvc` v = `sap.ui.core.mvc`
)->ele( `Page`
)->a( n = `title` v = `abap2UI5 - Timer`
)->tag( `Text`
)->a( n = `text` v = client->_bind( counter ) ).
client->view_display( view->stringify( ) ).
ENDMETHOD.
METHOD timer_start.
client->follow_up_action( val = client->cs_event-start_timer
t_arg = VALUE #( ( `TICK` ) ( `2000` ) ) ).
ENDMETHOD.
ENDCLASS.The counter increments every 2 seconds. To stop the loop, simply don't re-arm the timer in the handler.
One-Shot Timer
A single start_timer call fires once — perfect for a deferred action like opening a new tab after a short delay:
ELSEIF client->check_on_event( `BUTTON_OPEN_NEW_TAB` ).
client->follow_up_action( val = client->cs_event-start_timer
t_arg = VALUE #( ( `FIRE_OPEN_TAB` ) ( `500` ) ) ).
ELSEIF client->check_on_event( `FIRE_OPEN_TAB` ).
client->follow_up_action( val = client->cs_event-open_new_tab
t_arg = VALUE #( ( `/sap/bc/z2ui5?app_start=z2ui5_cl_my_report` ) ) ).Replacing a Pending Timer
There is one timer at a time. Calling start_timer again before the previous one fires replaces it — useful for a debounce, e.g. auto-saving an input field 500 ms after the last keystroke.
Every roundtrip cancels the pending timer. That is why a poll starts the timer again in every response that keeps it going. It is also why no timer survives an app switch: the nav_app_call( ) or nav_app_leave( ) that changes the app is a roundtrip, and the pending timer is gone before the next app's main( ) runs.
A tick can come due while another roundtrip is still running, for example a popup's own event or a Back/Forward restore. Such a tick is not dropped and does not abort that request. It waits for the response and fires right after it.
Without the Busy Indicator
Each tick is a backend roundtrip like any other, so when the backend takes longer than a second, the full-screen busy indicator comes up. For a tick nobody is waiting on — a background poll, or a carousel or ticker that moves on by itself — the overlay then flashes over a screen the user is only reading. Pass `X` as a third argument to keep it down for that tick:
ELSEIF client->check_on_event( `TICK` ).
" read the new status ...
client->follow_up_action( val = client->cs_event-start_timer
t_arg = VALUE #( ( `TICK` ) ( `5000` ) ( `X` ) ) ).The flag belongs to the tick that call arms, so a repeating timer passes it again every time it re-arms. Write it as the string `X`, not abap_true: t_arg is a string table, and abaplint's syntax check rejects a c value such as abap_true as one of its rows.
Only the overlay goes — the flag does for the tick what check_no_busy does for an _event( ). The tick is still the one roundtrip in flight: a click that lands while it runs is dropped, as during any roundtrip, and brings the overlay up at once. Leave the flag off for a tick the user is actually waiting for; there the overlay is what tells them the app is working.
WARNING
Each timer tick causes a full backend roundtrip. Use sensible intervals (e.g. 2000 ms or more) to avoid heavy server load.
Working Samples
Complete apps from the sample catalog that use what this page describes. Each is a single class in abap2UI5/samples unless its row names another of the three sample repositories — pull that repository with abapGit and start the class with ?app_start=<class>.
| Sample | Class |
|---|---|
| Progress Indicator during a Backend Call (A) | Z2UI5_CL_SMP_APP_064 |
| Refresh the View Every n Seconds (A) | Z2UI5_CL_SMP_APP_028 |
