Skip to content

Commit 92ef62d

Browse files
committed
Add Timer / Auto-Refresh documentation page
Add new cookbook page under Specifics documenting the client->timer_set() functionality with three examples: - Basic timer usage with counter increment - Dashboard auto-refresh pattern with periodic data reload - Stopping/toggling the timer with user control https://claude.ai/code/session_0165sq6V21ktTSAhKUW4r74K
1 parent a4ddc4a commit 92ef62d

2 files changed

Lines changed: 136 additions & 0 deletions

File tree

docs/.vitepress/config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ export default defineConfig({
162162
{ text: "Logging", link: "/development/specific/logging" },
163163
{ text: "Camera", link: "/development/specific/camera" },
164164
{ text: "CDS, EML", link: "/development/specific/cds" },
165+
{ text: "Timer", link: "/development/specific/timer" },
165166
{ text: "Drag & Drop", link: "/development/specific/drag" },
166167
{
167168
text: "Smart Controls",

docs/development/specific/timer.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Timer, Auto-Refresh
2+
3+
abap2UI5 provides a timer functionality that triggers backend events after a specified interval. This is useful for dashboards, status monitors, or any scenario that requires periodic data updates without manual user interaction.
4+
5+
#### Basic Usage
6+
7+
Use the `client->timer_set` method to schedule a backend event after a given interval in milliseconds:
8+
9+
```abap
10+
CLASS z2ui5_cl_sample_timer DEFINITION PUBLIC FINAL CREATE PUBLIC.
11+
12+
PUBLIC SECTION.
13+
INTERFACES z2ui5_if_app.
14+
DATA counter TYPE i.
15+
16+
ENDCLASS.
17+
18+
CLASS z2ui5_cl_sample_timer IMPLEMENTATION.
19+
METHOD z2ui5_if_app~main.
20+
21+
CASE abap_true.
22+
23+
WHEN client->check_on_init( ).
24+
client->view_display( z2ui5_cl_xml_view=>factory(
25+
)->page( `abap2UI5 - Timer`
26+
)->text( client->_bind( counter )
27+
)->stringify( ) ).
28+
29+
client->timer_set(
30+
interval_ms = 2000
31+
event_finished = `TIMER_FINISHED` ).
32+
33+
WHEN client->check_on_event( `TIMER_FINISHED` ).
34+
counter = counter + 1.
35+
client->view_model_update( ).
36+
37+
"set timer again for continuous refresh
38+
client->timer_set(
39+
interval_ms = 2000
40+
event_finished = `TIMER_FINISHED` ).
41+
42+
ENDCASE.
43+
44+
ENDMETHOD.
45+
ENDCLASS.
46+
```
47+
The timer fires once after the interval expires. To create a continuous auto-refresh loop, simply re-set the timer inside the event handler.
48+
49+
#### Dashboard Auto-Refresh
50+
51+
A common use case is refreshing dashboard data periodically. The following example fetches updated data from the database on every timer event:
52+
53+
```abap
54+
CLASS z2ui5_cl_sample_dashboard DEFINITION PUBLIC FINAL CREATE PUBLIC.
55+
56+
PUBLIC SECTION.
57+
INTERFACES z2ui5_if_app.
58+
DATA last_refresh TYPE string.
59+
DATA mt_orders TYPE STANDARD TABLE OF z2ui5_t_draft WITH EMPTY KEY.
60+
61+
ENDCLASS.
62+
63+
CLASS z2ui5_cl_sample_dashboard IMPLEMENTATION.
64+
METHOD z2ui5_if_app~main.
65+
66+
CASE abap_true.
67+
68+
WHEN client->check_on_init( ).
69+
last_refresh = |{ sy-datum DATE = USER } { sy-uzeit TIME = USER }|.
70+
71+
DATA(tab) = z2ui5_cl_xml_view=>factory(
72+
)->page( `Dashboard`
73+
)->header_content(
74+
)->text( client->_bind( last_refresh )
75+
)->get_parent(
76+
)->table( client->_bind( mt_orders ) ).
77+
78+
tab->columns(
79+
)->column( )->text( `ID` )->get_parent(
80+
)->column( )->text( `Status` ).
81+
82+
tab->items( )->column_list_item( )->cells(
83+
)->text( `{UUID}`
84+
)->text( `{UUID_PREV}` ).
85+
86+
client->view_display( tab->stringify( ) ).
87+
88+
client->timer_set(
89+
interval_ms = 5000
90+
event_finished = `REFRESH` ).
91+
92+
WHEN client->check_on_event( `REFRESH` ).
93+
"refresh data
94+
last_refresh = |{ sy-datum DATE = USER } { sy-uzeit TIME = USER }|.
95+
client->view_model_update( ).
96+
97+
client->timer_set(
98+
interval_ms = 5000
99+
event_finished = `REFRESH` ).
100+
101+
ENDCASE.
102+
103+
ENDMETHOD.
104+
ENDCLASS.
105+
```
106+
107+
#### Stopping the Timer
108+
109+
To stop an active timer, simply do not call `client->timer_set` again in the event handler. You can also add a toggle button for user control:
110+
111+
```abap
112+
WHEN client->check_on_event( `TOGGLE_TIMER` ).
113+
IF auto_refresh = abap_true.
114+
auto_refresh = abap_false.
115+
ELSE.
116+
auto_refresh = abap_true.
117+
client->timer_set(
118+
interval_ms = 2000
119+
event_finished = `TIMER_FINISHED` ).
120+
ENDIF.
121+
client->view_model_update( ).
122+
123+
WHEN client->check_on_event( `TIMER_FINISHED` ).
124+
counter = counter + 1.
125+
IF auto_refresh = abap_true.
126+
client->timer_set(
127+
interval_ms = 2000
128+
event_finished = `TIMER_FINISHED` ).
129+
ENDIF.
130+
client->view_model_update( ).
131+
```
132+
133+
::: warning
134+
Keep in mind that each timer event triggers a full backend roundtrip. Use reasonable intervals (e.g., 2000ms or higher) to avoid excessive server load.
135+
:::

0 commit comments

Comments
 (0)