Skip to content

michelou/cobol-examples

Repository files navigation

Playing with COBOL on Windows

COBOL language This repository gathers COBOL code examples coming from various websites - mostly from the Mainframestechhelp website - or written by ourself.
In particular it includes several build scripts (Bash scripts, batch files, Make scripts) for experimenting with the COBOL language on a Windows machine.

Ada, Akka, C++, Dafny, Dart, Deno, Docker, Erlang, Flix, Golang, GraalVM, Haskell, Kafka, Kotlin, LLVM, Modula-2, Node.js, Rust, Scala 3, Spark, Spring, TruffleSqueak, WiX Toolset and Zig are other topics we are continuously monitoring.

Project dependencies

This project depends on the following external software for the Microsoft Windows platform:

Optionally one may also install the following software:

Installation policy
When possible we install software from a Zip archive rather than via a Windows installer. In our case we defined C:\opt\ as the installation directory for optional software tools (in reference to the /opt/ directory on Unix).

For instance our development environment looks as follows (November 2024) 2:

C:\opt\cobj\3                                     (  10 MB)
C:\opt\ConEmu\                                    (  26 MB)
C:\opt\Git\                                       ( 392 MB)
C:\opt\GnuCOBOL\                                  ( 548 MB)
C:\opt\jdk-temurin-17.0.13_11\                    ( 304 MB)
C:\opt\msys64\                                    (2.83 GB)
C:\opt\VSCode\                                    ( 381 MB)
C:\Program Files (x86)\Micro Focus\Visual COBOL\  (1.26 GB)

🔎 Git for Windows provides a Bash emulation used to run git.exe from the command line (as well as over 250 Unix commands like awk, diff, file, grep, more, mv, rmdir, sed and wc).

Directory structure

This project has the following directory structure :

bin\
csis-examples\{README.md, MonthTable, etc.}
docs\
dovey-examples\{README.md, Colors, etc.}
examples\{README.md, helloworld, etc.}
harris-examples\{README.md, 100Doors, FizzBuzz, etc.}
moseley-examples\{README.md, Elapsed, etc.}
COBOL_4J.md
GNUCOBOL.md
VISUAL_COBOL.md
README.md
RESOURCES.md
setenv.bat

where

We also define a virtual drive – e.g. drive J: – in our working environment in order to reduce/hide the real path of our project directory (see article "Windows command prompt limitation" from Microsoft Support).

🔎 We use the Windows external command subst to create virtual drives; for instance:

> subst J: %USERPROFILE%\workspace\cobol-examples

In the next section we give a brief description of the batch files present in this project.

Batch/Bash commands

setenv.bat 4

We execute command setenv.bat once to setup our development environment; it makes external tools such as git.exe, make.exe and sh.exe directly available from the command prompt.

   > setenv
   Tool versions:
   cobc 3.3.0, ccbl 9.0.0.49, cobj 1.1.3, java 17.0.12, make 4.4.1,
   git 2.47.0, diff 3.10, bash 5.2.37(1)
    
   > where git make sh
   C:\opt\Git\bin\git.exe
   C:\opt\Git\mingw64\bin\git.exe
   C:\opt\msys64\usr\bin\make.exe
   C:\opt\Git\bin\sh.exe
   C:\opt\Git\usr\bin\sh.exe
   

🔎 Command setenv help displays the help messsage :

Footnotes

[1] MSYS2 libraries

Some COBOL examples depend on the gmp library – A free library for arbitrary precision arithmetic – which is part of our local MSYS2 installation.

[2] Downloads

In our case we downloaded the following installation files (see section 1):

ConEmuPack.230724.7z                               (  5 MB)
gnucobol-3.2-aio-20240306-user.msi                 ( 92 MB)
msys2-x86_64-20240727.exe                          ( 83 MB)
OpenJDK17U-jdk_x64_windows_hotspot_17.0.13_11.zip  (188 MB)
opensourcecobol4j-1.1.3.zip                        (  8 MB)
PortableGit-2.47.0-64-bit.7z.exe                   ( 41 MB)
VSCode-win32-x64-1.95.0.zip                        (131 MB)
vcvs2022_90.exe (for Visual Studio 2022)           (820 MB)

GnuCOBOL distribution
We prefer the All-in-One distribution from SuperBOL over the GnuCOBOL distribution from Arnold Trembley because it works out of the box (i.e. with no extra configuration settings).

[3] COBOL 4J

We built the COBOL 4J distribution from the source archive opensourcecobol4j-1.1.3.zip and installed it into directory C:\opt\cobj\. The 3 build steps are described in the COBOL 4J online documentation:
> set PATH=%MSYS_HOME%\usr\bin;%PATH%
> sh ./configure --prefix=/c/opt/cobj
[...]
OpenCOBOL Configuration:

  CC                   gcc
  COB_CC               gcc
  CFLAGS                -O2 -finline-functions -fsigned-char -Wall -Wwrite-strings -Wmissing-prototypes -Wno-format-security
  COB_CFLAGS           -I/c/opt/cobj/include
  COB_EXTRA_FLAGS
  LDFLAGS
  COB_LDFLAGS
  COB_LIBS             -L${exec_prefix}/lib -lcob -lm
  COB_CONFIG_DIR       ${datarootdir}/opensource-cobol-4j-1.1.3/config
  COB_COPY_DIR         ${datarootdir}/opensource-cobol-4j-1.1.3/copy
  COB_LIBRARY_PATH     ${exec_prefix}/lib/opensource-cobol-4j-1.1.3
  COB_MODULE_EXT
  COB_SHARED_OPT       -shared
  COB_PIC_FLAGS        -fPIC -DPIC
  COB_EXPORT_DYN       -Wl,--export-dynamic
  COB_STRIP_CMD        strip --strip-unneeded

  Use gettext for international messages:      no
  Use fcntl for file locking:                  yes
   
> make
[...]
Making all in libcobj
make[2]: Entering directory '/j/opensourcecobol4j-1.1.3/libcobj'
./gradlew shadowJar
Starting a Gradle Daemon (subsequent builds will be faster)

BUILD SUCCESSFUL in 50s
2 actionable tasks: 2 executed
make[2]: Leaving directory '/j/opensourcecobol4j-1.1.3/libcobj'
make[2]: Entering directory '/j/opensourcecobol4j-1.1.3'
make[2]: Leaving directory '/j/opensourcecobol4j-1.1.3'
make[1]: Leaving directory '/j/opensourcecobol4j-1.1.3'
 
> make install

Note: The make install command requires that the following development tools are available through the PATH environment variable :

> where autoconf bison flex
c:\opt\msys64\usr\bin\autoconf
c:\opt\msys64\usr\bin\bison.exe
c:\opt\msys64\usr\bin\flex.exe

If that is yet not the case we execute the following command :

> c:\opt\msys64\usr\bin\pacman.exe -Suy flex

In our case the installation directory C:\opt\cobj\ looks as follows :

> tree /a /f c:\opt\cobj | findstr /v /b [A-Z]
+---bin
|       cob-config
|       cobj-api
|       cobj-idx
|       cobj.exe
|       cobjrun.exe
+---include
|       libcobj.h
+---lib
|   \---opensourcecobol4j
|           libcobj.jar
\---share
    \---opensource-cobol-4j-1.1.3
        +---config
        |       bs2000.conf
        |       cobol2002.conf
        |       cobol85.conf
        |       default.conf
        |       ibm.conf
        |       mf.conf
        |       mvs.conf
        \---copy
                screenio.cpy

[4] setenv.bat usage

Batch file setenv.bat has specific environment variables set that enable us to use command-line developer tools more easily.
It is similar to the setup scripts described on the page "Visual Studio Developer Command Prompt and Developer PowerShell" of the Visual Studio online documentation.
For instance we can quickly check that the two scripts Launch-VsDevShell.ps1 and VsDevCmd.bat are indeed available in our Visual Studio 2019 installation :
> where /r "C:\Program Files (x86)\Microsoft Visual Studio" *vsdev*
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\Launch-VsDevShell.ps1
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\VsDevCmd.bat
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\vsdevcmd\core\vsdevcmd_end.bat
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\vsdevcmd\core\vsdevcmd_start.bat
Concretely, in our GitHub projects which depend on Visual Studio (e.g. michelou/cpp-examples), setenv.bat does invoke VsDevCmd.bat (resp. vcvarall.bat for older Visual Studio versions) to setup the Visual Studio tools on the command prompt.

mics/November 2024  

About

Playing with COBOL on Windows

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages