Mastering Total ETag in RAP , A Practical Guide.

Estimated read time 8 min read

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 .

 

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  

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

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

4. create draft table .

5.create service def.

6.Create service binding.

7.OUTPUT

8.now  user 1 opens the data

9.user 2 has the same data

10.now user 1 starts editing the data 

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

13.we can see the entry in the dradft table

14.now the active draft is

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

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

 

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

 

 

 

 

 

 

 

​ 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 . why total etag? and scenarioSuppose 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  2.create a consumption view and provide the necessary annotation . 3.create behaviour definition and provide total Etag and respective field.4. create draft table .5.create service def.6.Create service binding.7.OUTPUT8.now  user 1 opens the data9.user 2 has the same data10.now user 1 starts editing the data 11.suppose the user 2 trying to edit the same data–> he will get an error13.we can see the entry in the dradft table14.now the active draft is15.User2 Trying to edit active draft with different value->getting error->No data found 16.Now user2 trying to edit  with Same value->updated  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 

#SAP

#SAPTechnologyblog

You May Also Like

More From Author