Module lessons (1/2)
Program Structure and Columns (1–80)
Architecture of a COBOL source
Understanding why an 80-column punch card file requires rigorous positional discipline.
COBOL (Common Business-Oriented Language), born in 1959, still powers the majority of the world's banking, insurance and government transactions today. Unlike loosely syntax languages like Python or JavaScript, a classic COBOL program is organized as a formal business document divided into Divisions, Sections, Paragraphs, and Sentences.
1. The fixed 80 column format (Area A vs Area B)
Historically programs were punched onto 80 character IBM cards. Even in modern fixed compilers, the horizontal position determines whether the code compiles or generates errors:
- Columns 1–6 (Sequence Area): Optional row numbering (e.g.
000100); today left empty with 6 spaces. - Column 7 (Indicators Area): Entering
*transforms the entire row into a comment;-indicates continuation of literal string;/force skip page while printing. - Columns 8–11 (Area A): Reserved for structural headers:
DIVISION,SECTIONnames, paragraph names,FD, and01or77level data declarations. - Columns 12–72 (Area B): Reserved for all executable statements (
DISPLAY,MOVE,ADD,IF,PERFORM) and subordinate fields (05,10, …). - Columns 73–80 (Identification Area): Silently ignored by the compiler. Anything above column 72 is cut!
000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. BANK-BOOT.
* Commento valido: asterisco esattamente a colonna 7 (6 spazi).
PROCEDURE DIVISION.
DISPLAY "Area B: colonna 12 (11 spazi iniziali)".
STOP RUN.2. The Four Divisions in strict order
Every COBOL file always follows the same top-down pattern, from the ID card down to the executable statements:
IDENTIFICATION DIVISION.— ContainsPROGRAM-ID.and optional metadata (AUTHOR.,DATE-WRITTEN.). It is the only one required beforePROCEDURE DIVISION.ENVIRONMENT DIVISION.— Connect the program to the external (CONFIGURATION SECTION,INPUT-OUTPUT SECTIONandFILE-CONTROL).DATA DIVISION.— Declares each byte of program memory (FILE SECTION,WORKING-STORAGE SECTION,LINKAGE SECTION).PROCEDURE DIVISION.— Contains the executable stream. Must stop withSTOP RUN.(orGOBACK.).
IDENTIFICATION DIVISION.
PROGRAM-ID. PAYROLL-CHECK.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-STATUS PIC X(5) VALUE "READY".
PROCEDURE DIVISION.
DISPLAY "PAYROLL ENGINE: " WS-STATUS.
STOP RUN.3. Modern comments (*>) and the role of the final period (.)
From the COBOL 2002 standard onwards, in addition to the classic * in column 7, the inline comment *> is available, useful at the end of the line in Area B:
* Classico commento full-line (asterisco a col 7)
PROCEDURE DIVISION.
DISPLAY "Boot complete." *> Commento inline COBOL-2002+
STOP RUN.In PROCEDURE DIVISION, the period . acts as a sentence-ending "full stop" (period scope terminator):
IDENTIFICATION DIVISION.
PROGRAM-ID. MULTI-STOP.
PROCEDURE DIVISION.
DISPLAY "Step 1"
DISPLAY "Step 2"
STOP RUN.Try it yourself
Write the initial COBOL program headers by entering the IDENTIFICATION DIVISION and defining the program name as HELLO-PRG.
Show hint
Write IDENTIFICATION DIVISION. in column 8 (7 margin spaces) and at the end PROGRAM-ID. HELLO-PRG.
Solution available after 3 attempts
Complete the skeleton by entering the PROCEDURE DIVISION and print the text 'HELLO COBOL' on the screen using DISPLAY. Remember to stop the program with STOP RUN.
Show hint
Under DIVISION PROCEDURES, write DISPLAY 'HELLO COBOL'. in column 12 (11 margin spaces) and STOP RUN. on the next line.
Solution available after 3 attempts
Build a complete four-division program (IDENTIFICATION, ENVIRONMENT, DATA, PROCEDURES) with PROGRAM-ID CORE-BOOT, an asterisk (*) comment in column 7, and a final print DISPLAY 'SYSTEM READY'.
Show hint
Put a comment with 6 spaces + '*', the four divisions at 7 spaces (column 8) and DISPLAY + STOP RUN at 11 spaces (column 12).
Solution available after 3 attempts
What is the effect of this COBOL fixed format line (11 leading spaces before DISPLAY)?
IDENTIFICATION DIVISION.
PROGRAM-ID. CHECK-COL.
PROCEDURE DIVISION.
DISPLAY "ERRORE DI AREA".
STOP RUN.What happens during compilation if a line of COBOL code exceeds column 72 in the classic fixed format?
DISPLAY "MESSAGGIO LUNGHISSIMO CHE ESCE OLTRE SETTANTADUE QUI!"