COBOL · 2026-10-11

COBOL File Handling Basics: Sequential Files, File Status, and Practical Flow

Learn how COBOL file handling works with SELECT, FD, OPEN, READ, WRITE, CLOSE, and file status checks.

COBOL file handling is one of the first skills every mainframe developer needs. Many batch programs read input files, validate records, apply business rules, and write output files or reports. The structure looks old compared with modern APIs, but the idea is simple: define the file, open it, process records one by one, and close it safely.

Why file handling matters

In enterprise systems, files often carry daily transactions, customer updates, claim records, policy details, or reconciliation data. A small mistake in file handling can create duplicate processing, skipped records, or production abends. That is why COBOL programs usually combine file operations with return-code handling and audit counts.

Core COBOL sections

A typical file program uses:

Example pattern:

SELECT INPUT-FILE ASSIGN TO INFILE
    ORGANIZATION IS SEQUENTIAL
    FILE STATUS IS WS-IN-STATUS.

The DD name INFILE is normally supplied in JCL. This separation allows the same program to run against different physical files without recompiling.

Basic processing flow

A clean batch flow is:

1. Initialize counters and working fields.
2. Open input and output files.
3. Read the first input record.
4. Process until end-of-file.
5. Write valid output records.
6. Close all files.
7. Display processing counts.

In production, counters are not optional. They help support teams confirm how many records were read, processed, rejected, and written.

File status codes

The FILE STATUS clause is important because it gives a two-character status after file operations. Common values:

A beginner mistake is to check only end-of-file and ignore other statuses. Good programs validate every important operation.

Practical guidance

For production-ready COBOL file handling:

Conclusion

COBOL file handling is not just syntax. It is a disciplined batch-processing pattern. Once you understand file definition, file status, and record-loop structure, many mainframe programs become much easier to read and maintain.

← Back to all articles