The Four Divisions
The Four Divisions |
||||
Introduction |
At the top of the COBOL hierarchy are the four divisions. These divide the program into distinct structural elements. Although some of the divisions may be omitted, the sequence in which they are specified is fixed, and must follow the order below.
|
|||
The IDENTIFICATION DIVISION |
The IDENTIFICATION DIVISION supplies information about the program to the programmer and the compiler. Most entries in the IDENTIFICATION DIVISION are directed at the programmer. The compiler treats them as comments. The PROGRAM-ID clause is an exception to this rule. Every COBOL program must have a PROGRAM-ID because the name specified after this clause is used by the linker when linking a number of subprograms into one run unit, and by the CALL statement when transferring control to a subprogram. The IDENTIFICATION DIVISION has the following structure:
The keywords – IDENTIFICATION DIVISION – represent the division header, and signal the commencement of the program text. PROGRAM-ID is a paragraph name that must be specified immediately after the division header. NameOfProgram is a name devised by the programmer, and must satisfy the rules for user-defined names. Here’s a typical program fragment:
|
|||
The ENVIRONMENT DIVISION |
The ENVIRONMENT DIVISION is used to describe the environment in which the program will run. The purpose of the ENVIRONMENT DIVISION is to isolate in one place all aspects of the program that are dependant upon a specific computer, device or encoding sequence. The idea behind this is to make it easy to change the program when it has to run on a different computer or one with different peripheral devices. In the ENVIRONMENT DIVISION, aliases are assigned to external devices, files or command sequences. Other environment details, such as the collating sequence, the currency symbol and the decimal point symbol may also be defined here. |
|||
|
The DATA DIVISION
|
As the name suggests, the DATA DIVISION provides descriptions of the data-items processed by the program. The DATA DIVISION has two main sections: the FILE SECTION and the WORKING-STORAGE SECTION. Additional sections, such as the LINKAGE SECTION (used in subprograms) and the REPORT SECTION (used in Report Writer based programs) may also be required. The FILE SECTION is used to describe most of the data that is sent to, or comes from, the computer’s peripherals. The WORKING-STORAGE SECTION is used to describe the general variables used in the program. The DATA DIVISION has the following structure and syntax:
Below is a sample program fragment -
|
|||
The PROCEDURE DIVISION |
The PROCEDURE DIVISION contains the code used to manipulate the data described in the DATA DIVISION. It is here that the programmer describes his algorithm. The PROCEDURE DIVISION is hierarchical in structure and consists of sections, paragraphs, sentences and statements. Only the section is optional. There must be at least one paragraph, sentence and statement in the PROCEDURE DIVISION. Paragraph and section names in the PROCEDURE DIVISION are chosen by the programmer and must conform to the rules for user-defined names. Sample Program
Some COBOL compilers require that all the divisions be present in a program while others only require the IDENTIFICATION DIVISION and the PROCEDURE DIVISION. For instance the program shown below is perfectly valid when compiled with the Microfocus NetExpress compiler. Minimum COBOL program
|
|||
Comments
Tell me what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!


