Hello, I am learning COBOL and am having trouble reading and writing to files.
From my understanding it works something like this
INPUT OUTPUT SECTION.
SELECT RRR ASSIGN TO FILE.
OPEN EXTEND 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.
Welcome to the world of COBOL.
Please try simple programs before you venture in to files.
*> setup the identification division
*> setup the program id
*> setup the procedure division
*> print a string
DISPLAY 'Hello '.
*> end our program
What is the COBOL Compiler you are using? Only for mainframe COBOL programs, JCL is needed. Not for the one, that you are using.
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