OData and SAP Netweaver Gateway. Section XIII. SAP OData Gateways’ Entity Tags

Since concurrency management in SAP Netweaver Gateways via OData is vital to workflows and businesses in general, there is much opportunity to investigate and apply such notions.

concurrency in sapui5

Locks and ETag-Based Concurrency Management in SAP Netweaver Gateways

However, the current state of this control is not well defined. Lost update issues are commonly caused by concurrent editing, which involves two users modifying the same resource simultaneously. This article examines OData handling techniques using Entity Tags, which are referred to as “Etags” in this paper.

definition: “the fact that two or more circumstances or events occur or exist simultaneously.”

Technical: It is possible for numerous users to update the same record at once, which could lead to inconsistent results and user confusion. We refer to this problem as concurrency.

Parallel Processing

Negative concurrency management

In this case, the program waits for the successful completion of every transactional operation before blocking. Performance will typically suffer as a result of the application(s) utilizing the resource having to wait in line for the transaction to guarantee that the operations may be applied correctly. Deadlocks are also far more likely to occur in this case since the transaction can be waiting for a resource that is locked by another process.It is gloomy because it actively forbids concurrent writes by aggressively obtaining the resources, assuming that they would happen.

Aggressive concurrency management

Here, each transactional operation is tried, and if any of them fails, the full collection of

Reversals are made in operations. Usually, this is the recommended

HTTP Concurrency Control

It should be clear from the description above that HTTP is limited to using optimistic concurrency control.

  • due to the statelessness of each HTTP transaction.
  • For instance, the following illustrates the Lost update problem with concurrency control:
  • Using HTTP GET, User_A opens a document and begins altering it.
  • Additionally, User_B uses HTTP GET to access the same page once more and begins altering it.
  • User_A uses HTTP PUT to save their updates.
  • Although User_B saved their changes, User_A’s updates were not visible to User_B.
  • The edits made by User_A are therefore lost when User_B overwrites them.
  • In-depth illustrationBoth User_A and User_B send the same Etag in the response field when they submit GET requests to the server for document X.
  • User_A makes edits but doesn’t save them, meaning they aren’t sent to the server via a PUT request.
  • After editing, User_B makes a PUT request with the If-Match field value set to Etag.

The content is updated and a new entity tag is obtained through the response since the Etag value stays the same as the server, resulting in the status code 204 being received.Thus, User_B stores the new Etag for use in response to future requests and deletes the old one.

User_A sends a PUT request concurrently with the If-Match field value set to Etag. Due to User_B’s activity, the Etag value has changed, and as a result, the response is status code 428 with preconditions failed.

User_A sends PUT to get the most recent version of document X.

Consequently, concurrentness in HTTP transactions is regulated through the use of entity tags in conjunction with If-Match and If-None-Match sections.

How to Proceed

Developers would be more inclined to pursue this.Etags based on properties or entities can be implemented. Compared to property-based Etags, entity-based Etags are more common in real-world situations. With entity-based Etags, this sample will change over time.

Step I: Establish the Entity Framework

Initially, we must build a structure that will house the “Etag” as a property. Etag is essentially a hash value that is produced based on the entity data’s value. We added an Etag field to the SCARR structure to better accommodate the Etag.

ETags in OData

Phase Two: Establish the Gateway Service Entity Type

Using the ZSCARR framework, create your gateway entity and provide the necessary runtime artifacts. Although our Etag scope will be restricted to the SCARR entity type, my gateway service includes both the SPFLI and SCARR structures.

The properties, navigations, and relationships created for the service used in this example are explained in the graphic below. The ZSCARR Entity’s ETag property has been mapped to the entity’s “Etag” field. This facilitates the Etag’s appearance in the get responses’ metadata section.

locking in sapui5
Entity based ETag

Also Check: OData and Netweaver Gateway Introduction

Step – III:  Create the ETag generation method

Now that you have generated the runtime artifacts, create one more method to calculate the hash value of the data record passed. I named the method – CALCULATE_HASH. The importing and exporting parameters are shown in the image.

calculate hash
multiple log in ui5

Step IV: The CALCULATE_HASH method’s coding

Let us code the procedure. The “CALCULATE_HASH_FOR_RAW” function module will be utilized to produce the hash value for a given record. A hash value that will be used as an Etag will be the FM output.

CALCULATE_HASH_FOR_RAW

Step V: Modify the GET_ENTITY and GET_ENTITYSET functions

It is important to keep in mind that the hash value is computed and returned as part of the response each time a resource request (GET) is made.The hash value will only alter in response to changes in the entity data, which will cause an Etag mismatch.Since we want the SCARR to be updated through the Etag validation, we will make the appropriate adjustments to accommodate the hash values in SCARRSET_GET_ENTITY and SCARRSET_GET_ENTITYSET of SCARR.

Semi-­optimistic concurrency control

SCARRSET_GET_ENTITY.

Semi-­optimistic concurrency control

Step VI: Use Etag to Update a Record

Let’s check the Etag’s functionality in a data record retrieval scenario. I’m attempting to get the data by using CARRID = “AS.” This graphic illustrates the current state of the data record in the database.

etag example

Let’s use ‘AS’ as the primary key in a SCARRSET_GET_ENTITY. This ought to give us back Etag from the metadata part as well as Etag from the SCARR entity’s field.

etag in response

Note: The header’s highlighted entry is “Etag.””etag” should also be found in the metadata section, however it is not the same as the header etag.The reason for this is the inclusion of the apostrophe “(” in the metadata.Apostrophes are written using the symbol (\” ). Take the Etag value from the response header to prevent confusion and manual changes.

Step VII: Update utilizing the results of Session 1

The current data record against key = “AS” is represented by this Etag. Any modification or alteration will result in a change to the Etag. To match and update the data record, we will use the current Etag in our update. To match an Etag value for a record and continue processing, we utilize the HTTP header “If-Match.” Should this Etag not match, the update will not proceed. I’ll provide an update on the current Etag in Session 1.

The picture I requested is shown below.Take note of the Etag header.

We can verify that the request is using the GET protocol in the debugger. The Etag is generated again in GET so that it may be compared at update time.

etag checking

Currently, the “Update” technique is under control.

ETag in sap

Step VIII: Update with the help of Session 2.

Step – VIII:                   Update using Session 2

Simultaneously run a different update scenario using Session 2. Because the user of the second session is unaware that the record has been modified in the interim, it should be noted that our original record Etag will be used here as well.

IF-NOT-MATCH

In order to retrieve the Etag for the data record, control should initially flow to the SCARRSET_GET_ENTITY.

netweaver gateway

Considering that the record has already been modified, take note of the ETAG value change. This ought to prevent the update from starting and displaying an error message.
Kindly Reload:CRUD Functions in OData with SAP Netweaver Gateway

Step IX: Apply “If-None-Match” to update the scenario.

Similar to “If-Match,” “If-None-Match” is another HTTP header that checks for the presence of the Etag first and moves forward if there is a mismatch. Let’s apply this heading to the same item.

if none match

Success Now

IN-NONE-MATCH

Conclusion

Mastering Entity Tags in SAP OData Gateways As we’ve explored in this series on SAP NetWeaver Gateway and OData, understanding and implementing entity tags (ETags) is crucial for efficient and reliable data management in your SAP environment.

you may be interested in this blog here:-

SAP fiori configuration for s/4hana

Salesforce Rainy ’24 Highlights | All You Need to Know

SAP ABAP future in next coming years

Related Posts

SAP XI/PI – Invoice Attachment Transfer from ARIBA to VIM

The documents that are connected to the invoice in the Ariba Network system should be transferred to the VIM system via PI Integration as part of the Ariba Supplier Invoice…

Attachments for SAP XI/PI – ARIBA Invoices sent via PI to S/4HANA

Integration with SAP systems has never been more intriguing, especially with Ariba, Workday, Concur, Successfactors, Fieldglass, Hybris, and other satellite cloud solution vendors banging on doors every day. 🙂 I…

Leave a Reply

Your email address will not be published. Required fields are marked *

You Missed

SAP XI/PI – Invoice Attachment Transfer from ARIBA to VIM

  • By Varad
  • November 8, 2024
  • 2 views
SAP XI/PI – Invoice Attachment Transfer from ARIBA to VIM

11 Steps to Include a New Field in an Already-Existing SAP LSMW Batch Input Recording

  • By Varad
  • November 6, 2024
  • 2 views

Part 23 of ABAP for SAP HANA. How Can AMDP Be Used to Access Database Schema Dynamically?

  • By Varad
  • November 4, 2024
  • 2 views

S/4HANA VDM 1 Employing CDS Virtual Data Model for Embedded Analytics

  • By Varad
  • November 1, 2024
  • 5 views