Skip to main content

๐Ÿงฑ 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:

DivisionPurpose
IDENTIFICATIONProgram name and metadata
ENVIRONMENTSystem setup and file/device information
DATAVariable and file declarations
PROCEDUREThe 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.

TypeDescriptionExample
ImperativeExecutes an actionADD A TO B
Compiler DirectiveGuides the compiler, not for executionCOPY WS-AREA.
ConditionalExecutes based on a conditionIF A > B
Delimited ScopeUses END-IF, END-EVALUATE, etc. for clear block endingsIF 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:

  1. Must start with a letter.

  2. Can be up to 30 characters.

  3. No COBOL reserved words.

  4. Only hyphen allowed as special character.

  5. 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.