Back in the days of mainframes and minicomputers, COBOL licenses were very expensive (eg. starting at tens of thousands of dollars per machine).
One neat thing about Linux and open source software is that a fairly good COBOL compiler called GnuCOBOL could be downloaded then installed for zero dollars.
The following instructions describe nothing new and are only meant to pique your curiosity.
caveats:
| command | notes |
|---|---|
| yum list \*-release\* | display all available distros |
| yum install epel-release |
install yum support for the epel distro (required for gnucobol) |
| yum list \*cobol\* |
display all available packages containing the string "cobol" |
| yum install gnucobol |
install gnucobol |
| which cobc | locate where was the binary stored |
| man cobc | read the online manual |
| yum list vim\* | display all available packages beginning with vim |
| yum install vim-enhanced | install vim (the "vim" editor is superior to "vi" for most programming work) |
online help: https://gnucobol.sourceforge.io/doc/gnucobol.html
| Switch | Notes |
|---|---|
| -m | build a dynamically loadable module (default) |
| -x |
build an executable program (overrides -m) |
| -ftext-column=132 | increases the right side limit from 72 to 132 |
| -free |
removes left side limits for code and remarks increases the right side limit from 72 to 511 note: all remarks must be modified from from "*" to "*>" |
| -help |
display this help and exit |
| -V |
display compiler version information and exit |
| -info | display the compiler's build environment |
| -std=<dialect> | cobol2014, cobol2002, cobol85, ibm, etc. |
| -t error.log | save compiler output to the specified file |
| -tlines=132 | increase -t listing from 55 |
| -T error.log | save wide compiler output to the specified file |
| --list-intrinsics | display built-in functions (eg. INDEX-OF is probably missing) |
Notes:
* 1 2 3 4 5 6
*89012345678901234567890123456789012345678901234567890 * file : hello-world-classic.cob * notes : this is a classic COBOL demo * build : cobc -x hello-world-classic.cob * execute: ./hello-world-classic * history: * when who what * 2023-02-14 NSR original effort IDENTIFICATION DIVISION. PROGRAM-ID. hello-world-classic. PROCEDURE DIVISION. DISPLAY "Hello World!". STOP RUN.
$ cobc -x hello-world-classic.cob
$ ./hello-world-classic
Hello World!
$
Notes:
*> file : hello-world-free-format.cob
*> notes : this is a free format COBOL demo
*> build : cobc -x -free hello-world-free-format.cob
*> execute: ./hello-world-free-format
*> history:
*> when who what
*> 2023-02-14 NSR original effort
IDENTIFICATION DIVISION.
PROGRAM-ID. hello-world-classic.
PROCEDURE DIVISION.
DISPLAY "Hello World!".
STOP RUN.
$ cobc -x -free hello-world-free-format.cob $ ./hello-world-free-format Hello World! $
$ cobc --info | grep -i index indexed file handler : BDB
Notes:
Notes:
| File | Demo | Notes |
|---|---|---|
| hello-world-classic.cob | 1 |
a classic COBOL demo |
| hello-world-free-format.cob | 2 |
a free-format COBOL demo |
| index-file-demo1.cob | 3 |
a classic COBOL ISAM demo with a problem (and solution) |
| index-file-demo2.cob | 4 | a multi-key ISAM demo converted from DEC-BASIC to COBOL (translation done via Google Gemini in 2026) |
| sql-demo1.cob | 5 | coming soon |
*> ==========================================================
*> title : display-gotcha.cob
*> author : Neil Rieck
*> created: 2026-09-30
*> compile: cobc -x -free display-gotcha.cob
*> notes :
*> 1) changing CONSOLE breaks DISPLAY WITH NO ADVANCING so
*> this program will not compile as-is.
*> 2) To fix this program you must remove "CONSOLE IS CRT."
*> ==========================================================
IDENTIFICATION DIVISION.
PROGRAM-ID. display-gotcha.
AUTHOR. Neil Rieck.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.
CONSOLE IS CRT.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-CONTROL-VARS.
05 JUNK-INPUT PIC X(10) VALUE SPACES.
05 JUNK-CHAR PIC X(1) VALUE SPACES.
PROCEDURE DIVISION.
MAIN-PROGRAM.
DISPLAY "display-gotcha"
DISPLAY "Continue? (y/N) " WITH NO ADVANCING
ACCEPT JUNK-INPUT
PERFORM EXTRACT-FIRST-UPPER
IF JUNK-CHAR = "Y"
DISPLAY "continuing"
ELSE
DISPLAY "not continuing"
END-IF
GO TO PROGRAM-EXIT.
EXTRACT-FIRST-UPPER.
MOVE FUNCTION UPPER-CASE(FUNCTION TRIM(JUNK-INPUT))
TO JUNK-INPUT
IF JUNK-INPUT = SPACES
MOVE "N" TO JUNK-CHAR
ELSE
MOVE JUNK-INPUT(1:1) TO JUNK-CHAR
END-IF.
PROGRAM-EXIT.
DISPLAY "Adios..."
STOP RUN.
$ cobc -x -free display-gotcha.cob display-gotcha.cob: in paragraph 'MAIN-PROGRAM': display-gotcha.cob:28: error: cannot specify NO ADVANCING in screen DISPLAY 26 | DISPLAY "Display-FUBAR" 27 | DISPLAY "Continue? (y/N) " WITH NO ADVANCING 28 > ACCEPT JUNK-INPUT 29 | PERFORM EXTRACT-FIRST-UPPER 30 | IF JUNK-CHAR = "Y" $
$ # attempt 1 $ cobc -x -free mysql-demo-native.cob -lmariadb $ ./mysql-demo-native MySQL-Demo-Native ================= OK to delete 'demo data table'? (y/N)y libcob: error: module 'mysql_init' not found $ # attempt 2 $ cobc -x -free -fstatic-call mysql-demo-native.cob -lmariadb $ ./mysql-demo-native MySQL-Demo-Native ================= OK to delete 'demo data table'? (y/N)y -e- error: 1045 in connect -i- text : Access denied for user 'demo'@'localhost' (using password: YES) Adios... $or by commanding your system to load the library bindings (this demo uses mariadb; your program might be using mysql)
$ # get help
$ ldconfig -?
$ ....verbage ensues...
$ # is library installed in memory?
$ ldconfig -p | grep -i mariadb
$ # install all libraries
$ ldconfig
...verbage ensues...
$ # is library installed in memory?
$ ldconfig -p | grep -i mariadb
libmariadb.so.3 (libc6,x86-64) => /lib64/libmariadb.so.3
libmariadb.so (libc6,x86-64) => /lib64/libmariadb.so
$
Back to Home