Midrange News for the IBM i Community

Posted by: basticar
Legacy Programmer
San Diego, CA USA
How to get around a simple record lock
has no ratings.
Published: 02 Sep 2011
Revised: 23 Jan 2013 - 2185 days ago
Last viewed on: 16 Jan 2019 (7272 views) 

Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.

How to get around a simple record lock Published by: basticar on 02 Sep 2011 view comments(2)

Return to midrangenews.com home page.
Sort Ascend | Descend


(Sign in to Post a Comment)
Posted by: bobcozzi
Site Admin ****
Comment on: How to get around a simple record lock
Posted: 7 years 4 months 16 days 6 hours 13 minutes ago
Edited: Sun, 04 Sep, 2011 at 10:18:10 (2692 days ago)

Carole, on the toolbar when posting content, there is what looks like a Pencil icon (their choice not mine). To post code, position the cursor where you want the code to appear, then click the Pencil button. Paste your code into the dialog box and select the Language if other than RPG IV. Then press Insert. It will put it into the body of your post and assign the syntax highlighter to its HTML "style" so it colorizes it correctly.

I am doing that below, to illustrate the results.


.....C   *IN99         DOUEQ *ON
     C                 READ F55634LB                      9699
     C   *IN99         IFEQ *ON
     C                 LEAVE
     C                 ENDIF


Posted by: TFisher
Premium member *
Comment on: How to get around a simple record lock
Posted: 7 years 4 months 14 days 16 hours 16 minutes ago
Edited: Sun, 04 Sep, 2011 at 09:28:31 (2692 days ago)

It cannot read the "next" record after the locked record because it hasn't even read the locked record.  To use ITER and read the "next" record you would need to do a SETGT on a key in order to skip over the locked record.  If the file doesn't have a key then you could always read the locked record using 'N' in position 53:


C               *IN99 DOUEQ *ON

C                     READ F55634LB               9699

C               *IN99 IFEQ *ON

C                     READ F55634LB            N    99

C                     ITER

C                     ENDIF


I know you said that the updates are not urgent, but if you ever need a way to update a locked record...I created a batch process and a procedure that we use to "force an update to a locked record".  The application(s) do what I show above (except it's RPG IV).  If the record is locked then we do a READ/CHAIN without locking the record and set on a record locked indicator then go through the code that loads all the new values into the fields.  Then, when it's time to do an update we check the record locked indicator and if t's *ON then we pass the record and the file name to a procedure to later be updated, otherwise we update the record:


  If RecordLocked;

     Callp prUpdateLockedRecord( 'FILENAME' : rcdDS);


     Update Rcd;



This procedure writes the new record to a file where a batch process is waiting.  This batch program reads through that file and does the updates for us when the records are available.  It must compare all the fields so that we don't overlay someone else's updates.


The procedure has a third optional parameter that allows the library name to be passed but we don't use it very often because the procedure will determine the library name if this parameter isn't passed.