File I/O using OpenCOBOL on GNU/Linux

Hello, I am learning COBOL and am having trouble reading and writing to files.

From my understanding it works something like this


ENVIRONMENT DIVISION.
INPUT OUTPUT SECTION.
FILE-CONTROL.
SELECT RRR ASSIGN TO FILE.

DATA DIVISION.
FILE SECTION.
FD RRR.

PROCEDURE DIVISION.
OPEN EXTEND RRR.
WRITE “Information”.
END-WRITE.
CLOSE RRR.


I am having trouble getting the file to link. I have seen some documentation saying that the JCL must link to the actual file. I am compiling using OpenCOBOL on a GNU/Linux system so I am not doing anything with JCL. Do I have to emulate a mainframe running JCL to get this to work? Is there any way to get it to work in my environment? What kind of file formats are supported? Thank you.

It looks like you’re missing the Identification Division.
You also will need a shell script to assign the logical file names in the program to physical file names in the file system.
I can’t provide more detail at this point as I haven’t looked at this stuff for a couple decades. This should give yo a lead to research if you have yet to figure it out.

Hi,
Welcome to the world of COBOL.
Please try simple programs before you venture in to files.
one sample
*> setup the identification division
IDENTIFICATION DIVISION.
*> setup the program id
PROGRAM-ID. HELLO.
*> setup the procedure division
PROCEDURE DIVISION.
*> print a string
DISPLAY 'Hello '.
*> end our program
STOP RUN.
What is the COBOL Compiler you are using? Only for mainframe COBOL programs, JCL is needed. Not for the one, that you are using.
Regards,
Lakshmisudha

If you want to deal with structured files this may clear up some misconceptions and start you on the right path:

Alternatively, if you want to deal with unstructured streams then you can scrap the SELECT, FD, OPEN, WRITE and CLOSE statements and use subroutines instead. Have a look at page 10-109 in here for details