FILE is a logical representation of the data that stored in memory location. FILEs used to store the data permanently in a structured format. FILE contains RECORDs that logically divides the FILE data. Each RECORD contains the FIELDs that are typically data items or identifiers in the RECORD definition. FILEs usually store on DISKS/TAPES in mainframe environment. Maximum 255 files used in a COBOL program.

Hierarchy of file -

Files Heirarchy

From the above hierarchical representation, files define as a set of records that are stored as a instances/occurrence. Records defined as a combination of fields that are defined a sequence. Fields defined as a collection of information that requires to be frames in structure.

Types of Files -

FILEs divided into three types based on how the data stored and how the data accessed -

  • Sequential files (data entered in sequential order)
  • Indexed files (data entered based on key sequential order)
  • Relative files (data entered based on Relative Record Number (RRN))

Sequential Files -

Records are stored in the same order how they have written into the file. Records should read sequentially and random or dynamic reading is not possible. Sequential files are also called as flat files or QSAM files or non-VSAM files.

Indexed Files -

Records are stored and arranged based on the key value. Data accessing is faster in indexed files. Random accessing of record is possible based on key.

Duplicate records are not allowed in indexed files. Sequential, random and dynamic accessing modes possible in index files. Indexed file is can't store on tape and stores only on disk.

Key data item should not be updated. Record deletion is possible in indexed files. Indexed files are also called as VSAM files or KSDS files.

Relative Files -

Records are stored and arranged based on the key Relative Record Number. Random accessing of record is possible based on key. Sequential, random and dynamic accessing modes possible. Key data item should not be updated.

Record deletion is possible in relative files but not reused. RRN is not used defined and automatically defines by the system. Retrieving of data is very difficult in relative files. Relative files are also called as RRDS files.

Disadvantages of relative files -

  • Retrieving of RRN is practically impossible.
  • Whenever we delete any record from a relative file, unused storage space is created and can't be reused.

File Processing Life Cycle -

File processing life cycle describes about the processing steps in various phases of the COBOL program. File processing life cycle has mainly 4 different phases. Those are -

  • File Declaration - Any file that requires processing through COBOL application program, it should declare with all its characteristics in the program.
  • File Open - Opens a file before performing any kind of processing on files like read, write or re-write etc.
  • File Processing - File processing like file reading, record writing, record modifying, record deletion etc.
  • File Close - The CLOSE statement terminates the processing of files.

File Handling Statements -

The file handling statements are specified below –

StatementDescription
OPEN Opens a file before performing any kind of processing on files like read, write or re-write etc.
READ Used to read the records from the file.
WRITE Used to write a record to the file.
REWRITE Used to update the records that are already existed in the file.
DELETE Removes a record from an indexed or relative file.
START Used to set the file pointer to read the next record.
READ NEXT Used to read the next records from the current reading position of the file.
READ PREVIOUS Used to read the previous records from the current reading position of the file.
RELEASE Transfers records from an input/output area to the sorting operation initial phase.
CLOSE Terminates the processing of volumes and files.