Program Structure
Part of the First Programs section of Coddy's COBOL Programming journey. Lesson 4 of 19.
A COBOL program is made of divisions, in a fixed order. A program that runs anything has at least two:
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.
PROCEDURE DIVISION.
DISPLAY "Hi".
STOP RUN.The IDENTIFICATION DIVISION names the program: PROGRAM-ID. HELLO. The PROCEDURE DIVISION holds the statements that run, from top to bottom.
Two more divisions go between them when a program needs them. The ENVIRONMENT DIVISION describes the files a program uses and the DATA DIVISION describes its data. The order is always IDENTIFICATION, ENVIRONMENT, DATA, PROCEDURE.
Every division header ends with a period, and so does PROGRAM-ID. A division in the wrong place stops the compiler with a syntax error.
Challenge
EasyThe DATA DIVISION is at the end of the program, so the compiler stops with a syntax error. Move it above the PROCEDURE DIVISION so the program prints Ready.
Try it yourself
IDENTIFICATION DIVISION.
PROGRAM-ID. READY.
PROCEDURE DIVISION.
DISPLAY "Ready".
STOP RUN.
DATA DIVISION.