What is ETag in ABAP RAP?
ETag (Entity Tag) is a mechanism used for concurrency control and optimizing the performance of OData services. It plays a key role in the optimistic concurrency control used within ABAP RAP, allowing clients and servers to avoid unnecessary updates when data has not changed.
The ABAP RESTful Application Programming Model to ensure consistent data changes with the help of two approaches: Optimistic Concurrency Control and Pessimistic Concurrency Control (Locking). In this tutorial we are going to learn about Optimistic Concurrency Control and how ETag uses it for handling unnecessary updates.
Optimistic Concurrency Control: Optimistic concurrency control allows multiple users to access data simultaneously, ensuring transaction integrity while preventing inconsistencies and unintentional modifications to data that has already been changed.
Pessimistic Concurrency Control (Locking): Pessimistic concurrency control prevents multiple users from modifying the same data in the database at the same time by locking the data during the transaction, ensuring exclusive access for one user at a time.
How ETag works?
When optimistic concurrency control is enabled for RAP business objects, the OData client must send an ETag value with every update. The server compares the sent ETag with the current one. If they match, the change is accepted; if not, the update is rejected. This ensures that the client only changes data it intended to modify and prevents changes made by others in between. When an entity is modified, the ETag is updated to record the new version of the data.
ETag Definition
ETag can be defined in two ways:
ETag Master: An entity is an ETag master, if changes of the entity are logged in a field that is part of the business object entity. This field must be specified as an ETag field in the behavior definition.

ETag Implementation

@Semantics.systemDateTime.localInstanceLastChangedAt: true
➯ Unmanaged Scenario: Unlike in managed scenarios, the application developer in the unmanaged scenario must always ensure that the defined ETag field is correctly updated on every modify operation in the application code of the relevant operations, including for updates by actions.