Skip to content

Commit 089d8b3

Browse files
authored
Merge pull request #57 from abap2UI5/claude/add-locks-numbering-ulWaD
Restructure locking strategies guide with numbered sections and comparison table
2 parents b79c008 + 8e1ff91 commit 089d8b3

1 file changed

Lines changed: 26 additions & 23 deletions

File tree

docs/development/specific/locks.md

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ In classic SAP GUI, a transaction like `VA02` calls `ENQUEUE_EVVBAK` and the loc
1212

1313
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.
1414

15-
#### No Locking
15+
#### 1. No Locking
1616
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`.
1717

18-
#### Lock at Save
18+
#### 2. Lock at Save
1919
Do not hold a lock while the user thinks. Acquire it the moment they save, write, commit, and release — all in one short roundtrip:
2020
```abap
2121
METHOD on_event_save.
@@ -49,7 +49,7 @@ ENDMETHOD.
4949

5050
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`.
5151

52-
#### Optimistic Check
52+
#### 3. Optimistic Check
5353
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:
5454
```abap
5555
METHOD data_read.
@@ -78,10 +78,10 @@ No lock is held during the edit phase, so this scales to many concurrent users a
7878

7979
Pick a column that *always* updates on writes. If anyone writes the table bypassing `AEDAT` / `UPD_TMSTMP`, the check silently misses real conflicts.
8080

81-
#### Combined (recommended default)
81+
#### 4. Combined (recommended default)
8282
**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`.
8383

84-
#### Stateful Session
84+
#### 5. Stateful Session
8585
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:
8686
```abap
8787
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
123123
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.
124124
:::
125125

126-
#### Soft Lock
126+
#### 6. Soft Lock
127127
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:
128128

129129
| 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"*.
135135

136136
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).
137137

138-
#### RAP Drafts
138+
#### 7. RAP Drafts
139139
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).
140140

141-
#### Lock-Manager Add-on
141+
#### 8. Lock-Manager Add-on
142142
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.
143143

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 |
151+
| 4 | Combined | no | yes | yes | **Production default** |
152+
| 5 | Stateful Session | yes (enqueue) | yes | no (pins work process) | GUI-like feel, few users |
153+
| 6 | Soft Lock | yes (Z table) | only via underlying guard | yes | "Locked by Alice" UX |
154+
| 7 | RAP Drafts | yes (RAP-managed) | yes | yes | A released draft-enabled BO exists |
155+
| 8 | Lock-Manager Add-on | yes | yes | yes | Skip the boilerplate |
156+
157+
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**
159162

160163
For the underlying concepts and trade-offs of statefulness, see [Statefulness](./statefulness.md).

0 commit comments

Comments
 (0)