BudiBadu Logo
Samplebadu

COBOL by Example: Program Structure

COBOL 2002

Understanding the hierarchical structure of a COBOL program with its four mandatory divisions in fixed order, learning the purpose of IDENTIFICATION for program metadata, ENVIRONMENT for hardware configuration, DATA for variable definitions, and PROCEDURE for executable logic, and implementing proper division organization following COBOL standards.

Code

       IDENTIFICATION DIVISION.
       PROGRAM-ID. STRUCT-DEMO.
       
       ENVIRONMENT DIVISION.
       
       DATA DIVISION.
       
       PROCEDURE DIVISION.
           DISPLAY "Program Structure Example".
           STOP RUN.

Explanation

A standard COBOL program consists of four distinct divisions, which must appear in a specific order: IDENTIFICATION, ENVIRONMENT, DATA, and PROCEDURE. This rigid structure is a hallmark of COBOL, designed to enforce a clear separation of concerns between the program's identity, its hardware requirements, its data definitions, and its logic. These divisions form the top level of COBOL's hierarchical organization.

The ENVIRONMENT DIVISION is used to specify the computer environment in which the program is compiled and executed. It maps logical file names used in the program to physical files on the disk. The DATA DIVISION is where all variables, file records, and storage needs are defined. You cannot simply declare a variable in the middle of your logic code; it must be pre-defined here.

While modern COBOL compilers might allow omitting some divisions for simple programs (as seen in the Hello World example), a robust business application will almost always utilize all four. This structure aids in maintainability, as a programmer knows exactly where to look for file definitions versus business rules.

Code Breakdown

1
IDENTIFICATION DIVISION: The first division. It provides metadata like the program name, author, and date written.
2
PROGRAM-ID. STRUCT-DEMO. names the program. This is the only paragraph strictly required in the Identification Division.
4
ENVIRONMENT DIVISION: This division connects the program to the outside world (files, devices). It is empty here but usually contains the INPUT-OUTPUT SECTION.
6
DATA DIVISION: This is where you describe your data. It separates data definition from data manipulation. It is empty here as we are using literals.
8
PROCEDURE DIVISION: The final division containing the algorithms and logic. It uses the resources defined in the previous divisions.
9
DISPLAY "Program Structure Example". A simple instruction to verify the program is running.
10
STOP RUN. Explicitly ends the program.