INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Jobs from Indeed

Reading Records From An Indexed File

Reading Records From An Indexed File

(OP)
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.


RE: Reading Records From An Indexed File

Quote:

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close