Thread: COBOL

How do I read a sequential file in COBOL?

Started by Alex • user3 replies320 viewsLast activity 1 week ago
Post #1
0 votes
Alex
Reputation
8
Posts: 35
Joined: Jun 15, 2026, 9:20 AM
Posted: Aug 5, 2026, 9:40 AM

Need the absolute minimum: open a file, read records until end, close.

I have SELECT / FD / WORKING-STORAGE. What does the PROCEDURE DIVISION look like?

Post #2
0 votes
Marty
Reputation
412
Posts: 58
Joined: Aug 12, 2024, 9:14 AM
Posted: Aug 5, 2026, 10:40 AM

Skeleton:

OPEN INPUT IN-FILE
PERFORM UNTIL WS-EOF = 'Y'
READ IN-FILE
AT END MOVE 'Y' TO WS-EOF
NOT AT END PERFORM PROCESS-REC
END-READ
END-PERFORM
CLOSE IN-FILE

Check FILE STATUS after OPEN. Match your DD name to ASSIGN TO.

Post #3
1 votes
Anita
Reputation
118
Posts: 23
Joined: May 29, 2025, 12:45 PM
Posted: Aug 5, 2026, 1:40 PM

Do not forget END-READ and END-PERFORM. Missing those caused my first weird compile.

You must be signed in to reply to this thread