Problem:
By default, RM/COBOL implements a pessimistic record locking mechanism. This type of locking allows a user process to lock a record, indefinitely, during an update. This can cause issues if another user process is waiting on the record lock.
Resolution:
In Unix environments, the RM/COBOL subprogram library, C$OSLockInfo, can be used to obtain the process ID of the process that has a file locked, however, on Windows, RM/COBOL does not provide any built-in mechanism for obtaining the file lock information. In order to determine the user name of a locked file, you will have to implement some external method.
Below are several suggestions on how to accomplish this task:
1. Micro Focus provides a product named RM/InfoExpress that is server/client RM/COBOL file manager. If you route all of your I/O through RM/InfoExpress, then, you could use the RM/InfoExpress Server Display utility to determine what user has which files open. This is the only method that we will support. For more information about RM/InfoExpress, please see the RM/InfoExpress User's Guide.
2. Employ a third-party utility that can obtain Windows Networking(SMB) locking information.
3. Implement your own file lock table(s). You could have a shared index file that keeps track of locked files and user accounts. This shared file would be accessed by every runtime that locks/unlocks a file. You could determine who has a file locked by reading this lock table file.
4. Create a C/C subprogram library (DLL) that can provide this information. You can call C subprograms from RM/COBOL, therefore, you could create a subprogram library that would return the file lock information.
5. Implement an optimistic locking scheme in your application. This will eliminate the need to lock files and records will only be locked for limited amounts of time (during the actual writes/updates). Optimistic locking requires you to create a hash of a record and then check the hash when writing/updating to ensure that the record has not changed since it was read. You do not lock the file or record during the read.