COBOL programs are structured into four main divisions that organize code by function. This standardized structure is one of COBOL's defining characteristics, making programs more readable and maintainable. Each division has a specific purpose and must appear in a fixed sequence.
Identifies the program with a name and optional metadata like author, date written, etc.
Describes the computing environment, including file definitions and configuration.
Defines all data items used by the program, including files, working storage, and parameters.
Contains the actual executable instructions and business logic of the program.
This division-based structure reflects COBOL's business focus, separating program identification, environment configuration, data definition, and processing logic into distinct sections.
1234567891011121314IDENTIFICATION DIVISION. PROGRAM-ID. SAMPLE-PROGRAM. ENVIRONMENT DIVISION. CONFIGURATION SECTION. INPUT-OUTPUT SECTION. DATA DIVISION. FILE SECTION. WORKING-STORAGE SECTION. PROCEDURE DIVISION. DISPLAY "Hello, World!". STOP RUN.
The example above shows the basic structure of a COBOL program with all four divisions.
The IDENTIFICATION DIVISION is the first division in a COBOL program and provides information about the program itself. This division is mandatory for every COBOL program.
IDENTIFICATION DIVISION.
PROGRAM-ID. program-name.
AUTHOR.
- Name of the programmer who wrote the programINSTALLATION.
- Name of the company or site where the program is usedDATE-WRITTEN.
- Date when the program was writtenDATE-COMPILED.
- Date when the program was compiledSECURITY.
- Security classification of the programREMARKS.
- General comments about the program123456IDENTIFICATION DIVISION. PROGRAM-ID. PAYROLL. AUTHOR. JOHN SMITH. DATE-WRITTEN. 2023-01-15. SECURITY. CONFIDENTIAL. REMARKS. THIS PROGRAM CALCULATES EMPLOYEE PAYROLL.
This example shows an IDENTIFICATION DIVISION with several optional elements included.
The ENVIRONMENT DIVISION describes the computing environment in which the program will run. It specifies the relationship between the program and external resources such as files and devices.
Describes the overall configuration of the program, including:
SOURCE-COMPUTER
- Specifies the computer used for compilationOBJECT-COMPUTER
- Specifies the computer where the program will runSPECIAL-NAMES
- Defines symbolic names for system devices or implements currency signsDescribes the files and external devices used by the program:
FILE-CONTROL
- Assigns physical files to the program's internal file namesI-O-CONTROL
- Specifies input-output techniques, such as file sharing or memory allocation12345678910111213ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. IBM-Z. OBJECT-COMPUTER. IBM-Z. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT EMPLOYEE-FILE ASSIGN TO EMPFILE ORGANIZATION IS INDEXED ACCESS MODE IS DYNAMIC RECORD KEY IS EMP-ID FILE STATUS IS FILE-STATUS-CODE. SELECT REPORT-FILE ASSIGN TO PRINTER.
This example shows an ENVIRONMENT DIVISION with file definitions for an indexed employee file and a report file.
The DATA DIVISION defines all the data items that will be used by the program, including file structures, variables, constants, and parameter interfaces. It's where you define the format and structure of your program's data.
Describes the structure of data files referenced in the ENVIRONMENT DIVISION, including record layouts and field definitions.
Defines program variables that aren't associated with files, including temporary storage and constants.
Similar to WORKING-STORAGE but allocated each time a program is called and deallocated when it returns (for recursion support).
Describes data items passed to the program from a calling program (parameters).
1234567891011121314DATA DIVISION. FILE SECTION. FD EMPLOYEE-FILE. 01 EMPLOYEE-RECORD. 05 EMP-ID PIC 9(5). 05 EMP-NAME PIC X(30). 05 EMP-SALARY PIC 9(7)V99. WORKING-STORAGE SECTION. 01 WS-VARIABLES. 05 WS-TOTAL-SALARY PIC 9(9)V99 VALUE ZERO. 05 WS-COUNTER PIC 9(3) VALUE ZERO. 05 WS-EOF PIC X VALUE 'N'. 05 FILE-STATUS-CODE PIC X(2).
This example shows a DATA DIVISION with file and working storage sections.
The PROCEDURE DIVISION contains the executable instructions of the program. This is where the actual processing logic is defined, including calculations, data manipulation, file operations, and decision-making.
May include parameter specifications:
PROCEDURE DIVISION.
- Basic form with no parametersPROCEDURE DIVISION USING parameter1, parameter2...
- For receiving parametersPROCEDURE DIVISION USING ... RETURNING result
- For functions that return values12345678910111213141516171819202122232425262728PROCEDURE DIVISION. MAIN-LOGIC. PERFORM INITIALIZATION PERFORM PROCESS-RECORDS UNTIL WS-EOF = 'Y' PERFORM TERMINATION STOP RUN. INITIALIZATION. OPEN INPUT EMPLOYEE-FILE OPEN OUTPUT REPORT-FILE PERFORM READ-EMPLOYEE-RECORD. PROCESS-RECORDS. ADD EMP-SALARY TO WS-TOTAL-SALARY ADD 1 TO WS-COUNTER WRITE REPORT-RECORD FROM EMPLOYEE-RECORD PERFORM READ-EMPLOYEE-RECORD. READ-EMPLOYEE-RECORD. READ EMPLOYEE-FILE AT END MOVE 'Y' TO WS-EOF END-READ. TERMINATION. DISPLAY "Total employees: " WS-COUNTER DISPLAY "Total salary: $" WS-TOTAL-SALARY CLOSE EMPLOYEE-FILE CLOSE REPORT-FILE.
This example shows a PROCEDURE DIVISION with sections, paragraphs, and executable statements organized in a modular way.
The COBOL divisions must appear in a specific order, though not all divisions are always required:
The strict structure of COBOL programs with these divisions contributes to readability and maintainability, especially for large business applications where many programmers might work on the same code over time.
Examine the following COBOL program and answer the questions:
12345678910111213141516171819202122232425262728293031323334353637383940IDENTIFICATION DIVISION. PROGRAM-ID. INVENTORY. AUTHOR. JANE DOE. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT STOCK-FILE ASSIGN TO STOCKDAT ORGANIZATION IS SEQUENTIAL. DATA DIVISION. FILE SECTION. FD STOCK-FILE. 01 STOCK-RECORD. 05 ITEM-ID PIC X(10). 05 ITEM-NAME PIC X(30). 05 QUANTITY PIC 9(5). 05 UNIT-PRICE PIC 9(5)V99. WORKING-STORAGE SECTION. 01 WS-VARIABLES. 05 WS-TOTAL-VALUE PIC 9(10)V99 VALUE ZERO. 05 WS-EOF PIC X VALUE 'N'. PROCEDURE DIVISION. MAIN-PARAGRAPH. OPEN INPUT STOCK-FILE PERFORM UNTIL WS-EOF = 'Y' READ STOCK-FILE AT END MOVE 'Y' TO WS-EOF NOT AT END PERFORM PROCESS-RECORD END-READ END-PERFORM DISPLAY "Total inventory value: $" WS-TOTAL-VALUE CLOSE STOCK-FILE STOP RUN. PROCESS-RECORD. COMPUTE WS-TOTAL-VALUE = WS-TOTAL-VALUE + (QUANTITY * UNIT-PRICE).
1. Which of the following COBOL divisions are mandatory in every program?
2. What is the purpose of the ENVIRONMENT DIVISION?
3. Which section in the DATA DIVISION would you use to define variables that are passed as parameters from a calling program?
4. In what order must COBOL divisions appear in a program?
5. What is the only mandatory paragraph in the IDENTIFICATION DIVISION?
Yes, only the IDENTIFICATION DIVISION is absolutely mandatory for all COBOL programs. The PROCEDURE DIVISION is required for executable programs but not for copybooks. The ENVIRONMENT and DATA divisions are technically optional but are almost always included in practical programs, especially when working with files or variables.
Changing the order of the divisions will cause compilation errors. COBOL requires the divisions to appear in the exact sequence: IDENTIFICATION, ENVIRONMENT, DATA, PROCEDURE. This strict structure is part of COBOL's design philosophy for clarity and readability.
While there are different dialects of COBOL (IBM COBOL, Micro Focus COBOL, GnuCOBOL, etc.), the four main divisions and their sequence are standard across all ANSI-compliant COBOL compilers. Some modern COBOL implementations might offer extensions or relaxed rules, but the core division structure remains the same.
No, a COBOL program can have only one PROCEDURE DIVISION. To organize different functionalities, you should use sections and paragraphs within the PROCEDURE DIVISION or split your code into multiple programs that call each other. Modern COBOL also supports modules and object-oriented structures for better code organization.