COBOL – Because I Can – Pt 1

COBOL was my second home. VAX BASIC was the first. I lived there for many years. If you wait for enough people to die off, your old skills become really valuable!

Thankfully DECUS maintains URLs for Eisner. I believe it is actually hosted by VSI now. Any dues paying Encompass member can get themselves an account on Eisner.

My ancient copy of Reflections was from like, Windows 98 days. It installed, but was useless. SSH has changed dramatically. I could have moved over to one of my Linux machines and dusted off my old Xterm configuration, but wanted to see what was out there. I remember when KEAterm and Reflections were something like $400 a seat! Found ZOC9 for $80. I’ve almost got it configured the way I like. I seem to remember Reflections and KEAterm had a checkbox or something for “leave the cursor keys alone.”

Delete, End, and Home used to work just like on a PC. Delete would delete whatever was at the cursor, even on the command line. I haven’t replicated the command line capabilities yet, but things work well in LSE.

Triangles

I started researching what has changed in the world of COBOL and found this!

Yippee! I’m gonna do Triangles and use REPORT WRITER. Then reality screwed me from afar. Version of COBOL on Eisner (and most likely where I will contract) didn’t have that. The difficult part of the Triangles problem is dealing with the fact COBOL doesn’t have dynamic strings. COLUMN CENTER would make the problem go away.

Most of you kids will think that looks terrible. You kids should be warned about thinking. This is a character cell terminal, not a word processor with dynamic fonts nor is there really a graphics card involved. Odd count stars will stick out on the left if you don’t slush the remainder or right if you do. You just can’t center 3 under 4.

The Code

IDENTIFICATION DIVISION.

PROGRAM-ID.     TRIANGLE_REPORT.
AUTHOR.         ROLAND HUGHES.
DATE-WRITTEN.   2026-09-04.
DATE-COMPILED.  TODAY.

ENVIRONMENT DIVISION.

INPUT-OUTPUT SECTION.

FILE-CONTROL.

DATA DIVISION.

FILE SECTION.

WORKING-STORAGE SECTION.
01  STUFF.
    05 TODAYS-DATE.
       10 TODAY_YYYY         PIC X(4).
       10 TODAY_MM           PIC X(2).
       10 TODAY_DD           PIC X(2).

    05 TODAYS-DATE-FORMATTED.
       10 FMT_MM             PIC Z9.
       10 FILLER             PIC X VALUE '/'.
       10 FMT_DD             PIC 99.
       10 FILLER             PIC X VALUE '/'.
       10 FMT_YYYY           PIC 9(4).

    05 STAR-COUNT           PIC 9(2) VALUE 36.
    05 A-COUNT              PIC 9(2).
    05 D-COUNT              PIC 9(2).
    05 START-POS            PIC 9(2).

01  PAGE-HEADING.
    05 FILLER               PIC X(32) VALUE SPACES.
    05 FILLER               PIC X(16) VALUE IS 'Classic Stars'.
    05 FILLER               PIC X(22) VALUE SPACES.
    05 FORMATTED-DATE       PIC X(10).

01  DETAIL-HEADING.
    05 FILLER               PIC X(33) VALUE SPACES.
    05 FILLER               PIC X(10) VALUE IS 'Star Count'.
    05 FILLER               PIC X(7) VALUE SPACES.
    05 DISPLAY-COUNT        PIC Z9.

01  DTL-LINE.
    05 D-STRING             PIC X(40).
    05 A-STRING             PIC X(40).

PROCEDURE DIVISION.

A000-MAIN.
    PERFORM B000-HSK.

    PERFORM B100-PRINT-TRIANGLES
        VARYING D-COUNT FROM STAR-COUNT BY -1
        UNTIL D-COUNT IS LESS THAN 1.

    STOP RUN.

*****
*   Paragraph to initialize our data and files.
*****
B000-HSK.
    ACCEPT TODAYS-DATE FROM DATE YYYYMMDD.

    MOVE TODAY_YYYY TO FMT_YYYY.
    MOVE TODAY_DD   TO FMT_DD.
    MOVE TODAY_MM   TO FMT_MM.

    MOVE TODAYS-DATE-FORMATTED TO FORMATTED-DATE.
    MOVE STAR-COUNT TO DISPLAY-COUNT.

    DISPLAY ' '.
    DISPLAY PAGE-HEADING.
    DISPLAY ' '.

    DISPLAY DETAIL-HEADING.
    DISPLAY ' '.

*****
*   Actually write the report
*   Too bad the REPORT WRITER doesn't have COLUMN CENTER like
*   modern COBOL.
*****
B100-PRINT-TRIANGLES.
    ADD 1 TO A-COUNT.
    MOVE SPACES TO DTL-LINE.

    COMPUTE START-POS = 20 - (D-COUNT / 2).
    MOVE ALL '*' TO D-STRING(START-POS:D-COUNT).

    COMPUTE START-POS = 20 - (A-COUNT / 2).
    MOVE ALL '*' TO A-STRING(START-POS:A-COUNT).

    DISPLAY DTL-LINE.

END PROGRAM TRIANGLE_REPORT.

Instead of COMPUTE, to slush on the right you would need something like

DIVIDE D-COUNT by 2 GIVING QUOTIENT-VALUE REMAINDER SLUSH.
COMPUTE START-POS = 20 - QUOTIENT-VALUE + SLUSH.

Odd numbers would have a remainder of 1, otherwise SLUSH would be zero. For some reason people tend to not notice things sticking off the right side.

521 Articles

Roland Hughes started his IT career in the early 1980s. He quickly became a consultant and president of Logikal Solutions, a software consulting firm specializing in OpenVMS application and C++/Qt touchscreen/embedded Linux development. Early in his career he became involved in what is now called cross platform development. Given the dearth of useful books on the subject he ventured into the world of professional author in 1995 writing the first of the "Zinc It!" book series for John Gordon Burke Publisher, Inc.

A decade later he released a massive (nearly 800 pages) tome "The Minimum You Need to Know to Be an OpenVMS Application Developer" which tried to encapsulate the essential skills gained over what was nearly a 20 year career at that point. From there "The Minimum You Need to Know" book series was born.

Three years later he wrote his first novel "Infinite Exposure" which got much notice from people involved in the banking and financial security worlds. Some of the attacks predicted in that book have since come to pass. While it was not originally intended to be a trilogy, it became the first book of "The Earth That Was" trilogy:
Infinite Exposure
Lesedi - The Greatest Lie Ever Told
John Smith - Last Known Survivor of the Microsoft Wars

When he is not consulting Roland Hughes posts about technology and sometimes politics on his blog. He also has regularly scheduled Sunday posts appearing on the Interesting Authors blog.

Leave a Reply