COBOL - File Handling - COBOL Tutorial
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:
05 EMPLOYEE-ID PIC 9(05).
05 EMPLOYEE-NAME PIC X(20).
05 EMPLOYEE-GRADE PIC X(01).
05 EMPLOYEE-SALARY PIC 9(10).
Let see the file structure for the above file layout,
What is 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 employee id, employee name,employee grade and employee salary. The number of characters in any field is known as field size.
For example, employee name can have 20 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 employee file, each employee will be having a unique employee 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 employee file, full name of employee can be used as secondary key when employee id is not known.
- Descriptors fields are used to describe an entity. For example, in employee file, employee grade and employee salary that add meaning to the record are known descriptors.
What is 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 employee file, employee id, employee name,employee grade and employee salary 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.
What is File ?
File is a collection of related records. For example, the employee file consists of records of all the employees.
If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!