Wednesday, November 4, 2009

Bypassing a Locked Record, Take Two

Bypassing a Locked Record, Take Two

.

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.

No comments: