Timer
Fire a backend event after a delay with the start_timer frontend event. 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.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_sample_timer IMPLEMENTATION.
METHOD z2ui5_if_app~main.
CASE abap_true.
WHEN client->check_on_init( ).
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( ) ).
client->follow_up_action( val = client->cs_event-start_timer
t_arg = VALUE #( ( `TICK` ) ( `2000` ) ) ).
WHEN client->check_on_event( `TICK` ).
counter = counter + 1.
client->follow_up_action( val = client->cs_event-start_timer
t_arg = VALUE #( ( `TICK` ) ( `2000` ) ) ).
ENDCASE.
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:
WHEN 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` ) ) ).
WHEN 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, which is why a poll re-arms it in every response that keeps it going — and why no timer survives an app switch: the nav_app_call( ) or nav_app_leave( ) that changes the app is a roundtrip, and the timer that was pending is gone before the next app's main( ) runs. A tick that comes due while a roundtrip is in flight — a popup's own event, a Back/Forward restore — is not dropped and does not abort that request: it waits for the response to land 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:
WHEN 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( ) wire. 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 |
