Module lessons (1/2)
Program Structure
COBOL (Common Business-Oriented Language) is one of the longest-living programming languages in history, designed specifically for business and financial applications. Unlike modern languages, it has a rigid and formal structure split into sections called Divisions.
Fixed Layout and Area Formats
In traditional COBOL source files, every line is divided into specific areas based on columns:
- Columns 1-6 (Sequence Area): Historically used for punch card sequence numbers. Today it is usually left blank.
- Column 7 (Indicator Area): Used to mark comment lines by placing an asterisk
*. - Columns 8-11 (Area A): This is where division, section, and paragraph headers start.
- Columns 12-72 (Area B): This is where actual executable statements (like
DISPLAY,MOVE, etc.) are written. - Columns 73-80 (Identification Area): Historically ignored by the compiler, used for internal identification.
In our exercises, we will use a simplified but consistent formatting by starting Area B instructions with appropriate spaces (usually 7 or 11 spaces depending on the area).
The Four Main Divisions
Every complete COBOL program is structured into four mandatory divisions, which must appear in this exact order:
-
IDENTIFICATION DIVISION.Contains program metadata, such as the program name defined with thePROGRAM-IDkeyword. -
ENVIRONMENT DIVISION.Specifies the environment in which the program runs and maps physical files to internal variables. -
DATA DIVISION.Where all variables and data structures used by the program are declared. -
PROCEDURE DIVISION.Contains the executable instructions (the business logic). Every program must end withSTOP RUN.to stop execution.
Try it yourself
Write the initial COBOL headers by introducing the IDENTIFICATION DIVISION and defining the program name as HELLO-PRG.
Show hint
Write IDENTIFICATION DIVISION. starting at column 8 (7 spaces) and on the next line PROGRAM-ID. HELLO-PRG.
Solution available after 3 attempts
Complete the structure by introducing the PROCEDURE DIVISION and print the text 'HELLO COBOL' to the console using DISPLAY. Remember to end the program execution using STOP RUN.
Show hint
Below PROCEDURE DIVISION., write DISPLAY 'HELLO COBOL'. starting at column 12 (11 spaces) and STOP RUN. on the following line.
Solution available after 3 attempts