Mastering Total ETag in RAP , A Practical Guide.
Share

In this blog I have explained the mechanism of total etag  and also differnce between  E-TAG and total etag in RAP in restful abap programming model .

Introduction :

 ETAG: the etag concept ensures that  the end user of an Odata service only changes instances with the state that is displayed on the UI .

Hence , the etag prevents changes of the BO that are not noticed by the Odata consumers .With Etag master each BO  entity can be checked independently.

TOTAL E-TAG: 

  • It enables optimistic concurrency checks durig the transition from draft to active data 
  • This total etag field on the database table is updated by the RAP runtime framework as soon as an active instance is changed  
  • Its value is compared when resuming a draft instance to ensure that the active data has not been changed after the exclusive lock has expired 

The total E-tag is used for edit-drafts, a draft that has a corresponding active instance .As soon as the exclusive lock expires and  an edit-draft is resumed , the total etag value of the draft is compared to the total ETAG value of the active instance .

The total etag is compared for all entities of BO 

Total e-tag is useful when we are changing draft data to active data .

Pradeep555_0-1758777107961.png

 

why total etag? and scenario

Suppose an application is not using draft concepts ,  if it is only using e-tag then that application is also modifying the same table 

E-tag will work whenever we are loading the data in the front end , someone else changes the data  and  unknowingly  saving the data – etag will be compered 

In  order to save the data and override we use etag .

SCENARIO: 

When we start working on a draft table , we will put exclusive lock on active instance (say BOOKING ID-1)so that nobody can change the data.  

Active data base–>it will become active instance–> active instance to it will become draft instance  .

Suppose  I  have made some changes in active instance and – forgot to save it , But it will be automatically saved in draft instance – as we are working on draft 

 Chages made will be automatically saved in draft table .

As soon as we stop working – the exclusve lock will be removed from active instance (BOOKING ID-1) .

So now  the I  will come again ad start working on the draft instance which  have  Saved , again  I will put exclusive lock and make some changes in the data and save it . As soon as we save – draft instance will be converted into active instance .

What happens if we don’t use total eTag? 

Suppose somebody else did some changes and those changes are not saved in draft  (the app is not using draft ) ,And we will be overwriting those changes with our changes, since we don’t exactly now  whether someone eles has changed the data or not . 

Total etag will be matched automatically based on the field @Semantics.systemDateTime.lastChangedAt: true 

We need to match these field in behaviour definition  

The framework will update total etag field each time –> whenever we are converting draft into  active data .

Example :

1.create the table  

Pradeep555_1-1758777516837.png

2.create a consumption view and provide the necessary annotation .

Pradeep555_2-1758777601278.png

 3.create behaviour definition and provide total Etag and respective field.

Pradeep555_3-1758777648461.png

4. create draft table .

Pradeep555_4-1758777676405.png

5.create service def.

Pradeep555_5-1758777706631.png

6.Create service binding.

Pradeep555_6-1758777736935.png

7.OUTPUT

Pradeep555_7-1758777788413.png

8.now  user 1 opens the data

Pradeep555_8-1758777841691.png

9.user 2 has the same data

Pradeep555_9-1758777887709.png

10.now user 1 starts editing the data 

Pradeep555_10-1758777929109.png

11.suppose the user 2 trying to edit the same data–> he will get an error

Pradeep555_11-1758777971032.png

Pradeep555_12-1758777991719.png

13.we can see the entry in the dradft table

Pradeep555_13-1758778026503.png

14.now the active draft is

Pradeep555_14-1758778067261.png

15.User2 Trying to edit active draft with different value->getting error->No data found 

Pradeep555_15-1758778105887.png

16.Now user2 trying to edit  with Same value->updated 

Pradeep555_16-1758778144031.png

 

So total etag comes into picture !!

Conclusion:

<< Whenever we wil save the data  from active to draft instance – before saving I will compare total e-tag  value  

If it matches –> I shall save the data  

If it does not match –> i shall not save 

Whenever we change the  active data –> total etag changes each time . If nobody changes the data  —> total etag will be matched  

If somebody changes the data–> total  etag will not be matched , we need to discrad the current draft and  we need to load the current data  

NOTE: whenever we change the draft data into active data we need total etag

 

thank you !

– Pradeep Ishwar Devadiga

 

 

 

 

 

 

 

  Read More Technology Blog Posts by Members articles 

#abap

By ali