cancel
Showing results for 
Search instead for 
Did you mean: 

pessimistic lock in custom RAP based application(OData V2)

santosh_fhalke
Participant
0 Kudos

Hi,

We want to implement pessimistic lock in one of the custom RAP based application(OData V2) where if user A is editing the document & if at the same time user B is trying to edit the same document then system should give error as "The document is currently being processed by user". 

User do not want to use optimistic lock, which lets user to go in edit mode and at the time of save system will checks the lock.

The similar functionality is already achieved in one of the standard Fiori app -- App ID
F3893 (Manage Sales Orders - Version 2) it is using pessimistic lock.

When user click on Edit button on object page, call goes to backend to check sales order is already locked or not. if it is locked then system is giving popup with error as it is already locked. However not able to understand how this is integrated into this particular app.

If anyone have any idea about this, appreciate your help in this.

santosh_fhalke_0-1712591169931.png

View Entire Topic
Amit_Sharma
Explorer
0 Kudos

The lock will be checked automatically as soon you go into the EDIT mode . There could 2 scenario here 

1. Managed App : If you are using managed app , the lock check will be handle by framework and it will give                                     you generic error " You can't edit this instance at the moment. It's currently locked.".

Amit_Sharma_0-1712663136321.png

2. Unmanaged App : In your example , Manage Sales Order Version 2 i.e. an Unmanaged app , the lock                                           check has to be handled explicitly by custom logic in the lock method . You need to                                           throw the error by filling up the Failed and Reported Structure and it will be shown                                             automatically on the screen .

Amit_Sharma_1-1712663619703.png

BDEF : R_SALESORDERTP

 

 

santosh_fhalke
Participant
0 Kudos

Hi Amit,

Thanks for your response.

In my custom app which is unmanaged app, I have implemented the lock method & call is also going into lock method but on save button & not on edit button. When we are clicking on Edit button on object page, that time call is not going into backend to check the lock entry.

However in manage sales order app, when we are clicking on edit button, call is going into backend & giving error. Here, SAP has implemented below screenshot action in behavior projection which is getting called when we are clicking on edit button. but there is clue how they are calling this action on edit button.

santosh_fhalke_0-1712669401994.pngsantosh_fhalke_1-1712669558031.png

Regards,

Santosh F.

 

Amit_Sharma
Explorer
0 Kudos

Hi Santosh , 

I tried replicating the scenario with unmanaged and i am getting the lock method triggered as soon i click on edit button .

Amit_Sharma_0-1712726983469.png

Dummy logic Implemented which i have followed :- 

failed-zsa_r_material_2 = value #( ( matnr = keys[ 1 ]-Matnr ) ).
 
APPEND VALUE #( %msg = new_message_with_text( severity =  if_abap_behv_message=>severity-error
                                              text = 'Lock has been triggered' )
                ) TO reported-zsa_r_material_2.

Error : 

Amit_Sharma_1-1712727200317.png

I have used Unmanaged V4 app with draft enabled for this example .

santosh_fhalke
Participant
0 Kudos
Hi Amit, It seems your latest reply is not captured in the post.
santosh_fhalke
Participant
0 Kudos

Hi Amit,

User do not want to use draft functionality in the custom application. However when we use OData V4 then draft functionality must be enabled otherwise we will not be able to see Edit/Delete buttons.

But in Sales order app they have used OData V4 without draft functionality & they are able to see EDIT button in the app. How this is possible? Do you have any idea about this?

Regards,

Santosh

Amit_Sharma
Explorer
0 Kudos

Hi,

Not sure , about how it has been done standard app . May be they have used additional UI5 code for this ,if see the BSP file there are custom views and controller , so might be the possibility it has been done from UI5. 

But , you can use V2 if you do not want draft functionality it will work similarly .