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 - 4109 days ago
Last viewed on: 24 Apr 2024 (10440 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)

Well, figured the best way to try out the new forums is to list a problem and see how it goes.  1st off . . . the code I pasted in from RDp isn't quite ledgible, so I'm fixing that.

Below is some pretty standard code in the JDE applications which I *thought* would bypass a locked record.  Apparently it does NOT!  I thought the ITER here would cause the next record to be read, but what I'm seeing in the debugger is that the cursor is sitting on the same record and trying and retrying to read that one locked record, sigh. 

What the heck is that 2nd indicator for if this sort of logic won't work? 

Bob - in reading your book, it's very clear what is suppose to happen on a read, but I'm not finding anything addressing this simple, common record lock issue.  Is there an easy remedy for this or am I going to have to do a pssr type of routine to try and kick the cursor down a knotch?

This program needs to update the target record, but it's not urgent.  This runs in batch everynight and is ok if it skips the locked record and picks it up the next time . . . but I can't get it to skip LO

 ~ suprized and somewhat frustrated ~ Carol

 

C   *IN99 DOUEQ *ON

C            READ F55634LB                      9699

  

C   *IN99 IFEQ *ON

C            LEAVE

C            ENDIF

 

 

C    *IN96 IFEQ *ON

C             ITER

C             ENDIF

~ do processing

C             ENDDO

 

PS ~ YES I know this is old freaking code and s/b rewritten, but we have a gigaton of this code around that has been working for eons (errrr well we *thought* it was working!) and no time to rewrite it all now . . . so do please bear with me :p

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: 12 years 7 months 23 days 3 hours 37 minutes ago
Edited: Sun, 04 Sep, 2011 at 10:18:10 (4616 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: 12 years 7 months 21 days 13 hours 40 minutes ago
Edited: Sun, 04 Sep, 2011 at 09:28:31 (4616 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.