MODULE 1 · FIRST STEPS · 4/8

Fixed-format columns

12 min30 XPExercise

COBOL dates from the era of punched cards: one card per line, 80 columns per card. The column layout from those cards survives in every mainframe COBOL program today. The rules are called reference format (or fixed format):

Columns Name Use
1–6 Sequence area Line numbers; ignored by the compiler
7 Indicator area * comment, / comment + new listing page, - continuation, D debugging line
8–11 Area A Division, section and paragraph headers; 01 and 77 levels
12–72 Area B Statements and everything else
73–80 Identification area Ignored by the compiler

Here is a program laid out correctly:

      *----------------------------------------------------------*
      * DAILYMSG - PRINTS THE DAILY OPERATOR MESSAGE             *
      *----------------------------------------------------------*
       IDENTIFICATION DIVISION.
       PROGRAM-ID. DAILYMSG.
       PROCEDURE DIVISION.
      *    TELL THE OPERATOR THE RUN HAS STARTED
           DISPLAY "DAILY RUN STARTED".
           STOP RUN.

It prints one line, DAILY RUN STARTED. Every line starting with * in column 7 is a comment, including the box at the top. Shops put a comment block like that at the start of every program.

Sequence numbers and change tags

Programs that have lived on a mainframe for decades often have numbers in columns 1–6 and a tag in columns 73–80 recording which change last touched the line. A real listing looks like this:

000100 IDENTIFICATION DIVISION.                                         CHG0412
000200 PROGRAM-ID. DAILYMSG.                                            CHG0412
000300 PROCEDURE DIVISION.                                              CHG0412
000400     DISPLAY "DAILY RUN STARTED".                                 CHG0587
000500     STOP RUN.                                                    CHG0412

The compiler ignores both areas, so this compiles and runs exactly like the version without them.

The column-72 trap

Anything past column 72 is thrown away silently. If a statement runs past column 72, the end of it simply vanishes, which can produce baffling errors such as an unterminated literal. Most editors show a marker at column 72; keep your code inside it.

Area A versus Area B

Headers go in Area A: IDENTIFICATION DIVISION., WORKING-STORAGE SECTION., paragraph names like MAIN-PARA., and the level numbers 01 and 77. Statements such as DISPLAY go in Area B, conventionally at column 12. GnuCOBOL is lenient about statements that start in Area A, but IBM's compiler flags them, so always indent statements to column 12.

Debugging lines

A D in column 7 marks a debugging line. It is treated as a comment unless the program turns on debugging mode (with SOURCE-COMPUTER. ... WITH DEBUGGING MODE). You will find these in old code; don't rely on them in new code.

On the job

When you remove logic during a change, many shops want you to comment it out with * and add a note with the change number rather than delete it, so reviewers can see what changed. Follow your shop's standard.

Your task

Someone left two debug messages in this program. Your change ticket says: comment them out, don't delete them.

Put a * in column 7 of each DEBUG line so the compiler ignores it. The program must then print exactly:

DAILY RUN STARTED
ACCOUNTS POSTED
DAILY RUN ENDED

Check your understanding

1. A line has an asterisk (*) in column 7. What does the compiler do with it?
2. Where must a division header such as PROCEDURE DIVISION start?
3. What happens to text in columns 73–80?
fixed format
Run your program to see its output here. The first visible test's input and datasets are used.
Submit to grade your program against every test.