Divisions in cobol
In COBOL, a division is a fundamental structural component of a COBOL program, which logically separates the program's functionality into specific sections. Each division has a specific purpose and defines how data and processes are managed. The four main divisions in COBOL are:
1. Identification Division
Purpose: Provides metadata about the program, such as the program name, author, and other related information.
Typical Contents:
PROGRAM-ID
: The name of the program.AUTHOR
: The name of the author (optional).DATE-WRITTEN
: The date the program was written (optional).SECURITY
: Information about the program's security (optional).
Example:
cobolCopy codeIDENTIFICATION DIVISION.
PROGRAM-ID. MYPROGRAM.
AUTHOR. JOHN DOE.
DATE-WRITTEN. 2024-01-01.
2. Environment Division
Purpose: Defines the environment in which the program runs. This includes the hardware and software configuration, such as file handling and system-specific details.
Typical Sections:
CONFIGURATION SECTION
: Specifies the hardware and software setup, including file control.INPUT-OUTPUT SECTION
: Defines the external devices and files the program will use.
Example:
cobolCopy codeENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT myfile ASSIGN TO 'MYDATA.DAT'.
3. Data Division
Purpose: Describes all the data elements used by the program, including variables, file structures, and other data records.
Typical Sections:
FILE SECTION
: Defines the structure of files.WORKING-STORAGE SECTION
: Defines temporary data items used during program execution.LINKAGE SECTION
: Used for passing data between programs (such as when a program is called by another program).LOCAL-STORAGE SECTION
: Holds variables that retain their values only for the duration of a specific invocation (for programs with recursion).
Example:
cobolCopy codeDATA DIVISION.
WORKING-STORAGE SECTION.
01 MY-VAR PIC 9(5).
4. Procedure Division
Purpose: Contains the program's executable code, such as statements, operations, and logic. This is where the actual processing of the program occurs.
Typical Contents:
COBOL statements such as
DISPLAY
,ADD
,MOVE
, andIF
.Control structures and loops like
PERFORM
,GOTO
, etc.
Example:
cobolCopy codePROCEDURE DIVISION.
DISPLAY 'HELLO, COBOL!'.
MOVE 10 TO MY-VAR.
DISPLAY MY-VAR.
Summary of Divisions:
Identification Division: Program metadata.
Environment Division: System configuration and file management.
Data Division: Data definitions and structures.
Procedure Division: Program logic and operations.
Each division serves a distinct role, helping organize the COBOL program into a structured and readable format.