Bypassing a Locked Record, Take Two
January 7, 2009 Hey, Ted
I have a slightly different solution to the locked record problem your friends tackled in Bypassing a Locked Record. Like them, I have RPG programs that sequentially read a file and update some of the records. When a program tries to read a record that another job has locked, I sometimes bypass the locked record. Here’s how. Notice the READ operation in the second calculation of this example: FSomeFile UF E K Disk Prefix(SR_) D Forever S N inz(*On) D Open C Const(' ') D Closed C Const('Z') /Free DoW Forever; Read(E) SomeRec; If %Eof(SomeFile); Leave; EndIf; If %Error(); Read(N) SomeRec; Iter; EndIf; If SR_Status = Open and SR_Balance = *Zero; Eval SR_Status = Closed; Update SomeRec %Fields(SR_Status); EndIf; EndDo; Eval *InLR = *On; Return; /End-Free The READ includes an E extender, which tells the RPG compiler not to stop if the read ends in error. After the READ and the usual check for end-of-file, I use the %ERROR built-in function to trap the locked records. If the read failed, I read again, but this time without a lock. This second read allows me to move the file pointer to the next record. In this example, I didn’t verify that the read error was caused by a lock. If you need to get that granular, check the %STATUS built-in function for a value of 1218. Thanks for writing about record locking. It’s a big deal in my shop. –Don Thanks for the example, Don. We’ve run several tips about record locking, and I have more to cover when I can get to it. –Ted RELATED STORIES Readers Insights and Feedback: Dealing with Record Locks
|
The two links to Bypassing a Locked Record don’t work.
I coded the record lock skip above and is not working? It is caught in a loop…