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/cookbook/eml_cds_sql/draft_handling.md
+50-31Lines changed: 50 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,61 +5,80 @@ outline: [2, 4]
5
5
6
6
Draft handling lets users save unfinished work — for example a half-filled form — without writing through to the active database state. In abap2UI5 apps you drive RAP draft-enabled business objects directly through EML, just like any other entity (see also [EML](./eml.md)).
7
7
8
+
All examples on this page use `I_BankTP`, a draft-enabled BO that ships with S/4HANA.
9
+
10
+
### The EML Primitives
11
+
8
12
#### Create a Draft
9
13
Use `MODIFY ENTITIES` with `%is_draft = if_abap_behv=>mk-on` to create a new draft instance:
Set `%is_draft = if_abap_behv=>mk-on` to read the draft instead of the active record:
33
35
```abap
34
-
READ ENTITIES OF i_salesordertp
35
-
ENTITY SalesOrder
36
-
FIELDS ( SalesOrderType )
37
-
WITH VALUE #( ( %key-SalesOrder = `0000004711`
38
-
%is_draft = if_abap_behv=>mk-on ) )
36
+
READ ENTITIES OF i_banktp
37
+
ENTITY Bank
38
+
FIELDS ( SWIFTCode LongBankName )
39
+
WITH VALUE #( ( %key-BankCountry = `DE`
40
+
%key-BankInternalID = `50070010`
41
+
%is_draft = if_abap_behv=>mk-on ) )
39
42
RESULT DATA(lt_drafts).
40
43
```
41
44
42
-
#### Activate or Discard
43
-
Promote the draft to the active state with the `Activate` action, or throw it away with `Discard`:
45
+
#### Activate a Draft
46
+
Promote the draft to the active state with the `Activate` action:
44
47
```abap
45
-
MODIFY ENTITIES OF i_salesordertp
46
-
ENTITY SalesOrder
48
+
MODIFY ENTITIES OF i_banktp
49
+
ENTITY Bank
47
50
EXECUTE Activate
48
-
FROM VALUE #( ( %key-SalesOrder= `0000004711`
49
-
%key-IsActiveEntity = abap_false ) )
51
+
FROM VALUE #( ( %key-BankCountry = `DE`
52
+
%key-BankInternalID = `50070010` ) )
50
53
FAILED DATA(ls_failed)
51
54
REPORTED DATA(ls_reported).
52
55
53
56
COMMIT ENTITIES.
54
57
```
55
58
56
-
### Editing a Standard SAP Draft BO
59
+
#### Discard a Draft
60
+
Throw the draft away with the `Discard` action, releasing the lock:
61
+
```abap
62
+
MODIFY ENTITIES OF i_banktp
63
+
ENTITY Bank
64
+
EXECUTE Discard
65
+
FROM VALUE #( ( %key-BankCountry = `DE`
66
+
%key-BankInternalID = `50070010` ) )
67
+
FAILED DATA(ls_failed)
68
+
REPORTED DATA(ls_reported).
69
+
70
+
COMMIT ENTITIES.
71
+
```
72
+
73
+
### Tutorial — Building a Bank Edit App
74
+
75
+
With the primitives in hand, the rest of this page walks step by step through a full abap2UI5 app that edits a bank record through its standard BO draft.
57
76
58
-
On S/4HANA or BTP ABAP Environment (Steampunk), many business objects already ship as draft-enabled BOs (e.g.`I_BankTP`, `I_SalesOrderTP`). You don't build a BO and you don't create a draft table — SAP provides both. Your abap2UI5 app just calls the standard BO via EML, which sidesteps the whole lock-during-think-time problem.
77
+
On S/4HANA or BTP ABAP Environment (Steampunk), many business objects already ship as draft-enabled BOs —`I_BankTP` is one of them. You don't build a BO and you don't create a draft table — SAP provides both. Your abap2UI5 app just calls the standard BO via EML, which sidesteps the whole lock-during-think-time problem.
59
78
60
79
The session can stay **stateless**: the draft survives between roundtrips in SAP's draft-shadow table, and the lock is held by the BO framework as long as the draft exists. Closing the browser without activating or discarding leaves the draft for the same user to resume later — no `set_session_stateful( )`, no `ENQUEUE_*`, no custom Z table.
61
80
62
-
The walkthrough below uses`I_BankTP` to edit a bank record. The flow is split into two modes:
81
+
The app uses two modes:
63
82
-**VIEW mode** — read-only display of the active database record. No lock, no draft.
64
83
-**EDIT mode** — a draft is open; inputs are editable. The BO framework holds the lock.
0 commit comments