7 years ago I did some testing with Open COBOL. I wanted to see how well it implemented COBOL and do some performance testing as well. As I recall, the implementation was lacking a bit, but I was still able to write some decent performance testing code.
I’ve been looking into COBOL again, just for fun, and decided to review the current state of the compiler. I would also like to do some performance testing and see if / how it integrates with SQLITE.
Just to make my life easier, I want to start with a Windows installation of gnuCOBOL though I may decide Linux is a better choice for my testing. So this post records my installation of the compiler.
Open COBOL is now gnuCOBOL
I didn’t look into the reasoning (legal I presume), but Open COBOL has become gnuCOBOL. From this point forward, any reference I make to COBOL is gnuCOBOL.
Locating the Compiler
See Jun 2020 update at the end of this post for a better location for Windows binaries.
gnuCOBOL is located on sourceForge.net. But I found that the default download for windows, like Linux, does not include a binary of the compiler.
Compiling projects on Linux isn’t tyically too bad, but Windows is a whole other beast. I just want a binary, I don’t want to have to build the compiler for Windows and deal with the whole Window/Linux/minGW compilation mess.
What I discovered is if you go to nightly_snapshots, there is a windows binary for gnuCOBOL 3.1.
In case that binary goes away, I have put a copy here BUT it will be as of this writing so use nightly_snapshots if you have a choice.
Note that this compilation does not include indexed file support.
Installing the Compiler
- Unzip the distribution file. I unzip into c:\gnuCOBOL and my examples will assume that location.
- In c:\gnuCOBOL\bin you will find various EXE files particularly cobc.exe and cobcrun.exe:
- In System Properties | Environment Variable you need to add the path c:\gnucobol\bin:
- In CMD at C:\, cobc.exe should work:
C:\>cobc -V cobc (GnuCOBOL) 3.1-dev.0 Copyright (C) 2020 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html> This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Written by Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch, Edward Hart Built May 05 2020 16:26:39 Packaged May 05 2020 15:48:49 UTC C version (MinGW) "5.3.0" C:\>
Setting Up a BAT File
There are parameters you’ve got to pass to the compiler every time. It is easiest just to have a bat file. I’ll call mine COBOL.BAT and simply put it into c:\gnucobol\bin.
C:\gnuCOBOL\bin>type cobol.bat @echo off rem Compile a COBOL program rem are env strings already defined? (tried using () here, but it failed so goto it is if NOT "%COB_MAIN_DIR%" == "" goto cont rem define env strings set COB_MAIN_DIR=c:\gnucobol\ set COB_CONFIG_DIR=%COB_MAIN_DIR%config set COB_COPY_DIR=%COB_MAIN_DIR%copy set COB_CFLAGS=-I"%COB_MAIN_DIR%include" %COB_CFLAGS% set COB_LDFLAGS=-L"%COB_MAIN_DIR%lib" %COB_LDFLAGS% set COB_LIBRARY_PATH=%COB_MAIN_DIR%extras set PATH=%COB_MAIN_DIR%bin;%PATH% :cont rem Start the compiler cobc -x %*
-x indicates the output from the compiler should be an EXE file.
If you want to use the cobc command directly, simply use “cobol -V” once to set up the environment, then cobc can be used directly.
In c:\gnuCOBOL, you will find gnuCOBOL.pdf, a very comprehensive manual of the compiler.
If you want to do a hello world test, here is the code:
C:\gnuCOBOL>type hellow.cob id division. program-id. hellow. procedure division. display 'hello world!'.
Note there are 8 leading spaces on every line and another 4 for the DISPLAY verb. This is how fixed format COBOL code must be written.
Here is the compile and subsequent execution. Note that I use the -t- option during the compile. This will create a compiler output listing.
C:\gnuCOBOL>cobol -t- hellow.cob GnuCOBOL 3.1-dev.0 hellow.cob Tue May 05 13:57:13 2020 Page 0001 LINE PG/LN A...B............................................................ 000001 id division. 000002 program-id. hellow. 000003 procedure division. 000004 display 'hello world!'. 0 warnings in compilation group 0 errors in compilation group C:\gnuCOBOL>hellow hello world!
If you have stumbled across this post because you want to learn COBOL here are a few resources I can give you (and I’ll try to keep this updated when I find others).
The gnuCOBOL manual is very extensive, especially for free software, but most of the time it is pretty terse.
I have found the Unisys manual to be quite well written and it goes into much more detail about the language. Granted gnuCOBOL and Unisys COBOL aren’t exactly the same, but that will probably not be much of a problem. Usually vendor manuals are pretty good about pointing out non-standard extensions.
I am towards the end of taking this udemy.com course:
This is an IBM mainframe-based course. But COBOL is COBOL. All COBOL code shown will work the exact same way in gnuCOBOL.
The list price is $175, I paid $10. For $10 it is a decent course. I would not have been very happy had I paid $175. But I get more from books than videos.
There are several books I used during my career that are, as far as I’m concerned, essential in writing production COBOL code.
The first is The Programmer’s ANSI COBOL Reference Manual, 2nd Edition by Donald A. Sordillo. This book is, of course, out of print and fairly expensive. It is $250-$800 on Amazon and no listing on ebay today. But if you want to code in COBOL, keep watching for this book at a reasonable price. It is the best I ever saw.
My college textbook (yes, I took COBOL in college), is Fundamentals of Structured COBOL Programming by Carl Feingold. You can probably find this for < $20 if you are patient. It only covers the 1974 standard, but as a college level text book it has a very thorough coverage of the language.
Update: I have the 3rd Edition of Fundamentals of Structured Programming. After writing these blog posts for GnuCOBOL I came across the 4th edition for a reasonable price (~ $15) and bought it to compare. The newer edition is bigger in all 3 dimensions. I examined the Report Writer chapters in both books. The newer edition was easier to understand and the page layout was easier to read as well. Still, it only covers COBOL’74.
When I wrote the COBOL standards for the companies I worked for, I used Handbook of COBOL Techniques (Computer Partners, Inc) and COBOL with Style (Louse J. Chmura). These are great books for producing clean code that others can read.
June 2020 Update
The gnuCOBOL binary available from Source Forge doesn’t include ISAM support and for experimentation I really would like ISAM.
I messed around with building my own compiler which was successful, but it took days of messing around. Then I stumbled on Arnold Trembley’s website. He has exact instructions for building the compiler as you want it. More importantly, he keeps various flavors of the recent release available in binary form.
From his website I was able to download
GnuCOBOL 3.1-dev r3577 (16MAY2020) MinGW compiler for Windows XP/7/8/10 with COBOL ReportWriter. Includes VBISAM 2.0.1 for Indexed Sequential file access support, GMP 6.2.0, and PDCurses 4.1.0 (17.0 megabytes). Rename .7z to .exe for self-extracting archive.
Extracted this to c:\gnuCOBOL and it works perfectly, well on a hello world test anyway.