Unveiling the Hierarchical Structure of COBOL: A Journey Through Divisions to Statements

Sanket Nawale
5 min readDec 29, 2023

--

In the vast realm of programming languages, COBOL emerges with its distinct organizational framework. Embracing a hierarchal structure, COBOL unfolds with precision and clarity, outlined by a series of compositional tiers. This captivating structure resonates through divisions, sections, sentences, statements, and the intricate interplay between words and verbs.

DIVISIONS | SECTIONS | SENTENCE | STATEMENT | WORD /VERB

The Architecture of COBOL: Navigating Divisions and Their Significance

DIVISION SECTIONS: 4 DIVISIONS IN COBOL, IDENTIFICATION, ENVIRONMENT DIVISION, DATA DIVISION, PROCEDURE DIVISION

1.IDENTIFICATION DIVISION:

The IDENTIFICATION DIVISION is the smallest, simplest, and least significant division of a COBOL program. As the name indicates, it supplies identifying information about the program.

The IDENTIFICATION DIVISION has no effect on the execution of the program but is, nevertheless, required as a means of identifying the program to the computer. The IDENTI FICATI0N DIVISION is divided into paragraphs, not sections. The following paragraphs may be coded:

EXAMPLE
IDENTIFICATION DIVIS ION.
PROGRAM-ID. SAMPLE1.
[AUTHOR. comment-entry]
[INSTALLATION. comment-entry]
[DATE-WRITTEN. comment-entry]
[DATE-COMPILED, comment-entry]
[SECURITY. comment-entry]

The division name, IDENTIFICATION DIVISTON, is coded in Area A. Paragraph- names are also coded in Area A, and each must be followed by a period.

AS PROGRAM- ID is a paragraph-name, the user-defined program name SAMPLE1 may appear on the same line as PROGRAM -ID, Or on the next line in Area B. In either case, PROGRAM- ID and the program name must each be followed by a period.

Each paragraph-name is followed by a period and at least one space. The actual entry following the paragraph-name is called a “comment entry” because it is treated as a comment; it can contain any character Including a period. If used, AUTHOR Would include the name of the programmer; INSTALLATION would be the name of the company or the computer organization; DATE-WRITTEN is the date the program was coded. We need identification division and procedure division to display output minimum. It is the first and only mandatory division of every Cobol program.

2.ENVIRONMENT DIVISION: ENVIRONNENT DIVISION is the only machine-dependent division of a COBOL program. It supplies information about the computer equipment to be used in the program.( talk about the environment in which we write the program, also talk about the input output file.) That is, the entries in this division will be dependent on (1) the computer system and (2) the specific devices or hardware used in the program.

The ENVIRONMENT DIVISION is composed of two sections:
configuration section.
input-Output section.

  • CONFIGURATION SECTION PROVIDES INFORMATION ABOUT THE SYSTEM ON WHICH THE PROGRAM IS WRITTEN AND EXECUTED. IT CONSISTS OF TWO PARAGRAPHS −
  • SOURCE COMPUTER − SYSTEM USED TO COMPILE THE PROGRAM.
  • OBJECT COMPUTER − SYSTEM USED TO EXECUTE THE PROGRAM.
  • INPUT-OUTPUT SECTION PROVIDES INFORMATION ABOUT THE FILES TO BE USED IN THE PROGRAM. IT CONSISTS OF TWO PARAGRAPHS −
  • FILE CONTROL − PROVIDES INFORMATION OF EXTERNAL DATA SETS USED IN THE PROGRAM.
  • I-O CONTROL − PROVIDES INFORMATION OF FILES USED IN THE PROGRAM.

3.DATA DIVISION:

The DATA DIVISIOW is that part of a COBOL program that defines and describes fields, records, and field’s in storage. Any area of storage that is required for the processing of data must be established in the DATA DIVISTON. We focus on the following two main sections of the DATA DIVISION in this text:

THE TWO MAIN SECTIONS OF THE DATA DIVISION
1. FILE SECTTON — defines all input and output files.
2. WORKING-STORAGE SECTION-reserves storage for fields not part of input or output but required for processing, These include constants, end-of-file indicators, and work areas.
The sections of the DATA DIVISION must be defined in the sequence shown.
Any program that (1) reads data from input files or (2) produces output files, requires a FILE SECTION to describe the input and output areas, Since batch programs typically read input files, operate on them, and produce output files, the FILE SECTION will be an essential part of all such programs.

WE DECLARE VARIABLE IN DATA DIVIDION 1. CONSTANT — DO NOT CHANGE 2. VARIABLE- VARIABLE KEEPS CHANGING

WE DEFINE A VARIABLE LIKE THIS: LEVEL NUMBER DATA NAME PICTURE CLAUSE VALUE CLAUSE

PIC 9(3) — -à DATA TYPE AND SIZE OF DATA: WE HAVE NUMERIC 9, ALPHABETIC A, ALPHANUMERIC X AND SIGNED S

VALUE CLAUSE IS USED TO INITILIZE THE VARIABLE.

FOR EXAMPLE : 01 DATA1 PIC 9(9) VALUE 123456789.

WE WILL SEE FILE SECTION IN DETAIL IN FILE HANDLING SECTION.

4.PROCEDURE DIVISION

The PROCEDURE DIVISION consists of optional declaratives and procedures that contain sections, paragraphs, sentences and statements. The PROCEDURE DIVISION contains the actual logic or operations to be performed to complete the task.

The PROCEDURE DIVISION may contain declarative as well as non-declarative procedures. Program execution starts from PROCEDURE DIVISION. PROCEDURE DIVISION ends with STOP RUN or GO BACK statements.

Sections are the logical subdivision of program logic. A section is a collection of paragraphs

Crafting Logic: Decoding Sentences, Statements, and Verbs

The realm of COBOL’s logic is sculpted through the interplay of sentences and statements, where each holds a distinct role:

STATEMENT VS SENTENCES: A STATEMENT IS MADE OF ONE OR MORE CHARACTER OF STRING.

A SENTENCE IS ONE OR MORE STETEMENTS THAT ARE TERMINATED BY PERIOD(.) .

EXAMPLE: ADD A TO B GIVING C -à STATEMENT1

MOVE A TO B -à STATEMENT1

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — -

MOVE A TO B

DISPLAY “THIS IS COBOL PRORGRAM”. — — — à THIS IS SENTENCE WITH 2 STATEMENTS.

VERBS These action-oriented powerhouses infuse life into COBOL programs. From ACCEPT and ADD to ALTER and CALL, verbs direct the program’s operations, embodying the program’s purpose.

As our voyage through the corridors of COBOL structure draws to a close, we reflect on the elegance of this hierarchal arrangement. COBOL’s structure not only nurtures organized and efficient code but also serves as a testament to the marriage of human creativity and computational precision, a symphony where logic dances in harmony with innovation. In mastering COBOL’s structure, we uncover the artistry within engineering, where each component contributes to the composition of software poetry — a reflection of the ever-evolving dialogue between humans and machines.

--

--

Sanket Nawale

I am a ICT Student , I am Z Mainframe campus ambassador |