For old times sake – COBOL on Linux

Common Business Oriented Language

To Install on Debian or Ubuntu just enter the following:
sudo apt install open-cobol
Create your program with .cbl suffix for example vars.cbl and compile with
cobc -free -x -o vars vars.cbl


Download the following example cbl file with this link

        IDENTIFICATION DIVISION.
          PROGRAM-ID. VARS.
        DATA DIVISION.
          WORKING-STORAGE SECTION.
          *> define a number with a sign, 3 numbers, a decimal, and then
          *> two numbers after the decimal. by default it should be 0 filled
          01 FIRST-VAR PIC S9(3)V9(2) VALUE 123.46.
          *> do the same thing as above but actually initialize
          *> to a number -123.45
          01 SECOND-VAR PIC S9(3)V9(2) VALUE -123.45.
          *> defines an alphabetic string and initialize it to abcdef
          01 THIRD-VAR PIC A(6) VALUE 'ABCDEF'.
          *> define an alphanumeric string and initialize it to a121$
          01 FOURTH-VAR PIC X(5) VALUE 'A121$'.
          *> define a numeric variable and initialize to zero
          01 FIFTH-VAR PIC 9(5)v9(2) VALUE 00000.00.
          *> create a grouped variable
          01 GROUP-VAR.
            05 SUBVAR-1 PIC 9(3) VALUE 337.

            *> create 3 alphanumerics, but use less than
            *> the allocated space for each of them
            05 SUBVAR-2 PIC X(15) VALUE 'LALALALA'.

            05 SUBVAR-3 PIC X(15) VALUE 'LALALA'.

            05 SUBVAR-4 PIC X(15) VALUE 'LALALA'.

        *> add first and second together and then print our variables
        PROCEDURE DIVISION.

          ADD FIRST-VAR SECOND-VAR GIVING FIFTH-VAR
          DISPLAY "1ST VAR :"FIRST-VAR.
          DISPLAY "2ND VAR :"SECOND-VAR.
          DISPLAY "3RD VAR :"THIRD-VAR.
          DISPLAY "4TH VAR :"FOURTH-VAR.
          DISPLAY "5TH VAR :"FIFTH-VAR.
          DISPLAY "GROUP VAR :"GROUP-VAR.
          STOP RUN.

Run the program and see the results

executing cobol on linux

Leave a Reply

Your email address will not be published. Required fields are marked *