File Handling

The concept of files in COBOL is different from that in C/C++. While learning the basics of ‘File’ in COBOL, the concepts of both languages should not be corelated. Simple text files cannot be used in COBOL, instead PS (Physical Sequential) and VSAM files are used. PS files will be discussed in this module.

To understand file handling in COBOL, one must know the basic terms. These terms only serve to understand the fundamentals of file handling. Further in depth terminology would be discussed in the chapter ‘File Handling Verbs’. Following are the basic terms −

  • Field
  • Record
  • Physical Record
  • Logical Record
  • File

The following example helps in understanding these terms −

Program Structure

Field

Field is used to indicate the data stored about an element. It represents a single element as shown in the above example such as student id, name, marks, total marks, and percentage. The number of characters in any field is known as field size, for example, student name can have 10 characters. Fields can have the following attributes −

  • Primary keys are those fields that are unique to each record and are used to identify a particular record. For example, in students marks file, each student will be having a unique student id which forms the primary key.
  • Secondary keys are unique or non-unique fields that are used to search for related data. For example, in students marks file, full name of student can be used as secondary key when student id is not known.
  • Descriptors fields are used to describe an entity. For example, in students marks file, marks and percentage fields that add meaning to the record are known descriptors.

Record

Record is a collection of fields that is used to describe an entity. One or more fields together form a record. For example, in students marks file, student id, name, marks, total marks, and percentage form one record. The cumulative size of all the fields in a record is known as the record size. The records present in a file may be of fixed length or variable length.

Physical Record

Physical record is the information that exists on the external device. It is also known as a block.

Logical Record

Logical record is the information used by the program. In COBOL programs, only one record can be handled at any point of time and it is called as logical record.

File

File is a collection of related records. For example, the students marks file consists of records of all the students.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *