Comprehensive Study Notes on COBOL Programming Language Fundamentals

Industry Impact and Global Role of COBOL

  • Mainframe Backbone: COBOL remains the primary foundational language for mainframe computing and global enterprise infrastructure.

  • Financial Infrastructure Powerhouse: Critical global business transactions rely heavily on systems powered by COBOL:

    • Approximately 96%96\% of Automated Teller Machine (ATM) transactions run on COBOL.

    • Processes 80%80\% of all in-person financial transactions across banking, insurance, and commerce sectors.

    • Powers nearly every credit card transaction processing system globally.

  • Enterprise Dependence:

    • 71%71\% of Fortune 500 companies rely on COBOL for core daily operational workflows.

    • Over 60 million60\text{ million} hospital patients receive healthcare services managed by COBOL backend systems.

    • Over 500 million500\text{ million} mobile phone connections interface directly or indirectly with COBOL applications.

    • Manages over 2,0002\text{,000} shipping containers and 20,00020\text{,000} retirement plans worldwide.

  • Active Development: Over 1 billion1\text{ billion} lines of new COBOL code are written globally each year.

History and Standard Evolution

  • Full Name Definition: COBOL stands for Common Business Oriented Language.

  • Creation and Governance: Developed in 1959 by the Conference on Data Systems Languages (CODASYL) committee.

  • First Compilers: Released in 1960.

  • ANSI Standardization Timeline:

    • 1968 Standard: The first official standardized version established by the American National Standards Institute (ANSI).

    • 1974 Standard: Introduced optimizations focused on runtime efficiency and performance.

    • 1985 Standard: Enhanced language structure, control blocks, and functional versatility.

    • 2002 Standard: Integrated object-oriented programming (OOP) principles and capabilities.

    • 2014 Standard: Introduced support for method overloading.

  • Primary Domains: Universally deployed across business, banking, insurance, and government IT ecosystems.

  • Core Strengths: Simple syntax structure, platform portability, and long-term maintainability.

  • Core Weaknesses: High verbosity, rigid structural formatting, and lack of suitability for complex scientific computing.

Advantages and Disadvantages of COBOL

  • Advantages:

    • Readability: Features an English-like syntax that facilitates straightforward reading and self-documentation.

    • Lifecycle Simplicity: Simple to develop, execute, and maintain across software life cycles.

    • Tooling Support: Broad availability of testing, static analysis, and execution debugging tools.

    • High-Level Structure: Structured, self-documenting high-level design that simplifies business rule auditing.

    • Backward Compatibility: Strong commitment to maintaining compatibility across older legacy versions.

    • Open Availability: Free and open-source availability.

    • Batch Data Processing: Optimized to process massive, high-volume batch data routines efficiently.

    • Portability: Highly portable and platform-independent across distinct hardware operating systems.

  • Disadvantages:

    • Code Length: Verbose syntax leads to extensive codebase lengths compared to modern languages.

    • Compilation Overhead: Requires higher compilation times based on source program length and resource overhead.

    • Inapplicable for Scientific Computing: Designed strictly for business operations; unsuitable for complex mathematical calculations.

    • Redundant Coding: Requires significantly more lines of code to express concise algorithmic logic.

    • Low-Level Debugging: Programmers must understand machine language and assembly concepts to analyze system core dumps when fatal failures occur.

Core Terminology and Definitions

  • Abend: An unexpected or abnormal termination of a program caused by runtime exceptions in logic or input data.

  • Syntax: System-defined structural standards and grammar rules required when coding statements (e.g., MOVE, IF, PERFORM).

  • Character String: A sequence of valid characters used to identify or name data elements.

  • Statement: An individual programmatic instruction or command in COBOL (e.g., MOVE, ADD, DISPLAY).

  • Sentence: A logical grouping of one or more COBOL statements terminated strictly by a period followed by a space.

  • Paragraph / Routine: A named block of one or more sentences coded separately inside the PROCEDURE DIVISION to perform a specific function. Must be called using the PERFORM verb.

  • Section: A cohesive collection of paragraphs grouped together within the PROCEDURE DIVISION. Must be called using the PERFORM verb.

  • Division: Top-level structural units used to divide a COBOL source file (IDENTIFICATION DIVISION, ENVIRONMENT DIVISION, DATA DIVISION, and PROCEDURE DIVISION).

  • Separator: Characters used to separate strings or words (e.g., spaces, commas).

  • Delimiter: Character flags used to mark the beginning and end of string values (e.g., single quotes ', double quotes ").

  • Condition: An expression evaluated to either TRUE or FALSE that determines control flow execution.

  • Variable / Data Item: A named memory pointer holding a data value processed during execution.

  • Constant: A variable whose assigned value remains completely fixed throughout program execution.

  • Figurative Constants: Predefined system keywords that represent fixed values (e.g., ZERO, SPACES).

  • Literal: An explicit value directly assigned to a variable.

  • Scope Terminator: A reserved keyword that marks the end of specific conditional or operational statements (e.g., END-IF, END-PERFORM).

  • Arithmetic Expression: Formatted mathematical formulas combining variables with arithmetic operators (+, -, *, /). Example: WS-A = WS-B + WS-C.

  • Physical File: The actual data file stored on persistent physical media containing structured records.

  • Logical File: The internal variable name declared within the program that references a physical file.

  • Array / Table: A contiguous sequence of identical data elements accessed by positional index numbers. Known strictly as a Table in COBOL.

  • Binary Search: An efficient search algorithm executed on pre-sorted arrays that repeatedly splits data intervals in half until target items are located.

  • Compiler: A system tool that translates high-level COBOL source code into low-level machine-readable object code.

  • Load Modules: Executable program components generated after source code compilation and linkage.

Hierarchical Structure of COBOL Programs


Overall Structure of COBOL Programs
  • Hierarchy Cascade: Program elements decrease in scope from macro-structures to atomic units:

    • COBOL Program→DIVISION→Section→Paragraph→Sentence→Statement→Character Strings\text{COBOL Program} \rightarrow \text{DIVISION} \rightarrow \text{Section} \rightarrow \text{Paragraph} \rightarrow \text{Sentence} \rightarrow \text{Statement} \rightarrow \text{Character Strings}

  • Structural Elements Breakdown:

    • Character: The foundational, indivisible unit of language structure.

    • Word: Formed by combining one or more individual characters.

    • Clause: A combination of words and characters defining specific properties of a data entry (e.g., FD clause, PICTURE clause).

    • Statement: A syntactically complete instruction located in the PROCEDURE DIVISION beginning with an operational verb.

    • Sentence: A series of statements ending with a period followed by a space.

    • Paragraph: A logical grouping of one or more sequential sentences.

    • Section: A logical block containing one or more paragraphs.

    • Division: Top-tier program blocks; every complete COBOL program consists of four standardized divisions in strict order.

The Four Divisions of COBOL

  • 1. IDENTIFICATION DIVISION:

    • The initial required division of any program.

    • Contains metadata identifying the program name, version, author, and documentation parameters.

  • 2. ENVIRONMENT DIVISION:

    • Specifies the hardware environment and system interfaces for program compilation and execution.

    • CONFIGURATION SECTION: Specifies the source computer (SOURCE-COMPUTER) and execution target (OBJECT-COMPUTER).

    • INPUT-OUTPUT SECTION: Defines external physical files and maps them to internal logical files.

  • 3. DATA DIVISION:

    • Declares all data variables, memory allocations, and file formats.

    • FILE SECTION: Details the specific record formats and logical file descriptors (FD).

    • WORKING-STORAGE SECTION: Defines working variables, constants, temporary accumulators, and data structures required for program execution.

  • 4. PROCEDURE DIVISION:

    • Contains the executable business logic constructed with user-defined sections, paragraphs, clauses, and statements.

COBOL Coding Form and Column Layout

  • Coding Sheet Standard: COBOL requires explicit character column positioning for lines of code. Program text must conform to defined spatial boundaries.


COBOL Coding Sheet Column Layout
  • Columns 1–6 (Sequence Number Area):

    • Reserved strictly for line sequence tracking numbers.

    • Automatically increments with each new line added.

    • Completely ignored by the COBOL compiler during translation.

    • Divided into two distinct sub-fields:

    • Columns 1–3: Represents the current page number.

    • Columns 4–6: Represents the current line number on the page.


Sequence Number Area Example in Editor
  • Column 7 (Indicator Area):

    • Accepts specific control indicator characters:


Indicator Area Column 7 Special Characters
  • - (Hyphen): Continuation line. Indicates that a statement, entry, clause, or string literal from the preceding line is being continued in Area B of the current line.

  • * (Asterisk): Comment line. The entire line across Area A and Area B is treated as non-executable developer commentary.

  • / (Forward Slash): Page Eject / Form Feed. Triggers a print jump to the top of the next page when producing hardcopy output reports.

    • Columns 8–11 (Area A):

  • Strictly reserved for major structural headers and top-level definitions:

    • Division headers

    • Section headers

    • Paragraph names/headers

    • Data level indicators (01 and 77 level numbers)

    • Declaratives control markers (DECLARATIVES and END DECLARATIVES)

    • Structural scope boundaries (END PROGRAM, END CLASS, END METHOD)

    • Columns 12–72 (Area B):

  • Reserved for standard program operations:

    • Procedure statements and sentences

    • Subordinate data entries and clauses

    • Continuation content from previous lines

    • Columns 73–80 (System Generated Number):

  • Reserved for legacy card-punch identification or system tracking codes; stripped and ignored by the compiler.

Character Set, Words, Variables, and Literals

  • Characters: Atomic building blocks of COBOL syntax.

  • Words:

    • User-defined Words: Created by developers to identify variables, records, and routines. Maximum length is 30 bytes30\text{ bytes} (excluding level numbers). Examples: MTHPROG1, STD-GENDER.

    • Reserved Words: Predefined keywords reserved by the system with specialized meanings. Sub-categories include keywords, optional words, figurative constants, special character words, and special registers. Examples: ACCEPT, SKIP1, ZERO.

  • Variables (Data Items):

    • Memory pointers allocated to store dynamic execution data.

    • Must be explicitly declared in the DATA DIVISION with a data type and storage length specification (except for group items).

    • Examples: WS-A, WS-VAR, WS-TOTAL, WS-INPUT, WS-OUTPUT.

  • Literals:

    • Explicit fixed data values directly assigned to variables:

    • Non-numeric Literals: Text strings enclosed in quotation marks (") or apostrophes ('). Can contain any valid character from the computer's character set. Examples: "HELLO", "THIS ISN'T WRONG".

    • Numeric Literals: Numerical values that can include an algebraic sign (+ or -) and a decimal point. Coded directly without quotation marks. Examples: 1234, -1234.

  • Constants:

    • Numeric Constants: Fixed numeric values that remain static throughout program execution (e.g., 01 WS-PI PIC 9(2)V9(2) VALUE 3.14. where 3.14 is a numeric constant).

    • Alphanumeric / Non-numeric Constants: Fixed string values assigned to variables that never change during execution (e.g., 01 WS-HI PIC X(05) VALUE "HI".).

Figurative Constants

  • Definition: System-defined keywords that act as dynamic replacements for standard literal values like spaces or zeros.


Figurative Constants Descriptions
  • Figurative Constant Catalog:

    • ZERO, ZEROS, ZEROES: Represents one or more numeric 0 values. ZERO specifies a single 0, whereas ZEROS or ZEROES represents two or more 0s (e.g., 01 WS-VAR PIC 9(5) VALUE ZEROES.).

    • SPACE, SPACES: Represents one or more space characters. SPACE represents a single blank character; SPACES represents multiple consecutive blanks (e.g., MOVE SPACES TO X).

    • QUOTE, QUOTES: Represents one or more quotation mark (") or apostrophe (') characters.

    • ALL: Fills an entire storage field by repeating a specified literal character or figurative constant (e.g., MOVE ALL "A" TO HEADER fills every byte position of the variable HEADER with 'A').

Internal Data Structure and Level Numbers

  • Conceptual Data Mapping:


Conceptual Storage Structure for Customer Info
  • Data record hierarchy breakdown:

    • CUSTOMER-INFO (Root Record)

      • NAME (Group Item)

      • FIRST: "MARIA"

      • LAST: "MAKILING"

      • STREET (Group Item)

      • NUMBER: "12"

      • STR-NAME: "CHAMPACA"

      • CITY: "QUEZON CITY"

      • ZIPCODE: "1118"

    • Hierarchical Data Organization with Level Numbers:


Hierarchical Data Organization with Level Numbers
  • Implementation Code:

01  CUSTOMER-INFO
    02  NAME
        03  FIRST
        03  LAST
    02  STREET
        03  NUMBER
        03  STR-NAME
    02  CITY
    02  ZIPCODE
  • Level Number Rules:

    • Valid numerical level range: 01 to 49 for standard hierarchical structures.

    • Level 01 represents top-level record boundaries and must be coded in Area A.

    • Subordinate levels (02 to 49) establish child data relationships.

    • Indentations improve readability and code structure but are not strictly required by compiler syntax rules.

    • Level numbers do not need to increment in consecutive steps (e.g., skipping from 01 to 05 to 10 is valid).

Data Naming Conventions and Rules

  • Rule 1: A data name can contain up to 30 characters30\text{ characters} in length and can include alphabetic characters (A-Z), numeric characters (0-9), and hyphens (-).

  • Rule 2: At least one character in the data name must be an alphabetic letter.

  • Rule 3: The hyphen (-) is the only permitted special symbol and must always be embedded within the name (it cannot be the starting or ending character).

  • Rule 4: Spaces and blank characters are strictly forbidden within data names.

  • Rule 5: COBOL reserved words must never be used as user-defined data names.

  • Valid Data Name Examples:

    • HOURS

    • ENDING-INVENTORY

    • SALES-TAX-TOTAL

    • A5271

    • SUM