You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/development/specific/locks.md
+26-23Lines changed: 26 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,10 +12,10 @@ In classic SAP GUI, a transaction like `VA02` calls `ENQUEUE_EVVBAK` and the loc
12
12
13
13
The patterns below combine in different ways. The examples use the sales order header table `VBAK` and its standard enqueue object `EVVBAK`, but the same shapes apply to any table. All snippets have a complete, copy-paste-ready demo class — sample numbers are linked next to each section.
14
14
15
-
#### No Locking
15
+
#### 1. No Locking
16
16
The minimal starting point — the user edits and saves, no lock and no conflict check. Last save wins, silently. Fine for personal sandboxes and throwaway demos, but rarely what you want in production. See sample `Z2UI5_CL_DEMO_APP_S_07`.
17
17
18
-
#### Lock at Save
18
+
#### 2. Lock at Save
19
19
Do not hold a lock while the user thinks. Acquire it the moment they save, write, commit, and release — all in one short roundtrip:
20
20
```abap
21
21
METHOD on_event_save.
@@ -49,7 +49,7 @@ ENDMETHOD.
49
49
50
50
The lock exists for milliseconds, so this scales — but two parallel saves can still race if the timestamps line up, and the second one silently overwrites the first. See sample `Z2UI5_CL_DEMO_APP_S_08`.
51
51
52
-
#### Optimistic Check
52
+
#### 3. Optimistic Check
53
53
On read, remember the record's change timestamp. On save, re-read and reject if it shifted in the meantime — the same idea as an HTTP ETag:
54
54
```abap
55
55
METHOD data_read.
@@ -78,10 +78,10 @@ No lock is held during the edit phase, so this scales to many concurrent users a
78
78
79
79
Pick a column that *always* updates on writes. If anyone writes the table bypassing `AEDAT` / `UPD_TMSTMP`, the check silently misses real conflicts.
80
80
81
-
#### Combined (recommended default)
81
+
#### 4. Combined (recommended default)
82
82
**Lock at Save** plus the **Optimistic Check** is the safest stateless pattern and the sensible production default — the enqueue serializes parallel saves of *this* app, the timestamp check catches everyone else. See sample `Z2UI5_CL_DEMO_APP_S_10`.
83
83
84
-
#### Stateful Session
84
+
#### 5. Stateful Session
85
85
For classic SAP GUI-like behaviour, switch the session to stateful and call the lock function module on init. The lock survives subsequent roundtrips as long as the session stays alive:
86
86
```abap
87
87
IF client->check_on_init( ).
@@ -123,7 +123,7 @@ See samples `Z2UI5_CL_DEMO_APP_S_11` and `Z2UI5_CL_DEMO_APP_350` for complete ex
123
123
Each active user pins a work process. Use stateful sessions only for low-traffic, internal apps. Always pair `set_session_stateful( )` with an explicit `set_session_stateful( abap_false )` on every exit path — otherwise a leaked enqueue blocks future users until the session times out.
124
124
:::
125
125
126
-
#### Soft Lock
126
+
#### 6. Soft Lock
127
127
A soft lock is a row in a custom Z table marking *"user X is editing object Y"*. It is **not** enforced by the SAP kernel — only your app code respects it — so use it for UX feedback ("locked by Alice since 09:32") and always layer it on top of a real save-time guard. A minimal schema:
128
128
129
129
| Field | Type | Description |
@@ -135,26 +135,29 @@ A soft lock is a row in a custom Z table marking *"user X is editing object Y"*.
135
135
136
136
A user closing the browser without pressing *Release* leaves the row behind, so add a cleanup job that deletes entries older than, say, 30 minutes. See sample `Z2UI5_CL_DEMO_APP_S_12` (with the matching `Z2UI5_SAMPLE_01` table).
137
137
138
-
#### RAP Drafts
138
+
#### 7. RAP Drafts
139
139
On modern releases, RAP draft-enabled business objects manage locking for you: the draft holds an exclusive lock for its owner while the user keeps editing — no stateful session, no `ENQUEUE_*` call. If a released SAP BO already covers your object, this is usually the simplest path. See [Draft Handling](./draft.md).
140
140
141
-
#### Lock-Manager Add-on
141
+
#### 8. Lock-Manager Add-on
142
142
The community add-on [**lock-manager**](https://github.com/abap2UI5-addons/lock-manager) wraps the lock logic in a reusable class — including stale-lock cleanup and a "locked by X since…" message for the user. Install it like any other [add-on](../../resources/addons.md) and call it instead of writing the boilerplate yourself.
143
143
144
-
#### Choosing a Strategy
145
-
```
146
-
Does the app edit data at all?
147
-
├── No → render as read-only
148
-
└── Yes
149
-
├── A released, draft-enabled SAP BO already covers this object?
150
-
│ └── RAP Drafts
151
-
├── Need "locked by X" feedback at open?
152
-
│ ├── Few users, GUI-like feel → Stateful Session
153
-
│ └── Many users → Soft Lock + save guard
154
-
├── A lock-manager add-on available for your platform?
155
-
│ └── Lock-Manager Add-on
156
-
└── Default high-scale stateless editing
157
-
└── Combined (Lock at Save + Optimistic Check)
158
-
```
144
+
#### Overview
145
+
146
+
| # | Strategy | "Locked by X" while editing | Catches external writes | Stateless | Best fit |
147
+
|---|---|---|---|---|---|
148
+
| 1 | No Locking | no | no | yes | Demos, sandboxes |
149
+
| 2 | Lock at Save | no | partial (race window) | yes | Single-app writers, low contention |
150
+
| 3 | Optimistic Check | no | yes (timestamp) | yes | Many concurrent users |
Start with **(4) Combined** unless one of these tips the balance:
158
+
- The app is read-only → no lock needed
159
+
- A released, draft-enabled SAP BO already covers your object → **(7) RAP Drafts**
160
+
- You need a "locked by X since…" message at open → add **(6) Soft Lock** on top of (4), or use **(5) Stateful Session** for few users with a GUI-like feel
161
+
- A lock-manager add-on exists for your platform → **(8) Lock-Manager Add-on**
159
162
160
163
For the underlying concepts and trade-offs of statefulness, see [Statefulness](./statefulness.md).
0 commit comments