MODULE 1 · FIRST STEPS · 2/8

Hello, Mainframe

8 min30 XPExercise

Time to run your first program. Every COBOL program is split into divisions. The smallest useful program needs only two of them:

       IDENTIFICATION DIVISION.
       PROGRAM-ID. HELLO.
       PROCEDURE DIVISION.
           DISPLAY "HELLO, MAINFRAME".
           STOP RUN.

Line by line:

  • IDENTIFICATION DIVISION. starts the program. Every program has one.
  • PROGRAM-ID. HELLO. names the program. On z/OS this is the name the program is stored and called under, so shops keep it to eight characters or fewer.
  • PROCEDURE DIVISION. marks where the instructions start.
  • DISPLAY "HELLO, MAINFRAME". writes a line of text. The text between the quotes is a literal: it is printed exactly as written.
  • STOP RUN. ends the program and hands control back to the operating system.

Notice the full stops. In COBOL a period ends a sentence, and forgetting one (or adding one in the wrong place) is one of the most common mistakes. Division headers, the PROGRAM-ID line and the last statement of each group all end with a period.

Where does DISPLAY go?

In this course DISPLAY output appears in the output panel next to the editor. On a mainframe it goes to the job's SYSOUT, a spool file you open in SDSF after the job finishes. Batch programs use DISPLAY for progress messages, record counts and error messages that operators read the next morning.

You can DISPLAY as many lines as you like; each DISPLAY statement starts a new line:

       IDENTIFICATION DIVISION.
       PROGRAM-ID. TWOLINES.
       PROCEDURE DIVISION.
           DISPLAY "LINE ONE".
           DISPLAY "LINE TWO".
           STOP RUN.

Columns matter

Classic COBOL is fixed format: columns 1–6 are the sequence area, column 7 is the indicator, code lives in columns 8–72. Division headers start in Area A (column 8); statements go in Area B (column 12 onwards). The editor already has the spacing right, so keep your statements lined up with the existing ones. The next lessons explain the columns properly.

On the job

COBOL is not case-sensitive for keywords, but most mainframe shops write code in upper case, and many older terminals and tools expect it. This course follows that convention.

Your task

Change the program so it displays exactly these two lines:

HELLO, MAINFRAME
JOB COMPLETE
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.