# File I/O using OpenCOBOL on GNU/Linux

**URL:** <https://community.openmainframeproject.org/t/file-i-o-using-opencobol-on-gnu-linux/1583>\
**Category:** COBOL technical questions\
**Created:** [April 11, 2020, 9:13pm UTC](https://community.openmainframeproject.org/t/file-i-o-using-opencobol-on-gnu-linux/1583 "2020-04-11T21:13:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bdr](https://avatars.discourse-cdn.com/v4/letter/b/7c8e57/32.png) [@bdr](https://community.openmainframeproject.org/u/bdr)\
**Post date:** [April 11, 2020, 9:13pm UTC](https://community.openmainframeproject.org/t/file-i-o-using-opencobol-on-gnu-linux/1583/1 "2020-04-11T21:13:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![wndavis](https://avatars.discourse-cdn.com/v4/letter/w/ccd318/32.png) [@wndavis](https://community.openmainframeproject.org/u/wndavis)\
**Post date:** [April 12, 2020, 9:24pm UTC](https://community.openmainframeproject.org/t/file-i-o-using-opencobol-on-gnu-linux/1583/2 "2020-04-12T21:24:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lakshmisudha](https://avatars.discourse-cdn.com/v4/letter/l/a3d4f5/32.png) [@lakshmisudha](https://community.openmainframeproject.org/u/lakshmisudha)\
**Post date:** [April 13, 2020, 8:21am UTC](https://community.openmainframeproject.org/t/file-i-o-using-opencobol-on-gnu-linux/1583/3 "2020-04-13T08:21:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![normant](https://avatars.discourse-cdn.com/v4/letter/n/b5e925/32.png) [@normant](https://community.openmainframeproject.org/u/normant)\
**Post date:** [April 26, 2020, 4:15pm UTC](https://community.openmainframeproject.org/t/file-i-o-using-opencobol-on-gnu-linux/1583/4 "2020-04-26T16:15:10Z")

</div>

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

> <https://stackoverflow.com/questions/33132295/cobol-simple-file-reading-issue>

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

> **[GNUCobol2.pdf](https://gnucobol.sourceforge.io/guides/GNUCobol2.pdf)**
>
> 4.11 MB
