SAP Fiori里的两种锁机制

Posted sap-jerry

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SAP Fiori里的两种锁机制相关的知识,希望对你有一定的参考价值。

Approach 1: ETAG mechanism

This approach is used in SAP CRM Fiori.
Suppose user Jerry has opened a given opportunity with ID = 3456 and clicked the Edit button:

技术图片

A read operation is fired and sent to ABAP backend:

技术图片

We can observe in Chrome development tool that the ETAG field of HTTP response header is filled accordingly.

技术图片

This ETAG value ending up with “26AE” is actually calculated by application.
The common calculation logic is to either leverage the last changed timestamp of OData model node being read, see example below:

技术图片

or use the calculated HASH value based on the whole content of model node:

技术图片

Now say another user has changed this opportunity and saved the change successfully. Jerry was not aware of it at all, he just changed the opportunity, and pressed the Save button.

技术图片

And Jerry saw this error message: Data has been changed by another user. Choose OK to retrieve the latest data.

技术图片

Open Chrome Development Tool again, and we can find that once Jerry has pressed the Save button, a batch request is sent to ABAP backend whose request header contains one field If-Match. This field is filled with the very ETAG value got from the response header field ETAG of the first read request ( which ends up with 26AE ).

技术图片

What has happened under the hood? A comparison between latest ETAG and the ETAG passed by Fiori UI is made in method CHECK_BEFORE_MODIFICATION:

技术图片

CHECK_BEFORE_MODIFICATION will delegate to method CHECK_ETAG_MATCH in line 57. If check fails, the save will not be performed at all.

技术图片

Approach 2: lock mechanism based on BOPF

This logic is used in S/4HANA Fiori application, such as Material application, which consumes OData service implemented on top of CDS view plus BOPF.
Open one Material and press Edit button:

技术图片

Now locks related to a series of Material tables could be found in tcode SM12:

技术图片

In S/4HANA backend system, launch tcode BOBX to open BO model with name I_PRODUCTWD. Navigate to Edit action and double click, to find implementation class CL_I_DR_PRODUCTWD.

技术图片

It’s responsible for method LOCK_ACTIVE_DOCUMENT to react on the Edit button click in Fiori UI.

技术图片

Set a breakpoint on it, click Edit button and breakpoint is triggered. From the callstack we can clearly know how the execution flow is delegated from BOPF framework code to Material application code. The acutal enqueue operation is achieved by the enqueue function module owned by Material application.

技术图片

要获取更多Jerry的原创文章,请关注公众号"汪子熙":
技术图片





以上是关于SAP Fiori里的两种锁机制的主要内容,如果未能解决你的问题,请参考以下文章

mysql 锁机制

mysql 锁机制

面试中的最常被问到的两种锁

做开发,这几种锁机制你不得不了解一下

锁机制及锁优化

做开发,这几种锁机制你不得不了解一下