Skip to content

Commit 12c691c

Browse files
authored
Merge pull request #104 from abap2UI5/claude/keen-allen-VYzK7
Claude/keen allen v yz k7
2 parents c8d0422 + da2810d commit 12c691c

1 file changed

Lines changed: 50 additions & 31 deletions

File tree

docs/cookbook/eml_cds_sql/draft_handling.md

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,61 +5,80 @@ outline: [2, 4]
55

66
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)).
77

8+
All examples on this page use `I_BankTP`, a draft-enabled BO that ships with S/4HANA.
9+
10+
### The EML Primitives
11+
812
#### Create a Draft
913
Use `MODIFY ENTITIES` with `%is_draft = if_abap_behv=>mk-on` to create a new draft instance:
1014
```abap
11-
METHOD z2ui5_if_app~main.
12-
13-
MODIFY ENTITIES OF i_salesordertp
14-
ENTITY salesorder
15-
CREATE
16-
FIELDS ( salesordertype salesorganization )
17-
WITH VALUE #( ( %cid = `0001`
18-
%is_draft = if_abap_behv=>mk-on
19-
%data = VALUE #(
20-
SalesOrderType = `TA`
21-
SalesOrganization = `1010` ) ) )
22-
MAPPED DATA(ls_mapped)
23-
FAILED DATA(ls_failed)
24-
REPORTED DATA(ls_reported).
25-
26-
COMMIT ENTITIES.
15+
MODIFY ENTITIES OF i_banktp
16+
ENTITY Bank
17+
CREATE
18+
FIELDS ( BankCountry BankInternalID LongBankName SWIFTCode )
19+
WITH VALUE #( ( %cid = `NEW_BANK`
20+
%is_draft = if_abap_behv=>mk-on
21+
%data = VALUE #(
22+
BankCountry = `DE`
23+
BankInternalID = `99999999`
24+
LongBankName = `My Bank`
25+
SWIFTCode = `DEUTDEFF` ) ) )
26+
MAPPED DATA(ls_mapped)
27+
FAILED DATA(ls_failed)
28+
REPORTED DATA(ls_reported).
2729
28-
ENDMETHOD.
30+
COMMIT ENTITIES.
2931
```
3032

3133
#### Read a Draft
3234
Set `%is_draft = if_abap_behv=>mk-on` to read the draft instead of the active record:
3335
```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 ) )
3942
RESULT DATA(lt_drafts).
4043
```
4144

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:
4447
```abap
45-
MODIFY ENTITIES OF i_salesordertp
46-
ENTITY SalesOrder
48+
MODIFY ENTITIES OF i_banktp
49+
ENTITY Bank
4750
EXECUTE Activate
48-
FROM VALUE #( ( %key-SalesOrder = `0000004711`
49-
%key-IsActiveEntity = abap_false ) )
51+
FROM VALUE #( ( %key-BankCountry = `DE`
52+
%key-BankInternalID = `50070010` ) )
5053
FAILED DATA(ls_failed)
5154
REPORTED DATA(ls_reported).
5255
5356
COMMIT ENTITIES.
5457
```
5558

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.
5776

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.
5978

6079
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.
6180

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:
6382
- **VIEW mode** — read-only display of the active database record. No lock, no draft.
6483
- **EDIT mode** — a draft is open; inputs are editable. The BO framework holds the lock.
6584

0 commit comments

Comments
 (0)