COBOL IDENTIFICATION & ENVIRONMENT
The first two divisions describe the program rather than do any work. They are short, but you will see them at the top of every real COBOL program.
IDENTIFICATION DIVISION
The only required paragraph is PROGRAM-ID. The others are documentation that old compilers copied into the
listing. COBOL 2002 made them obsolete, but they are still common in existing code, and GnuCOBOL accepts them.
| Paragraph | Meaning |
|---|---|
PROGRAM-ID. name. |
The program's name (required). Used by CALL |
AUTHOR. |
Who wrote it |
INSTALLATION. |
Where it runs (company or data centre) |
DATE-WRITTEN. |
When it was written |
DATE-COMPILED. |
Filled in by some compilers in the listing |
SECURITY. |
Free-text classification notes |
IDENTIFICATION DIVISION.
PROGRAM-ID. PAYROLL-01.
AUTHOR. ADA DEVELOPER.
INSTALLATION. TAD BANK DATA CENTRE.
DATE-WRITTEN. 2026-01-15.
SECURITY. INTERNAL USE ONLY.
PROCEDURE DIVISION.
DISPLAY "Payroll program PAYROLL-01"
STOP RUN.Payroll program PAYROLL-01
Tip: Modern teams keep the change history in version control and a comment block, and write only
PROGRAM-IDin the IDENTIFICATION DIVISION. The keywordID DIVISIONis an accepted abbreviation.
ENVIRONMENT DIVISION
This division isolates everything that depends on the machine, so moving a program to another computer should only mean changing this part. It has two sections:
| Section | Paragraphs | Purpose |
|---|---|---|
CONFIGURATION SECTION |
SOURCE-COMPUTER, OBJECT-COMPUTER, SPECIAL-NAMES |
Describes the compiling/running machine and special settings |
INPUT-OUTPUT SECTION |
FILE-CONTROL, I-O-CONTROL |
Connects each file in the program to a real file or data set |
SPECIAL-NAMES
SPECIAL-NAMES changes a few language-wide settings. The most famous is DECIMAL-POINT IS COMMA, used in
countries that write 1.234,56 instead of 1,234.56. It swaps the roles of . and , in numeric literals
and edited pictures:
IDENTIFICATION DIVISION.
PROGRAM-ID. EURO-FORMAT.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.
DECIMAL-POINT IS COMMA.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-PRICE PIC 9(5)V99 VALUE 1234,56.
01 WS-SHOWN PIC ZZ.ZZ9,99.
PROCEDURE DIVISION.
MOVE WS-PRICE TO WS-SHOWN
DISPLAY "Preis: " WS-SHOWN " EUR"
STOP RUN.Preis: 1.234,56 EUR
The picture ZZ.ZZ9,99 replaces leading zeros with spaces (Z), which is why there are two spaces after
Preis:. Edited pictures get their own lesson later.
SPECIAL-NAMES can also define a currency sign, named character classes and symbolic characters:
IDENTIFICATION DIVISION.
PROGRAM-ID. CLASS-DEMO.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.
CLASS HEX-DIGIT IS "0" THRU "9" "A" THRU "F".
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-CODE-1 PIC X(4) VALUE "1F3A".
01 WS-CODE-2 PIC X(4) VALUE "12G7".
PROCEDURE DIVISION.
IF WS-CODE-1 IS HEX-DIGIT
DISPLAY WS-CODE-1 " is hexadecimal"
END-IF
IF WS-CODE-2 IS NOT HEX-DIGIT
DISPLAY WS-CODE-2 " is not hexadecimal"
END-IF
STOP RUN.1F3A is hexadecimal
12G7 is not hexadecimal
INPUT-OUTPUT SECTION
FILE-CONTROL has one SELECT entry per file. It gives the file an internal name and says where the data lives
and how it is organised. You will use it in the files lesson:
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT CUSTOMER-FILE ASSIGN TO "customers.dat"
ORGANIZATION IS LINE SEQUENTIAL
FILE STATUS IS WS-CUST-STATUS.On a mainframe the ASSIGN TO name is a DD name such as CUSTIN, and the JCL that starts the job decides
which data set that DD name points to. The program never contains the real data set name, which is exactly the
portability the ENVIRONMENT DIVISION was designed for.
Test yourself
Which paragraph is required in the IDENTIFICATION DIVISION?
- AUTHOR
- DATE-WRITTEN
- PROGRAM-ID
- INSTALLATION
What does DECIMAL-POINT IS COMMA change?
- Nothing at run time
- The roles of
.and,in numeric literals and edited pictures - It makes all numbers integers
- It changes the currency sign
Where are files connected to real data sets?
- FILE SECTION
- FILE-CONTROL in the INPUT-OUTPUT SECTION
- PROCEDURE DIVISION
- IDENTIFICATION DIVISION