Master Mainframe Technologies - COBOL, JCL, DB2, VSAM, CICS & More
ABEND Codes SQLCODEs File Status Interview Prep Contact
💻 COBOL

COBOL FILE HANDLING - Sequential Files

Intermediate 🕑 10 min read 👁 0 views

20

Code Example


## COBOL Sequential File Handling

Sequential files are processed record by record, from beginning to end. This is the most common file organization in mainframe COBOL.

### File Control Entry (SELECT)

\`\`\`cobol
SELECT file-name ASSIGN TO ddname
    ORGANIZATION IS SEQUENTIAL
    ACCESS MODE IS SEQUENTIAL
    FILE STATUS IS ws-file-status.
\`\`\`

### FD Entry

\`\`\`cobol
FD file-name
    RECORDING MODE IS F/V/FB/VB
    BLOCK CONTAINS n RECORDS
    RECORD CONTAINS n CHARACTERS.
01 record-name.
    05 field-1    PIC X(10).
    ...
\`\`\`

### File Operations

1. **OPEN**: INPUT, OUTPUT, I-O, EXTEND
2. **READ**: Get next record
3. **WRITE**: Add record
4. **REWRITE**: Update current record (I-O mode)
5. **CLOSE**: End file processing

### File Status Codes

- 00: Successful
- 10: End of file
- 35: File not found
- 39: File attribute mismatch

### Best Practices

- Always check FILE STATUS after each I/O operation
- Use 88-level for EOF condition
- Close files before program ends