Module 5 · Lesson 2 of 210/16 in the course~16 min
Module lessons (2/2)
OPEN, READ (Priming Read), WRITE and CLOSE
Lesson preview5 hands-on exercises readyCourse COBOL · Module 5 — Batch Sequential Files & I/O
Master the INPUT/OUTPUT/EXTEND/I-O modes, the priming read pattern to avoid duplicate records on EOF and writing to records FD.
What you'll learn in this lesson
- Choose the right mode
OPEN:INPUT,OUTPUT,EXTENDorI-O. - Apply the key COBOL distinction: you read a file (
READ SALES-FILE), but you write a record (WRITE SALES-RECORD). - Implement the canonical Priming Read pattern in a
PERFORM UNTIL EOFloop to avoid empty records or last row duplication on EOF.
Overview
Once the file is connected in DATA DIVISION, in PROCEDURE DIVISION the operating cycle of each sequential file always goes through four phases: OPEN → READ/WRITE → CLOSE.
Here is the most counterintuitive golden rule of COBOL I/O:
Sections covered in this lesson
- 11. Opening with
OPEN(INPUT,OUTPUT,EXTEND,I-O) - 22. Reading (
READ <file>) vs Writing (WRITE <record>) - 33. The Canonical Batch Pattern: "Priming Read"
- 44. Secure closing (
CLOSE) andWRITE ... AFTER ADVANCING - 5Try it yourself
Pro Lesson · Module 5 — Batch Sequential Files & I/O
Unlock "OPEN, READ (Priming Read), WRITE and CLOSE" and the full Course COBOL curriculum
Master the INPUT/OUTPUT/EXTEND/I-O modes, the priming read pattern to avoid duplicate records on EOF and writing to records FD.
Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in Course COBOL plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.