We help IT Professionals succeed at work.

Notify user that another user has a record locked.

CompTech810
CompTech810 asked
on
Medium Priority
41 Views
Last Modified: 2019-09-20
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!
Comment
Watch Question

Gary PattersonVP Technology / Senior Consultant
CERTIFIED EXPERT

Commented:
DSPRCDLCK command does this.

Author

Commented:
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.
Gary PattersonVP Technology / Senior Consultant
CERTIFIED EXPERT

Commented:
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
Theo KouwenhovenApplication Consultant
CERTIFIED EXPERT

Commented:
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).
Gary PattersonVP Technology / Senior Consultant
CERTIFIED EXPERT

Commented:
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/

Explore More ContentExplore courses, solutions, and other research materials related to this topic.