Skip to main content

Problem:

When I read a record WITH LOCK, I would like to be able to re-write the same record without releasing the lock.  My understanding is that the re-write releases the lock, so I execute another read with lock immediately after the rewrite.  Is this possible, and if so, what is the proper syntax?

Resolution:

If you use single record locking in your program, a rewrite of a record that has just been read with lock will then be unlocked.

Therefore, you should use multiple record locking if you want a rewrite following a read to keep the record locked. You can then use the UNLOCK statement to release the lock. You will have to do a READ WITH KEPT lock in this scenario.

If you rewrite a record that was read without a lock, you would have to compile with the WRITELOCK compiler directive in order for the REWRITE to keep a lock on the record.

The attached project has a cobol.txt file with that directive so that you can test WRITELOCK by changing the file name to cobol.dir and rebuilding (Rebuild All) the app. Run 2 instances of this program outside of the Net Express IDE to test locking. A file status of 9/068 will indicate that a record is locked.

Attachments:

RewriteLock.zip

Old KB# 4038

#ServerExpress
#RMCOBOL
#COBOL
#netexpress
#AcuCobol