Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading Records From An Indexed File

Status
Not open for further replies.

klophockey

Programmer
May 25, 2016
41
US
There may be a simple (and maybe obvious) answer to this question but I need a definitive answer and not just my guess.

I have an indexed file that I want to read in a Cobol program. I will open the file as Input just to keep things very simple with respect to the status of the file.
I know for certain I can read the file in a couple of ways. One, is by doing a read using the index key. Another is to just read the file 'next record' and it will begin at the beginning of the file.

MY QUESTION - IS IT ALLOWED TO JUST READ THE FILE RECORD WITH A SIMPLE READ STATEMENT. I would expect the read to put me at the beginning of the file much like the 'Read Next' statement would do if it were used.
The 'Read a record with a key' (Read Filename Key Is File-Key) and 'Read the next record' (Read Filename Next Record) statements work with the file as one would expect

IS THIS A VALID STATEMENT FOR THE FILE DESCRIPTION I HAVE: Read Filex Record

The File Information Is As Follows:
FD Filex.
01 Filex-rec
05 Filex-key Pic 9(3)
05 Filex-data Pic X(127)

Select Filex Assign to FileIn
Organization indexed
Access Dynamic
Record Key Filex-key
Lock mode automatic
Status STATO.


 
IS THIS A VALID STATEMENT FOR THE FILE DESCRIPTION I HAVE: Read Filex Record

Yes - but not recommended.

Since ACCESS DYNAMIC, the READ statement needs to be of the proper form for either sequential or random access.

It is the presence of the NEXT or PREVIOUS keyword that signals 'read sequential'. A sequential read is based on the concept of a file position indicator that is established at OPEN time, or by a START statement.

It is the presence of the KEY phrase that signals a 'read random'. If the KEY phrase is omitted and the NEXT/PREVIOUS keywords are also omitted, the default is a random read using the primary key. It is this default behavior that makes the statement valid, but your colleagues may not like you for omitting the KEY phrase (which makes the code more easily understood). The key value in the record area is used to locate the record. An INVALID KEY phrase is strongly recommended.

Tom Morrison
Hill Country Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top