File Handling in COBOL
Introduction
- Logical representation of data stored in memory location is known as file.
- In a mainframe environment, files are normally stored in DISK/TAPES.
- In COBOL program, maximum 255 files are used.
- ORGANIZATION Clause is used to define a file.
Hierarchy of file
Hierarchy of the file consists of following basic terms:
1) Field
Following are the attributes of field:
i) Primary key – This is the unique key and used to recognize the particular record.
For example, each employee having an unique employee id and it forms the primary key for unique identification.
ii) Secondary keys – These keys are unique or non-unique fields which are used to search for related data.
iii) Descriptors – These fields are used to describe an entity.
2) Record
- The record is a collection of the field used to describe an entity.
- A combination of one or more fields known as Record.
For example, In EMP-INFO file, EMP id, name and designation form one record.
3) Physical record
- Physical record is the information which exists on the external device. It is also called as a block.
4) Logical record
- The information used by the program is the logical record.
5) File
- A collection of related records is known as a File.
For example, in the EMP-INFO file consists of record of all employees.