cancel
Showing results for 
Search instead for 
Did you mean: 

Effective Record Locking Management in SAP CAP for Concurrent Row Selection and Update

richa_dwivedi
Explorer
0 Kudos

Hello All,

How can we effectively manage record locking in SAP CAP when multiple users are selecting the same rows for operations, ensuring that only one user can update the rows while others receive an error?

robinjayasinghe
Advisor
Advisor
0 Kudos

Which runtime are you using? CAP Java or CAP node.js?

richa_dwivedi
Explorer
0 Kudos

robinjayasinghe Using CAP node.js

View Entire Topic
robinjayasinghe
Advisor
Advisor
0 Kudos

On a DB level we support shared locks: https://cap.cloud.sap/docs/node.js/cds-ql#forsharelock

On a logical/UI level, users normally work with draft-flows when data is edited. Here, you can rely on draft-locks: https://cap.cloud.sap/docs/node.js/fiori#draft-locks

I hope this answers your question.

richa_dwivedi
Explorer
0 Kudos

Hi robinjayasinghe

Do you have any implementation example on forShareLock()?

robinjayasinghe
Advisor
Advisor
0 Kudos

No running sample but you can see how it's used in our release notes: https://cap.cloud.sap/docs/releases/archive/2022/jun22#shared-locks

So, if you have a CQL statement in a custom handler (e.g. a On handler) you can just append forShareLock() to the statement and you're good to go. 🙂

richa_dwivedi
Explorer
0 Kudos

robinjayasinghe Yes, I've tried the same, but it's not working for me.

robinjayasinghe
Advisor
Advisor
0 Kudos

In case you're running locally on SQLite this statement might either produce an error or does not have an effect at all. I just checked: SQLite does not support "SELECT FOR UPDATE" https://www.sqlite.org/lang_select.html. So, this would only work on SAP HANA or PostgreSQL.