DISPLAY and literals
DISPLAY is the simplest way for a program to talk to the outside world.
In batch it writes to SYSOUT, and operators and support staff read those
messages when a job fails at 3 a.m. Writing clear DISPLAY output is a
real part of the job.
Literals
A literal is a value written directly in the code. There are two kinds.
Alphanumeric literals are text in quotes. Double and single quotes both work, but a literal must end with the same quote it started with. To put a quote inside a literal, write it twice, or use the other kind of quote around it:
IDENTIFICATION DIVISION.
PROGRAM-ID. QUOTES.
PROCEDURE DIVISION.
DISPLAY "SAY ""HI""".
DISPLAY 'IT''S DONE'.
DISPLAY 'SAY "HI"'.
STOP RUN.
SAY "HI"
IT'S DONE
SAY "HI"
Numeric literals are numbers without quotes: 42, 007, 1.50,
-3. They can have a sign and a decimal point, and are displayed as
written. "42" in quotes is not a number; it is two characters that
happen to be digits. That difference matters as soon as you start doing
arithmetic.
Several items in one DISPLAY
DISPLAY writes its items one after another, with no spaces between
them. Put the spaces you want inside the literals, or use the figurative
constant SPACE:
IDENTIFICATION DIVISION.
PROGRAM-ID. ITEMS.
PROCEDURE DIVISION.
DISPLAY "BRANCH" "042".
DISPLAY "BRANCH " "042".
DISPLAY "BRANCH" SPACE "042".
DISPLAY "RECORDS READ: " 1500.
STOP RUN.
BRANCH042
BRANCH 042
BRANCH 042
RECORDS READ: 1500
Staying on the same line
Each DISPLAY normally ends the line. Add WITH NO ADVANCING to stay on
it, so the next DISPLAY continues where this one stopped:
IDENTIFICATION DIVISION.
PROGRAM-ID. NOADV.
PROCEDURE DIVISION.
DISPLAY "STEP 1 ... " WITH NO ADVANCING.
DISPLAY "OK".
STOP RUN.
STEP 1 ... OK
This is handy when the second half of a line depends on something the program works out later.
Long literals
A literal cannot run past column 72. If a message is too long, split it
into two literals in the same DISPLAY, each on its own line:
DISPLAY "FIRST HALF OF A LONG MESSAGE, " then, on the next line,
"SECOND HALF". COBOL also has a continuation line (- in column 7)
for this, but splitting is easier to read.
On the job
Make every batch message greppable: start it with the program name,
e.g. DISPLAY "PAYCALC: 1500 RECORDS READ". When a job log has output
from twenty programs, support staff will thank you.
Your task
Write the header that the nightly batch prints to SYSOUT. It must be
exactly:
ACME BANK - NIGHTLY BATCH
MANAGER'S NOTE: "ALL BALANCED"
BRANCH 042 CLOSED
STEPS RUN: 5
Rules:
- Line 2 contains both an apostrophe and double quotes. Write it as one literal.
- Line 3 must be written by two
DISPLAYstatements: the first printsBRANCHand stays on the line withWITH NO ADVANCING, the second prints the rest. - On line 4, the
5must be a numeric literal (no quotes).