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
Added detailed explanation for Scenario 7 regarding standard SAP BO draft handling via EML, including user flow and considerations for using draft-enabled business objects.
Copy file name to clipboardExpand all lines: docs/development/specific/draft.md
+267Lines changed: 267 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,3 +46,270 @@ For more on EML in abap2UI5 apps, see [CDS, EML](./cds.md).
46
46
::: tip
47
47
Draft tables hold exclusive locks for the draft owner. Combine draft handling with [Locks](./locks.md) only when you also need backend lock objects outside of RAP.
If you are on **S/4HANA** or **BTP ABAP Environment (Steampunk)** and the business object you want to edit is already shipped by SAP as a draft-enabled BO (e.g. `I_SalesOrderTP`), you do not build your own BO and you do not create a draft table. SAP ships both. Your abap2UI5 app simply calls the standard BO via EML.
55
+
56
+
This sidesteps the whole lock-during-think-time problem.
"Activate" pressed -> Activate (now VBAK is written through)
66
+
"Discard" pressed -> Discard (drops the draft, releases lock)
67
+
```
68
+
69
+
**When to use this:**
70
+
- The business object you need is already a released, draft-enabled SAP BO
71
+
- You want classic Fiori-style "edit a draft, activate later" UX in an abap2UI5 app
72
+
73
+
**Key idea:** the session can stay **stateless**. The draft survives between roundtrips in SAP's own draft-shadow table. The lock is held by the BO framework as long as the draft exists — closing the browser without activating or discarding leaves the draft so the same user can resume it on the next visit. No `set_session_stateful( )`, no `ENQUEUE_*`, no custom Z table — SAP does all of that.
74
+
75
+
**Caveat:** field names (`SalesOrder`, `SalesOrderType`) match the released `I_SalesOrderTP` on current S/4HANA. On older releases the BO name or fields may differ — check the released-objects list in your system.
76
+
77
+
**If no standard BO exists** for your object — for instance because you are editing a custom Z business object — you would have to define your own draft-enabled RAP BO (with its own `draft table z…_d`, `lock master`, etc.) and consume that via EML in the same way. That is a separate topic; see the official [SAP RAP draft documentation](https://help.sap.com/docs/abap-cloud/abap-rap/draft).
78
+
79
+
---
80
+
81
+
### example
82
+
83
+
```abap
84
+
* Scenario 7 — Consume a standard SAP draft-enabled BO via EML
85
+
*
86
+
* You are on S/4HANA or BTP ABAP Environment. The sales order is
87
+
* already exposed by SAP as a draft-enabled BO (I_SalesOrderTP). You
88
+
* do NOT build your own BO and you do NOT create a draft table — SAP
89
+
* ships both.
90
+
*
91
+
* The flow the user sees:
92
+
* on_init -> Edit (create or resume the draft)
93
+
* "Save Draft" pressed -> UPDATE (writes the draft only)
94
+
* "Save Draft" again -> UPDATE (still draft, VBAK untouched)
95
+
* ...
96
+
* "Activate" pressed -> Activate (now VBAK is written)
97
+
* "Discard" pressed -> Discard (drops the draft, releases lock)
98
+
*
99
+
* The session stays stateless. The draft survives in SAP's own
100
+
* draft-shadow table between roundtrips. The lock is held by the BO
101
+
* framework as long as the draft exists; closing the browser without
102
+
* discarding leaves the draft so the same user can resume it later.
103
+
*
104
+
* Field names below (SalesOrder, SalesOrderType) match the released
105
+
* CDS view I_SalesOrderTP on current S/4HANA. On older releases the
106
+
* BO name or fields may differ — check the released-objects list in
107
+
* your system.
108
+
109
+
CLASS z2ui5_test_lock_07 DEFINITION PUBLIC.
110
+
111
+
PUBLIC SECTION.
112
+
INTERFACES z2ui5_if_app.
113
+
114
+
DATA sales_order TYPE c LENGTH 10 VALUE `0000004711`.
115
+
DATA sales_order_type TYPE c LENGTH 4.
116
+
DATA draft_open TYPE abap_bool.
117
+
DATA status_text TYPE string.
118
+
119
+
PROTECTED SECTION.
120
+
DATA client TYPE REF TO z2ui5_if_client.
121
+
122
+
METHODS on_init.
123
+
METHODS on_event_save_draft.
124
+
METHODS on_event_activate.
125
+
METHODS on_event_discard.
126
+
METHODS draft_acquire.
127
+
METHODS draft_read.
128
+
METHODS view_display.
129
+
130
+
PRIVATE SECTION.
131
+
ENDCLASS.
132
+
133
+
134
+
CLASS z2ui5_test_lock_07 IMPLEMENTATION.
135
+
136
+
METHOD z2ui5_if_app~main.
137
+
138
+
me->client = client.
139
+
140
+
IF client->check_on_init( ).
141
+
on_init( ).
142
+
ELSEIF client->check_on_event( `SAVE_DRAFT` ).
143
+
on_event_save_draft( ).
144
+
ELSEIF client->check_on_event( `ACTIVATE` ).
145
+
on_event_activate( ).
146
+
ELSEIF client->check_on_event( `DISCARD` ).
147
+
on_event_discard( ).
148
+
ENDIF.
149
+
150
+
ENDMETHOD.
151
+
152
+
153
+
METHOD on_init.
154
+
155
+
draft_acquire( ).
156
+
draft_read( ).
157
+
view_display( ).
158
+
159
+
ENDMETHOD.
160
+
161
+
162
+
METHOD draft_acquire.
163
+
164
+
" Edit is idempotent: if the user already has a draft for this
165
+
" sales order, SAP returns it instead of failing.
166
+
167
+
MODIFY ENTITIES OF i_salesordertp
168
+
ENTITY SalesOrder
169
+
EXECUTE Edit
170
+
FROM VALUE #( ( %key-SalesOrder = sales_order
171
+
%param-PreserveChanges = abap_true ) )
172
+
FAILED DATA(failed)
173
+
REPORTED DATA(reported).
174
+
175
+
IF failed IS NOT INITIAL.
176
+
draft_open = abap_false.
177
+
status_text = `Could not open draft — locked by another user, or no authorization.`.
178
+
RETURN.
179
+
ENDIF.
180
+
181
+
COMMIT ENTITIES.
182
+
183
+
draft_open = abap_true.
184
+
status_text = `Draft open — changes are saved as a draft until you press Activate.`.
185
+
186
+
ENDMETHOD.
187
+
188
+
189
+
METHOD draft_read.
190
+
191
+
IF draft_open = abap_false.
192
+
RETURN.
193
+
ENDIF.
194
+
195
+
READ ENTITIES OF i_salesordertp
196
+
ENTITY SalesOrder
197
+
FIELDS ( SalesOrderType )
198
+
WITH VALUE #( ( %key-SalesOrder = sales_order
199
+
%key-IsActiveEntity = abap_false ) )
200
+
RESULT DATA(drafts).
201
+
202
+
IF drafts IS NOT INITIAL.
203
+
sales_order_type = drafts[ 1 ]-SalesOrderType.
204
+
ENDIF.
205
+
206
+
ENDMETHOD.
207
+
208
+
209
+
METHOD on_event_save_draft.
210
+
211
+
" Persists progress to the draft only. VBAK is NOT touched.
212
+
" The user can press Save Draft many times across many roundtrips.
0 commit comments