๐งฑ Structure of a COBOL Programโ
๐ Overviewโ
A COBOL program is organized into divisions, sections, paragraphs, and statements. This structure makes the code easier to read, maintain, and understand.
๐ Divisions in COBOLโ
A COBOL program has four fixed divisions, each serving a unique purpose:
Division | Purpose |
---|---|
IDENTIFICATION | Program name and metadata |
ENVIRONMENT | System setup and file/device information |
DATA | Variable and file declarations |
PROCEDURE | The actual executable logic |
-
Each division starts at Margin A and ends when the next begins.
-
Division names are predefined and mandatory.
๐ Sections in COBOLโ
-
A section is a subdivision of a division, used mainly in the PROCEDURE DIVISION.
-
It groups related paragraphs and helps with modular programming.
๐งฉ Section Facts:
-
Begins in Margin A and can continue to Margin B.
-
Ends when a new section or division begins.
-
Predefined:
FILE SECTION
, etc. -
User-defined:
READ-FILE-SECTION
,CALC-SEC
, etc.
๐งพ Paragraphs in COBOLโ
-
A paragraph is a logical unit inside a section, especially in the PROCEDURE DIVISION.
-
Contains executable COBOL statements.
๐งฉ Paragraph Facts:
-
Starts at Margin A.
-
Has a name followed by a period (
.
). -
Ends when a new paragraph, section, or program ends.
๐น Statements in COBOLโ
- A statement is a single COBOL instruction.
๐งฉ Statement Facts:
-
Starts in Margin B.
-
Built with COBOL verbs and operands.
-
Ends with a period if itโs the last in a sentence.
Type | Description | Example |
Imperative | Executes an action | ADD A TO B |
Compiler Directive | Guides the compiler, not for execution | COPY WS-AREA. |
Conditional | Executes based on a condition | IF A > B |
Delimited Scope | Uses END-IF , END-EVALUATE , etc. for clear block endings | IF A > B ... END-IF |
๐ Tip: Use
END-IF
,END-EVALUATE
for better readability and fewer logic bugs.
๐งโ๐ป COBOL Wordsโ
COBOL uses both predefined and user-defined words.
-
Predefined Words:
MOVE
,DISPLAY
,IF
, etc. -
User-Defined Words: Programmer-defined identifiers like variables or paragraph names.
๐ Rules for User-Defined Words:
-
Must start with a letter.
-
Can be up to 30 characters.
-
No COBOL reserved words.
-
Only hyphen allowed as special character.
-
Not case-sensitive.
๐ Literals in COBOLโ
Literals are fixed values directly specified in the COBOL program source. They represent constant data used in initialization or processing.
๐งฎ Numeric Literalsโ
-
Represent constant numeric values.
-
May be positive or negative.
-
Can include decimal points.
-
Used in numeric data items (e.g., defined with
PIC 9
,PIC S9
, etc.).
๐ Non-numeric Literalsโ
-
Represent textual or alphanumeric constants.
-
Enclosed in single (
'
) or double ("
) quotes. -
Can include letters, digits, and allowed special characters.
-
Used with alphanumeric picture clauses like
PIC X
.
๐ Special Literalsโ
-
Predefined constant values in COBOL.
-
Often used to initialize data fields or in conditions.
-
Include keywords such as
SPACES
,ZEROS
,ALL
.
โ๏ธ Figurative Constantsโ
Figurative Constants are special keywords representing common constant values in COBOL.
๐งฉ Common Figurative Constants:โ
-
ZERO
,ZEROS
,ZEROES
: Represent numeric zero. -
SPACE
,SPACES
: Represent blank spaces. -
HIGH-VALUE
,HIGH-VALUES
: Represent the highest possible character value. -
LOW-VALUE
,LOW-VALUES
: Represent the lowest possible character value. -
QUOTE
,QUOTES
: Represent quotation marks. -
ALL literal
: Repeats a single character across the field.