Run COBOL / gnuCOBOL using MSYS2 in Windows

Submitted by Dickens A S on Mon, 07/12/2021 - 03:55
Run COBOL in windows

Why COBOL in 2021?

The reason is, many migration still happening from mainframe COBOL to Java or .NET

If the developer knows how test the COBOL in his local machine, then it benefits the migration to speed up

This article demonstrates the Cygwin dependencies to compile gnuCOBOL from source code

Mainframe is going through another refresh cycle to make mainframe available in Cloud based IDE like Eclipse CHE

It is important to learn to COBOL

What is this article?

This article demonstrates how to use MSYS2 to install cobol in windows easily and run a cobol code

How to install MSYS2?

Refer Official documentation https://www.msys2.org/

How to Install COBOL in MSYS2?

$ pacman -S mingw-w64-x86_64-gnucobol

COBOL Code?

       IDENTIFICATION DIVISION.
       PROGRAM-ID. HELLO-WORLD.

       DATA DIVISION. 
       WORKING-STORAGE SECTION.
       01 WS-OUT PIC X(80) VALUE SPACES.
       01 WS-N PIC 9(2) VALUE 0. 
       01 WS-CENTER PIC 9(2) VALUE 20.

       PROCEDURE DIVISION.

       PERFORM VARYING WS-N FROM 1 BY 2 UNTIL WS-N > 26
       MOVE ALL '*' TO WS-OUT(WS-CENTER:WS-N)
       COMPUTE WS-CENTER = WS-CENTER - 1
       DISPLAY WS-OUT
       END-PERFORM.

       STOP RUN.

How to Compile that code? (test.cob)

$ cobc -conf=/mingw64/share/gnucobol/config/default.conf -x test.cob

How to Run the EXE (test.exe)

$ ./test

What is the output

                   *
                  ***
                 *****
                *******
               *********
              ***********
             *************
            ***************
           *****************
          *******************
         *********************
        ***********************
       *************************

Finished !!

 

 

Add new comment