TSO-ISPF JCL COBOL VSAM DB2 CICS Tools Articles Job Portal Forum Quiz Interview Q&A

COBOL - File Organization

File organization indicates how the records are organized in a file. 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:
  1. 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.

  2. Line-sequential file organization

    • Line-sequential files are sequential files that reside on the hierarchical file system (HFS) 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.

  3. 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.

  4. 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.

Choosing file organization and access mode:

There are several guidelines you can use to determine which file organization and access mode to use in an application.

Consider the following guidelines when choosing file organization:
  • If an application accesses records (whether fixed-length or variable-length) only sequentially and does not insert records between existing records, a QSAM or VSAM sequential file is the simplest type.

  • If you are developing an application for UNIX that sequentially accesses records that contain only printable characters and certain control characters, line-sequential files work best.

  • If an application requires both sequential and random access (whether records are fixed length or variable length), a VSAM indexed file is the most flexible type.

  • If an application inserts and deletes records randomly, a relative file works well.

Consider the following guidelines when choosing access mode:
  • If a large percentage of a file is referenced or updated in an application, sequential access is faster than random or dynamic access.

  • If a small percentage of records is processed during each run of an application, use random or dynamic access.

Summary of file organizations, access modes, and record formats of COBOL files

File organizationSequential accessRandom access Dynamic accessFixed lengthVariable length
QSAM (physical sequential)X XX
Line sequential X XX
VSAM sequential (ESDS) X XX
VSAM relative (RRDS) XXXXX

If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!

Are you looking for Job Change? Job Portal