File organization and input-output devices
Depending on the input-output devices, your file organization can be sequential, line sequential, indexed, or relative. Decide on the file types and devices to be used when you design your program.
You have the following choices of file organization:
- Sequential file organization
- The chronological order in which records
are entered when a file is created establishes the arrangement of
the records. Each record except the first has a unique predecessor
record, and each record except the last has a unique successor record.
Once established, these relationships do not change.
The access (record transmission) mode allowed for sequential files is sequential only.
- Line-sequential file organization
- Line-sequential files are sequential files that reside in the z/OS® UNIX file system and that contain only characters
as data. Each record ends with a newline character.
The only access (record transmission) mode allowed for line-sequential files is sequential.
- Indexed file organization
- Each
record in the file contains a special field whose contents form the
record key. The position of the key is the same in each record. The
index component of the file establishes the logical arrangement of
the file, an ordering by record key. The actual physical arrangement
of the records in the file is not significant to your COBOL program.
An indexed file can also use alternate indexes in addition to the record key. These keys let you access the file using a different logical ordering of the records.
The access (record transmission) modes allowed for indexed files are sequential, random, or dynamic. When you read or write indexed files sequentially, the sequence is that of the key values. When you read or write indexed files randomly, the sequence is in a programmer-specified manner. When you read or write indexed files dynamically, the sequence is sequential or random or both, determined by the input-output statements used.
- Relative file organization
- Records in the file are identified by
their location relative to the beginning of the file. The first record
in the file has a relative record number of 1, the tenth record has
a relative record number of 10, and so on.
The access (record transmission) modes allowed for relative files are sequential, random, or dynamic. When relative files are read or written sequentially, the sequence is that of the relative record number.
With IBM® Enterprise COBOL for z/OS, requests to the operating system for the storage and retrieval of records from input-output devices are handled by the two access methods QSAM and VSAM, and the z/OS UNIX file system.
The device type upon which you elect to store your data could affect the choices of file organization available to you. Direct-access storage devices provide greater flexibility in the file organization options. Sequential-only devices limit organization options but have other characteristics, such as the portability of tapes, that might be useful.
- Sequential-only devices
- Terminals,
printers, card readers, and punches are called unit-record devices because
they process one line at a time. Therefore, you must also process
records one at a time sequentially in your program when it reads from
or writes to unit-record devices.
On tape, records are ordered sequentially, so your program must process them sequentially. Use QSAM physical sequential files when processing tape files. The records on tape can be fixed length or variable length.
- Direct-access storage devices
- Direct-access storage devices
hold many records. The record arrangement of files stored on these
devices determines the ways that your program can process the data.
When using direct-access devices, you have greater flexibility within
your program, because you can use several types of file organization:
- Sequential (VSAM or QSAM)
- Line sequential (z/OS UNIX)
- Indexed (VSAM)
- Relative (VSAM)