File Organization Interview Questions


What is the file organization?

File organization is the method used to store and arrange data records within a file. It specifies how information is physically stored in the memory and impacts how efficiently data can be accessed and managed.

What are the file organizations supported by COBOL?

COBOL primarily supports three types of file organizations -

  • Sequential File Organization
  • Indexed File Organization
  • Relative File Organization

How will you define a sequential file in COBOL?

Sequential file organization applies to the sequential files (PS - Physical sequential file) that use the QSAM access method. Example - Declaring a sequential file in program.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
    SELECT empfile ASSIGN TO input01
    ORGANIZATION IS SEQUENTIAL

How will you define an indexed file in COBOL?

Indexed file organization applies to the KSDS file that uses the Virtual storage access method (VSAM). Example - Declaring indexed file in program with key emp-no and alternate key emp-dept.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
    SELECT empfile ASSIGN TO input01
    ORGANIZATION IS INDEXED
	RECORD KEY IS emp-no
	ALTERNATE KEY IS emp-dept

How will you define relative file in COBOL?

Relative file organization applies to the RRDS file that uses the Virtual storage access method (VSAM). Example - Declaring Relative file in program with key emp-rrn.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
    SELECT empfile ASSIGN TO input01
    ORGANIZATION IS RELATIVE
	RELATIVE KEY IS emp-rrn

What are the problems associated with using ordered sequential files?

Newly writing records are not placed in the order if the file is already ordered.

How do you work with external files in COBOL?

When an EXTERNAL file is defined in multiple COBOL programs, once it is opened by one of these COBOL programs, it is accessible to all of the programs.

What is the difference between a sequential, indexed and relative files in COBOL?

Sequential Files Indexed Files Relative Files
Sequential files are QSAM files. Indexed files are VSAM files. Relative files are VSAM files (RRDS).
Records are written in entry sequential order. Records are written in key sequential order. Records are written in Record Relative Number order.
Duplicate records are allowed to be written into the file. Duplicate records are not allowed to be written into the file. Duplicate records are not allowed to be written into the file.
Records need not be in sorted order. Records are in sorted order based on key. Records are in sorted order based on RRN.
Record deletion is not possible. Records deletion is possible. Records deletion is not possible, but the memory will not reused.
Accessing records is slow because the records can only be read in sequential order. Accessing records is faster because the records can be read dynamically or randomly. Accessing records is faster than indexed files as the records can be read using RRN.
The key concept is not available. The key is available. The key is user-defined and is part of the record. The key is available. The key is system-generated and is outside of a record.
Data can be stored on tape/disk. Data can be stored on disk only. Data can be stored on disk only.
File opening modes are – INPUT, OUTPUT, I-O, and EXTEND. File opening modes are – INPUT, OUTPUT, and I-O. File opening modes are – INPUT, OUTPUT, and I-O.
Sequential files are used frequently. Indexed files are frequently used. Relative files are used very rarely.

Frequently Asked Questions -

What are the different File organisations in COBOL?
What are the different types of file organizations available?

How will you define an index and relative file in COBOL?

Give the importance of Sequential, Index, relative files in real time?