Thread: COBOL

How do I write records to an output file?

Started by Jordan • user3 replies189 viewsLast activity 1 week ago
Post #1
0 votes
Jordan
Reputation
12
Posts: 32
Joined: May 2, 2026, 11:10 AM
Posted: Aug 3, 2026, 10:36 AM

I can READ. Writing feels scarier. OPEN OUTPUT then WRITE? What goes wrong if the DD is missing?

Post #2
0 votes
Marty
Reputation
412
Posts: 58
Joined: Aug 12, 2024, 9:14 AM
Posted: Aug 3, 2026, 12:36 PM

OPEN OUTPUT OUT-FILE
MOVE stuff TO out-record
WRITE out-record
...
CLOSE OUT-FILE

Missing DD → bad file status (35/96 depending). Always check status after OPEN and WRITE.

OPEN OUTPUT on an existing dataset can wipe it depending on DISP. Know what your JCL is doing.

Post #3
0 votes
Jen
Reputation
287
Posts: 34
Joined: Sep 3, 2024, 11:02 AM
Posted: Aug 3, 2026, 3:36 PM

For a new file use DISP=(NEW,CATLG,DELETE) with SPACE and DCB that match the FD.

You must be signed in to reply to this thread