DRAFT Functionality In ABAP Restful Application Programming
Satya Prakash Tiwari
Certified SAP ABAP on HANA /ABAP/Fiori consultant at Deloitte | Ex-IBM | Ex-Accenture | Ex-Wiproite
Introduction
In ABAP RAP (Restful Application Programming Model), the With_Draft functionality is used to handle draft data and enable the implementation of draft-enabled applications.
Drafts refer to intermediate or temporary versions of data that are being modified or created before they are finalized and saved.
The With_Draft functionality allows us to work with draft data in a consistent and controlled manner.
Application without Draft functionality
If we go in edit mode of record , we need to immediately save the changes to database layer or discard the editing and stay with current data.
There is no option to save the data as draft so that later part it can be saved .
Not having draft functionality in an application can have several drawbacks and limitations.
Here are some common cons of not having draft functionality.
Let us implement Draft functionality
We need to have two field (last_chaged_at and local_last_changed_at) data in business object/CDS hierarchy.
?last_changed_at? ? ? ?: timestampl; - total ETag
? local_last_changed_at : abp_locinst_lastchange_tstmpl; -? Etag
We will discuss about total Etag and Etag in detail.
Important annotations to use in root CDS.
? ? ? @Semantics.systemDateTime.lastChangedAt: true?
? ? ? last_changed_at,
? ? ? @Semantics.systemDateTime.localInstanceLastChangedAt:true
? ? ? ?local_last_changed_at
Once our VDM/BO is ready with field and annotations , we need to define WITH_DRAFT on behaviour defination level.
RAP framework will throw error saying there is no draft table created yet.
mentioned draft table name like below.
we have defined the draft table , lets create it .
Press CNTRL+1 on draft table name and framework will auto create the draft table with exactly same field as BO.
领英推荐
Maintain below field in Behaviour defination.
In the context of ABAP RAP, the "Lock Master: Total ETag" behavior definition refers to a concurrency control mechanism used to handle concurrent access and modifications to draft data.
When a business object with draft functionality is modified by multiple users concurrently, there is a possibility of conflicts where one user's changes may overwrite another user's changes. To prevent such conflicts, the "Lock Master: Total ETag" behavior definition is used.
Here's an explanation of the key aspects of this behavior definition:
The "Lock Master: Total ETag" behavior definition ensures that only the lock master, the user who initially acquired the lock, can modify and save the draft.
If another user tries to modify the same draft, the system checks the ETag to determine if it has been changed by the lock master.
If the ETag has changed, it indicates that the draft has been modified by someone else, and the system can handle the conflict appropriately (e.g., notify the user, prevent overwriting changes).
We need to add draft in projection behaviour defination as well like below.
Activate all including service binding and refresh the application.
Application enabled with Draft functionality
First thing that you will notice on the screen is filter bar named "Editing status".
That allow us to display the data on multiple criteria .
Lets try editing one of the record and check if changes are getting saved as draft.
Go in Edit mode.
Lets change Total price of travel from 750 to 950.
The moment we start making change in any of the field , framework will store the changes in draft table and on screen (below right corner) message would show draft updated.
We will not save changes in database . Lets see how application will display this data.
Lets go to main page and select all records hiding draft.
We have made changes in travel id 1 total price and saved it in draft .Draft price is 950 and real time data is 750 as shown on screen.
Draft data selection.
We can discard the draft if no longer needed.
SAP ABAP Developer | SAP RAP on BTP and S/4HANA | Also a Technical Content Creator ??♂?
11 个月In lock master total etag, is it necessary to maintain only timestamp field of we can put any datatype's field? Does it work the same way with other datatype's field?
ABAP | ABAP on HANA | CDS | SAP BTP
1 年This is a really great explanation of etags, thank you.
SAP Lead Consultant- SAP ABAP, Fiori/UI5, S4HANA, OData specialist
1 年Hi.. Nice blog. Is this draft functionality available for on-premise landscape as well?