Midrange News for the IBM i Community


Posted by: basticar
Legacy Programmer
PriceSmart
San Diego, CA USA
How to get around a simple record lock
has no ratings.
Published: 02 Sep 2011
Revised: 23 Jan 2013 - 1703 days ago
Last viewed on: 22 Sep 2017 (5890 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

COMMENTS

(Sign in to Post a Comment)
Posted by: bobcozzi
Site Admin ****
Chicagoland
Comment on: How to get around a simple record lock
Posted: 6 years 20 days 23 hours 52 minutes ago
Edited: Sun, 04 Sep, 2011 at 10:18:10 (2210 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: 6 years 19 days 9 hours 55 minutes ago
Edited: Sun, 04 Sep, 2011 at 09:28:31 (2210 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);

   Else;

     Update Rcd;

  Endif;

 

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.