Skip to Content
Author's profile photo Former Member

Prototyping “eTag Based” locking within SAP UI5 and SAP Gateway

I found no end-to-end example “How to use eTag based locking”. So implement a simple prototype which a share to you.

My question : Is there a better way to handle the eTag on the client side as is describe below ?


Locking :  Ensure that a user don’t change already updated data.



Backend implementation

1. Persistence and Datatypes

1.1. Table


1.2. Source structure for SAP Gateway Service generation


SAP Gateway Definition

The OData Service definition is strate foreward only the ETag Property definition is special.

etag definition.gif

As you see: The service has only four attributes and LastChanged is the Timestamp updated during updates on the given record.

SAP Gateway Implementation

Four methods are implemented:

….._get_entityset : Return all employees


……_get_entity : Return given employee


….._update_entity : Update given employee


In the update method a new timestamp is calculated and written to db and send back to SAP Gateway framework.

….._create_entity : Create employee entry


How ETag works in SAP Gateway ?

The Response of a GET (Entity or EntitySet) contain for each object the etag property . In this prototype this is assigned to the LastChanged attribute.



If you send now a Update or DeleteRequest with the needed etag the following happens:

  1. SAP Gateway call the ….._get_entity method and read the attribute bound to the eTag Property.
  2. SAP Gateway compare the eTag given in the Request with the eTag returned from the ….._get_entity method.
  3. If both eTags are equal the …._update_entity method will called within this method the attribute bound to the eTag Property will set to a new value and the new value is given back to the caller.

If both eTags are not equal (Data changed between read and update) an exeption will returned to the caller.

process flow.gif

In the screenshot below you see the eTag provided in the Request and the new eTag after the update.


Below the Status_code 412 if you try to change changed data.


Frontend Implementation

The frontend implementation is a strate foreward implementation.

  1. onInit function


Bind the OData Entity to the Overview Table

  1. onRow function


Called if the user select a row to change the data and bind the element to a simpleform to change the data.

  1. onUpdate function


Called to send the updated data to the backend and  set the eTag in the request.

Question : Is there a better way to get the etag  ??

I only found it within the object in the __metadata object.


I you have any question or you have a better way to get the etag on client side etc. please send a comment.

Kind regards,


Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Péter Catano
      Péter Catano

      Have you tried oModel.getETag('/EmployeeSet'); ?

      Author's profile photo Radoslaw Kiela
      Radoslaw Kiela

      There is no need to handle/push the ETag manually... it is automatically handled by the framework, if not explicitely implemented on the backend by