ibm-midrangerpglerpg

What can be done if we want to update a record locked by other program or application in RPGLE


Suppose I want to update a record , but that record is being locked by some other application or program , what can be done to make sure that I can update that record in the next iteration?


Solution

  • If this program was running in batch and it was critical that the record in question gets updated, you could use the (E) extender on your Chain and monitor for the %Error. Something like this:

    // This record MUST be updated
    Dou %Error = *Off;
      Chain(E) (FileKey) CriticalFile
    Enddo;
    
    // At this point, we've gotten past the file lock
    If %Found(CriticalFile);
      Update CriticalFileRec;
    Endif;
    

    The Do-Until will continuously loop until a successful chain is achieved.