Javatpoint Logo
Javatpoint Logo

COBOL - File Handling

COBOL also supports file handling like C/C++ languages, but the file concept is distinct from the C or C++. In COBOL, we can't use simple text files. COBOL uses PS and VSAM files (Physical Sequential). We're going to talk about PS files here.

The basic terms must be known in order to understand the concept of file handling in COBOL. These terms only help to understand the basics of file handling. Let's understand the following terms:

  • Field
  • Record
  • Physical Record
  • Logical Record
  • File
COBOL File Handling
COBOL File Handling


The field is used to indicate the data stored about an element. It represents a single element as given 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 ten characters. Fields can have the following attributes:

Primary Keys

Primary keys are those fields that are unique to each record and are used to identify a particular record. For example, in the above example, student id is the primary key.

Secondary Keys

Secondary keys are unique or non-unique fields that are used to search the related data. For example, in the above example, the student name is the secondary key when the student id not available.


Fields are used to describe an entity. For example, in the above student marks file example, marks and percentage fields that add meaning to the record are descriptors.


Record is a set of fields used to describe an entity. A record is formed by one or more fields together. For example, in the above student marks file, student id, name, marks, total marks, and percentage make one record. The record size is defined as the total size of all fields in a record. The size of records in a file may be fixed length or variable length.

Physical Record: This is the external device information that exists. It is called a block as well.

Logical record: This is the program's information. Just one record can be managed in COBOL programs at one time.


The file is a collection of related records. For example, the above student's marks file consists of records of all the students.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA