skip to main content

Procedure Division Statements : READ

READ
General Format
Format 1
READ File-Name-1  [NEXT    ] RECORD  
  [ WITH [NO    ] LOCK ] 
  [ INTO Identifier-1 ] 
  [ SIZE Identifier-2 ] 
  [ AT END Imperative-Statement-1 ] 
  [ NOT AT END Imperative-Statement-2 ] 
  [END-READ]
Format 2
READ File-Name-1 RECORD  
  [ WITH [NO    ] LOCK ] 
  [ INTO Identifier-1 ] 
  [ KEY IS Record-Key-Name-1 ] 
  [ INVALID KEY Imperative-Statement-3 ] 
  [ NOT INVALID KEY Imperative-Statement-4 ] 
  [END-READ]
Syntax rules
All Formats
1.
A.
B.
2.
3.
4.
Format 1
5.
6.
7.
8.
9.
Format 2
10.
11.
12.
General rules
All Formats
1.
2.
3.
4.
A.
B.
 
If the execution of a READ statement with the INTO phrase is unsuccessful, the content of the data item referenced by identifier-1 is unchanged and item identification of the data item referenced by identifier-1 is not done.
5.
6.
7.
8.
A.
B.
C.
D.
E.
9.
A.
B.
C.
D.
a lock is not acquired on the read record, unless iscobol.file.index.read_lock_test (boolean) * is set to true in the configuration. In such case, a lock is acquired just to test the record status, then it’s immediately released.
10.
A.
B.
i.
ii.
C.
11.
12.
13.
Format 1
14.
15.
A.
B.
C.
i.
ii.
 
NOTE - For OPEN, this means that you normally get the first record in the file for sequential or relative and normally get an at end condition for indexed.
D.
E.
i.
a.
b.
ii.
a.
b.
 
If a record is found that satisfies this general rule and other general rules for the READ statement, the record is made available in the record area associated with file-name-1 unless the RELATIVE KEY clause is specified for file-name-1 and the number of significant digits in the relative record number of the selected record is larger than the size of the relative key data item. In that case, the I-O status value associated with file-name-1 is set based on your iscobol.file.status * setting, the at end condition exists, the file position indicator is set to indicate that no next or previous logical record exists, and execution proceeds.
 
NOTE - Except in the case of an indexed file, the record made available may have a length of zero.
 
If no record is found that satisfies the above rules, the file position indicator is set to indicate that no next or previous logical record exists, the I-O status value associated with file-name-1 is set based on your iscobol.file.status * setting, the at end condition exists, and execution proceeds.
 
If a record is made available, the file position indicator is updated as follows:
A.
B.
C.
16.
A.
B.
C.
D.
 
When the at end condition exists, execution of the READ statement is unsuccessful.
17.
18.
19.
The I-O status for the file connector referenced by file-name-1 is set based on your iscobol.file.status * setting if the execution of the READ statement is successful, an indexed file is being sequentially accessed, the key of reference is an alternate record key, and one of the following is true:
A.
B.
20.
Format 2
21.
22.
23.
24.
25.
Examples
Format 1- Read next record sequentially validating when end of file is reached
read customers next
     at end display message "EOF has been reached"
            set customers-eof to true
     not at end display cust-code
Format 1 - Read previous record sequentially validating when top of file is reached
read customers previous
     at end display message "TOF has been reached"
            set customers-tof to true
     not at end display cust-code
Format 2 - Read record by primary key, checking for invalid key
move 1234 to cust-code 
read customers
     invalid key display message "Customer Code : " cust-code " not found!"
     not invalid key display message "Successful Read"
Format 2 - Read record by alternate key, checking for invalid key
move "Smith" to cust-last-name
read customers key cust-last-name
     invalid key display message "Customer Last Name : " cust-last-name " not found!"
     not invalid key display message "Successful Read"
Read record and put the contents on different variable
read customers into ws-first-customer
read customers next into ws-last-customer
Read record with no lock
read customers with no lock
read customers next with no lock

Copyright (c) 2017 Veryant
Contact us
Please share your comments on this manual or on any
Veryant product documentation with the email button at the top left