In COBOL, there are 4 Divisions.
1. Identification Division
2. Environment Division
3. Data Division
4. Procedure Division
Let’s explore each division one by one.
1. IDENTIFICATION DIVISION
This is the first division in COBOL Program and is mandatory.
Identification division uniquely identifies the name of the program and the name of the program can be a maximum of 8 characters and the program name is mandatory.
Some important points about the IDENTIFICATION DIVISION:
- IDENTIFICATION DIVISION must contain the Program name. Program Name is mandatory.
- There are some optional details like Author Name, installation date on which we write this particular program is and the date on which this particular program we compile and optional security level details.
So, in the above screenshot, you can see that this particular program has the name as IDDIV which you need to give after the keyword PROGRAM-ID.
Optional details are –
- Name of the Author is ‘Sandeep’.
- Installation related details.
- Date on which the particular program is written and compiled.
- The Security level of this particular program can be a comment which can describe the security of the file like whether the file is Confidential, Private, General or Public.
2. ENVIRONMENT DIVISION
ENVIRONMENT DIVISION contains the details about machine related and the files which we use in the COBOL Program.
Some important points about ENVIRONMENT DIVISION:
- It must follow the IDENTIFICATION DIVISION.
- ENVIRONMENT DIVISION is an Optional Division.
- This contains two sections
- CONFIGURATION SECTION.
- INPUT-OUTPUT SECTION.
2.1 CONFIGURATION SECTION
- The details in the CONFIGURATION SECTION are optional.
- CONFIGURATION SECTION contains the machine related details like Source Computer, Target computer, and Special-names paragraph.
2.2 INPUT-OUTPUT SECTION
INPUT-OUTPUT Section contains the definition of the files which we use in the input and output of the program. We also call INPUT-OUTPUT as the Logical files in the Program. These Logical Files must be linked to an external device where that file is located physically.
Syntax:
SELECT LOGICALFL ASSIGN TO PHYSICAL
ORGANIZATION IS ORG-TYPE
ACCESS MODE IS ACCESS-TYPE
FILE STATUS IS FL-STATUS
3. DATA DIVISION
Data Division describes the data items used in the program. It has 3 major sections
- FILE SECTION
- WORKING-STORAGE SECTION
- LINKAGE SECTION
It consists of 2 more sections. But we do not use this very frequently
- REPORT SECTION – It is used for preparing Reports.
- COMMUNICATION SECTION – Communication section is used for communicating between 2 programs running simultaneously.
FILE SECTION
- File section defines File definition of all the programs used in the program.
- Under this, it has FD (File Description) for each file to define the layout of the file.
WORKING-STORAGE SECTION
It defines the temporary variables used in the program
LINKAGE SECTION
When programs(main programs) calls another program(subprogram) we need to use LINKAGE SECTION
We define this in the subprogram.
Defines the arguments which passes by the main program in the LINKAGE-SECTION as well.
PROCEDURE DIVISION
- This is the main division where the business logic is written
- All COBOL programs must have Procedure division.
- Procedure Division contains user defined Sections, Paragraphs, Sentences, Statements, Clause and Verbs.