abap2UI5
Version 1.146.0

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:

abap
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:

abap
CLASS z2ui5_cl_sample_timer DEFINITION PUBLIC.

  PUBLIC SECTION.
    INTERFACES z2ui5_if_app.
    DATA counter TYPE i.

  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.

CLASS z2ui5_cl_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:

abap
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 #( ( `https://www.google.com/search?q=abap2ui5` ) ) ).

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.

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:

abap
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
Edit this page on GitHub ↗ Last updated:
On this page