- COBOL Tutorial
- COBOL - Home
- COBOL - Overview
- COBOL - Environment Setup
- COBOL - Program Structure
- COBOL - Basic Syntax
- COBOL - Data Types
- COBOL - Basic Verbs
- COBOL - Data Layout
- COBOL - Conditional Statements
- COBOL - Loop Statements
- COBOL - String Handling
- COBOL - Table Processing
- COBOL - File Handling
- COBOL - File Organization
- COBOL - File Access Mode
- COBOL - File Handling Verbs
- COBOL - Subroutines
- COBOL - Internal Sort
- COBOL - Database Interface
- COBOL Useful Resources
- COBOL - Questions and Answers
- COBOL - Quick Guide
- COBOL - Useful Resources
- COBOL - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
COBOL - File Organization
File organization indicates how the records are organized in a file. There are different types of organizations for files so as to increase their efficiency of accessing the records. Following are the types of file organization schemes −
- Sequential file organization
- Indexed sequential file organization
- Relative file organization
The syntaxes in this module, mentioned along with their respective terms, only refer to their usage in the program. The complete programs using these syntaxes would be discussed in the chapter 'File handling Verbs'.
Sequential File Organization
A sequential file consists of records that are stored and accessed in sequential order. Following are the key attributes of sequential file organization −
Records can be read in sequential order. For reading the 10th record, all the previous 9 records should be read.
Records are written in sequential order. A new record cannot be inserted in between. A new record is always inserted at the end of the file.
After placing a record into a sequential file, it is not possible to delete, shorten, or lengthen a record.
Order of the records, once inserted, can never be changed.
Updation of record is possible. A record can be overwritten, if the new record length is same as the old record length.
Sequential output files are good option for printing.
Following is the syntax of sequential file organization −
INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT file-name ASSIGN TO dd-name-jcl ORGANIZATION IS SEQUENTIAL
Indexed Sequential File Organization
An indexed sequential file consists of records that can be accessed sequentially. Direct access is also possible. It consists of two parts −
Data File contains records in sequential scheme.
Index File contains the primary key and its address in the data file.
Following are the key attributes of sequential file organization −
Records can be read in sequential order just like in sequential file organization.
Records can be accessed randomly if the primary key is known. Index file is used to get the address of a record and then the record is fetched from the data file.
Sorted index is maintained in this file system which relates the key value to the position of the record in the file.
Alternate index can also be created to fetch the records.
Following is the syntax of indexed sequential file organization −
INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT file-name ASSIGN TO dd-name-jcl ORGANIZATION IS INDEXED RECORD KEY IS primary-key ALTERNATE RECORD KEY IS rec-key
Relative File Organization
A relative file consists of records ordered by their relative address. Following are the key attributes of relative file organization −
Records can be read in sequential order just like in sequential and indexed file organization.
Records can be accessed using relative key. Relative key represents the record’s location relative to the address of the start of the file.
Records can be inserted using relative key. Relative address is calculated using relative key.
Relative file provides the fastest access to the records.
The main disadvantage of this file system is that if some intermediate records are missing, they will also occupy space.
Following is the syntax of relative file organization −
INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT file-name ASSIGN TO dd-name-jcl ORGANIZATION IS RELATIVE RELATIVE KEY IS rec-key