MODULE 1 · FIRST STEPS · 7/8

Reading compiler errors

15 min30 XPExercise

You will spend a lot of your career reading compiler output. The compiler is not your enemy: every message tells you where it got confused and what it expected. This lesson teaches you to read them calmly.

Anatomy of a message

Here is a program with a typo in a data name:

       IDENTIFICATION DIVISION.
       PROGRAM-ID. TYPO.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  WS-TOTAL         PIC 9(4) VALUE 150.
       PROCEDURE DIVISION.
           DISPLAY "TOTAL: " WS-TOTL.
           STOP RUN.

GnuCOBOL says:

prog.cbl:7: error: 'WS-TOTL' is not defined
    5 |        01  WS-TOTAL         PIC 9(4) VALUE 150.
    6 |        PROCEDURE DIVISION.
    7 >            DISPLAY "TOTAL: " WS-TOTL.
    8 |            STOP RUN.
    9 | <EOF>

Read it left to right: the file, the line number (7), the severity (error) and the message. The > marks the line in the excerpt. "Is not defined" nearly always means a spelling mistake, or a field you forgot to declare in WORKING-STORAGE.

Severity

  • error: the program was not built. You must fix it.
  • warning: the program was built, but something looks suspicious, such as a value too long for its field. Read every warning; many production bugs started as an ignored warning.
  • note: extra detail about the message above it. Notes are often the most useful line, e.g. note: unknown statement 'DISPLY'.

Common messages and what they usually mean

Message Usual cause
'X' is not defined Typo in a data name, or it is not declared
syntax error, unexpected ... A misspelled verb, or a missing period at the end of the line above (common in the DATA DIVISION)
note: unknown statement 'DISPLY' A misspelled verb
invalid literal / missing terminating " character A literal with no closing quote
continuation character expected Also a missing quote: the literal ran on to the next line

Rules for fixing errors

  1. Errors are not listed in line order. Sort them by line number in your head and start with the lowest.
  2. One mistake can produce several messages. A missing quote on line 12 can also report an error on line 13. Fix the cause, not every message.
  3. Some errors hide others. After a syntax error the compiler may skip the rest of a sentence, so fixing one error can reveal a new one. Compile again after every fix or two.
  4. Look at the line above. When the flagged line looks perfect, the real problem is often a missing period or quote just before it.

Mainframe compile listings

IBM Enterprise COBOL writes messages such as IGYPS2121-S into the compile listing. The last letter is the severity: I (information, return code 0), W (warning, RC 4), E (error, RC 8), S (severe, RC 12), U (unrecoverable, RC 16). The job's condition code tells you the worst one at a glance.

On the job

Many shops require a clean compile (RC 0) before code is promoted. If you must leave a warning, be ready to explain it in code review.

Your task

This program does not compile. It has three separate mistakes. Press Run, read the compiler messages, and fix them one at a time.

When it compiles, it must print:

JOB PAYRUN01 STARTED
STEPS RUN: 03
STATUS: OK
JOB PAYRUN01 ENDED

Don't change the DATA DIVISION; all three mistakes are in the PROCEDURE DIVISION.

Check your understanding

1. The compiler reports errors on lines 13, 10 and 11, in that order. Where should you start?
2. On z/OS, a compile finishes with return code 4. What does that mean?
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.