1

Here is my problem: I have a READE in a loop In this loop, I can update the record or not, depending on a condition.

In this situation: I've red the last record of the sequence, it's locked It doesn't satisfy the condition, so it isn't updated, so it isn't unlocked The program tries to read the next record, it isn't successful, but...

My question is: does it free the lock for the other record or not?

FredericP
  • 1,119
  • 1
  • 14
  • 27

2 Answers2

3

In fact yes, the record is unlocked after the unsuccessful read... I had little time to create a dirty test for that: the program

Fp1facll1  UF   E           k DISK                                       
D*                                                                       
Dexcmd            s            250    inz('DLYJOB DLY(10)')              
Dexlg             s             15P 5 inz(250)                           
C*                                                                       
C                   move      'F012'        adqtc4                       
C     adqtc4        setll     p1facll1                                   
C     adqtc4        reade     p1facll1                               58  
C     *in58         downe     '1'                                        
C* Update never occurs                                                   
C                   if        '0'                                        
C                   update    MEFRESM                                    
C                   endif                                                
C     adqtc4        reade     p1facll1                               58  
C                   enddo                                                
C* Wait indefinitively                                                   
C                   dow       '1'                                        
C                   call      'QCMDEXC'                                  
C                   parm                    excmd                         
C                   parm                    exlg                         
C                   enddo                                                
C                   SETON                                        LR      

Launched the first time (by SBMJOB) enters in the infinite wait loop (normal). Without ending the program, I launched it a second time, end it enters too the infinite loop, proving that the first one didn't lock the last record that it succesfully red, otherwise it should had a read-error

FredericP
  • 1,119
  • 1
  • 14
  • 27
  • I'd like to believe that this is so, but what then is the purpose of the UNLOCK opcode when used on a file? In what cases would it hold the record as locked? – Mike Nov 06 '19 at 16:06
  • 2
    If I read just one record and don't update, then the UNLOCK is to be used to free the record (if the program is still alive). In this case, the program tried to read another record, so it unlocked the other one (and probably _before_ reading) – FredericP Nov 06 '19 at 16:09
0

No. Use UNLOCKto free your record.

Dam
  • 986
  • 1
  • 14
  • 20