Link to home
Start Free TrialLog in
Avatar of CompTech810
CompTech810Flag for United States of America

asked on

Notify user that another user has a record locked.

Hi Experts.  I have what I think is a simple question but I haven't had any success searching for the answer.

I need a program that will notify a user when another user has a record locked that they are trying to access and who is using the record.

Thanks!
Avatar of Gary Patterson, CISSP
Gary Patterson, CISSP
Flag of United States of America image

DSPRCDLCK command does this.
Avatar of CompTech810

ASKER

I'm actually looking for coding that I can add to a CL or RPG for when a user enters a program the program checks to see if the record is locked and notifies the user of who has the record locked.
Ok, so user1 is running a poorly-written program that locks record 276 in a FILEA.  Then it throws a screen, and waits forever, right (or at least until the user comes back from lunch)?  

Best fix, of course, is to redesign the program to avoid this aggressive locking behavior.

But you have a few hundred programs that are all written to do this, and it isn't practical in the sort term to fix them all.

So now, along comes user2.  User2 also wants to update record 279 in FILEA.

My suggestion is to write a record lock error handler.

In ILE RPG, create a MONITOR group around each statement that requests a lock (READs for update, keyed reads, keyed update, keyed delete), and if a record lock is detected, call a program that retrieves the record lock holder and displays the info to the current user, or notifies the owner of the job holding the lock - or both.

If %status = 1218, you have a record lock, and the message data contains the locking job name - or if you are on a recent version of the OS, you can use SQL to retrieve the locking job:

https://www.experts-exchange.com/questions/23428071/How-to-show-a-record-lock-in-an-rpg-program.html

Simon Hutchinson's article about using SQL to find record locks:

https://www.rpgpgm.com/2016/01/finding-record-locks-using-sql.html
Hi CompTech810,

With RPG, use the error extention, the read(e) or chain(e)
After that you can see the result in %error() and/or %status().

To let the user not wait too long, you can set the timout of the file to e.g. 5 or 10 seconds.
(with the OVRDBF keyword WAITRCD).
A few other notes about record lock handling.

Using OVRDBF to reduce timeout before error is thrown for record lock
https://www.experts-exchange.com/questions/24608487/Record-Lock-Status-in-RPGLE.html

Extracting the job holding the lock from the program status data structure
https://enskill.com/record-locking-problem-in-a-monitor-block/
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.