📜 COBOL Fundamentals & Legacy Power
🎯 What is COBOL?
COBOL (Common Business-Oriented Language) is one of the oldest high-level programming languages, designed in 1959 by the CODASYL consortium. It was created for business, finance, and administrative systems. COBOL is self-documenting, English-like, and excels at batch processing and transaction handling. Today, over 95% of ATM transactions, 80% of in-person credit card swipes, and 43% of banking systems run on COBOL. It handles 220 billion lines of production code globally.
🔬 Key Characteristics
- Verbose & Readable: Syntax mimics English (ADD, SUBTRACT, MOVE, IF)
- Division Structure: IDENTIFICATION, ENVIRONMENT, DATA, PROCEDURE divisions.
- Fixed Format (traditional): Area A (col 8-11) and Area B (col 12-72).
- Strong Data Typing: PICTURE clauses define exact decimal/memory layout.
- Record-Oriented I/O: Native file processing (sequential, indexed, relative).
- Decimal Arithmetic: COBOL uses packed-decimal (COMP-3) for precise financial math.
🏢 Where COBOL Dominates
Banking core systems, insurance claims, government systems (Social Security, IRS), airline reservation systems, and mainframe transaction processors (CICS, IMS).
📋 The 4 DIVISIONS Structure
🎯 IDENTIFICATION DIVISION
Program metadata: PROGRAM-ID, AUTHOR, DATE-WRITTEN. Essential for compiler recognition.
📌 ENVIRONMENT DIVISION
Specifies hardware/software environment: CONFIGURATION SECTION, INPUT-OUTPUT SECTION (file assignment).
🗃️ DATA DIVISION
Declares variables: WORKING-STORAGE (local vars), LINKAGE (parameters), FILE SECTION (record structures).
⚙️ PROCEDURE DIVISION
Executable logic: paragraphs, sentences, statements, and PERFORM loops.
🔢 Picture Clauses & Data Types
🎯 PICTURE (PIC) Definition
PIC defines data format: 9 (numeric), X (alphanumeric), A (alphabetic), S (sign), V (implied decimal). Example: PIC 9(5)V99 = 5 digits, 2 decimal places.
📊 Usage Clauses
- COMP-3: Packed-decimal for arithmetic.
- BINARY/COMP: Binary representation.
- DISPLAY: Default human-readable.
- OCCURS: Table definition.
📦 Working-Storage & Variable Scope
🎯 WORKING-STORAGE SECTION
Defines local variables, constants, and intermediate fields. Level numbers (01-49) indicate hierarchy. 88-level condition names define boolean conditions.
🧮 Arithmetic & COMPUTE
🎯 COBOL Arithmetic Verbs
ADD, SUBTRACT, MULTIPLY, DIVIDE, COMPUTE. COMPUTE is most flexible using mathematical operators (+, -, *, /). ROUNDED, ON SIZE ERROR clauses.
🔀 IF / ELSE / EVALUATE
🎯 IF ... ELSE ... END-IF
Supports relational operators: =, >, <, >=, <=, NOT. Also EVALUATE (like switch) for multi-branch logic.
🔄 PERFORM Loops & Iteration
🎯 PERFORM Statement Variants
PERFORM VARYING (FOR loop), PERFORM UNTIL, PERFORM TIMES, and in-line PERFORM. Supports nested loops and EXIT PERFORM.
📊 Tables (Arrays) & OCCURS
🎯 OCCURS Clause
Defines arrays/tables. OCCURS DEPENDING ON (ODO) for variable-length tables. Can be 1D or 2D.
💾 File Handling (Sequential/Indexed)
🎯 Sequential, Relative, Indexed Files
COBOL file verbs: OPEN, READ, WRITE, REWRITE, DELETE, CLOSE. File organization: SEQUENTIAL, RELATIVE, INDEXED. FILE STATUS for error checking.
📝 STRING, UNSTRING & INSPECT
🎯 Powerful String Operations
STRING concatenates, UNSTRING splits, INSPECT counts/replaces characters. Essential for report generation and data parsing.
🔌 Subprograms & CALL
🎯 Modular Programming
CALL statement invokes subprograms. Linkage Section defines parameters. USING BY CONTENT / BY REFERENCE controls data passing. CANCEL releases subprogram.
⚙️ SORT/MERGE & Report Writer
🎯 High-Performance Sorting
COBOL has built-in SORT and MERGE verbs for large datasets. INPUT PROCEDURE / OUTPUT PROCEDURE for custom processing. Report Writer (RW) simplifies formatted reports.
🛡️ Exception Handling & Declaratives
🎯 DECLARATIVES & USE Statements
Declaratives section handles file errors, exceptions, and debugging. USE AFTER EXCEPTION traps file I/O errors. Also ON EXCEPTION clause for arithmetic.
🚀 Modern COBOL & Integration
🎯 COBOL 2023+ Features
Modern COBOL supports: XML/JSON generation and parsing, dynamic memory allocation (ALLOCATE), object-oriented COBOL (classes, methods, inheritance), and integration with Java/.NET (JNI, Managed COBOL).
🔌 Interoperability
- CICS (Transaction Server) for online processing
- IMS DB/DC hierarchical databases
- DB2 SQL embedded statements (EXEC SQL)
- RESTful APIs via JSON and HTTP
- Containers (z/OS Container Extensions) & DevOps