TExcelTAD
Home › COBOL › COBOL Intro

COBOL Intro

COBOL (COmmon Business-Oriented Language) is a programming language designed for business data processing: reading records, doing exact decimal arithmetic on money, and printing reports. It was created in 1959 by a committee of computer makers, users and the US government (the CODASYL committee), drawing heavily on Grace Hopper's earlier FLOW-MATIC language. The goal was a language that looked like English, so managers could read it, and that ran on machines from different vendors.

More than sixty years later, COBOL still runs a large share of the world's core banking, insurance, payroll, airline, tax and pension systems. When you withdraw cash or a government sends a benefit payment, there is a good chance a COBOL program moved the money.

Here is a complete COBOL program. Press Run to compile and run it:

cobol · try it yourself
       IDENTIFICATION DIVISION.
       PROGRAM-ID. WELCOME.
       PROCEDURE DIVISION.
           DISPLAY "Welcome to COBOL!"
           DISPLAY "Business programs since 1959."
           STOP RUN.
Welcome to COBOL!
Business programs since 1959.

Why COBOL looks the way it does

COBOL reads almost like a sentence: ADD TAX TO PRICE GIVING TOTAL. Programs are split into four divisions that separate what the program is, what machine it runs on, what data it uses and what it does. Data is described with PICTURE clauses that say exactly how many digits and characters a field holds, which maps directly onto fixed-width records on disk and tape.

Feature Why it matters for business code
Fixed-point decimal arithmetic 0.10 + 0.20 is exactly 0.30 — no binary floating-point surprises with money
Fixed-length records A 80-byte customer record is described field by field, byte by byte
English-like verbs MOVE, ADD, PERFORM, READ, WRITE are readable by auditors
Very stable language Programs written in the 1970s still compile today

Exact decimal arithmetic

The example below adds ten cents three times. In many languages, 0.1 + 0.1 + 0.1 gives 0.30000000000000004. COBOL stores the value as decimal digits, so the result is exact:

cobol · try it yourself
       IDENTIFICATION DIVISION.
       PROGRAM-ID. DECIMALS.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  WS-BALANCE     PIC 9(3)V99 VALUE 0.
       01  WS-DIME        PIC 9V99    VALUE 0.10.
       PROCEDURE DIVISION.
           ADD WS-DIME TO WS-BALANCE
           ADD WS-DIME TO WS-BALANCE
           ADD WS-DIME TO WS-BALANCE
           DISPLAY "Balance: " WS-BALANCE
           STOP RUN.
Balance: 000.30

PIC 9(3)V99 means "three digits, an implied decimal point, then two digits". You will learn PICTURE clauses in detail soon.

Where COBOL runs today

  • IBM mainframes (IBM Z) running z/OS, with Enterprise COBOL, batch jobs started by JCL, online transactions under CICS and data in DB2 or VSAM files.
  • Micro Focus / Rocket Visual COBOL on Windows and Linux servers, often after a mainframe migration.
  • GnuCOBOL, a free open-source compiler that translates COBOL to C. The examples in this course are compiled with GnuCOBOL 3.2.

Note: COBOL has been revised many times: COBOL-68, COBOL-74, COBOL-85 (structured programming with END-IF, EVALUATE, inline PERFORM), COBOL 2002 (object orientation, free format) and COBOL 2014/2023. Most production code is COBOL-85 style, which is what this course teaches first.

What you will learn

  1. The structure of a program: divisions, sections, paragraphs and the fixed column layout.
  2. Describing data with level numbers and PICTURE clauses.
  3. MOVE, arithmetic verbs, COMPUTE and edited pictures for printing money.
  4. Decisions (IF, EVALUATE, level-88 condition names) and loops (PERFORM).
  5. Tables, searching, string handling and intrinsic functions.
  6. Subprograms, files, sorting and report writing.
  7. How COBOL fits into the mainframe world (JCL, CICS, DB2) and how it is modernised.

Test yourself

What does COBOL stand for?

  1. Compiled Business Language
  2. Common Business-Oriented Language
  3. Computer Oriented Basic Language
  4. Common Binary Object Language

Why is COBOL popular for financial code?

  1. It has the fastest floating-point unit support
  2. It does exact fixed-point decimal arithmetic on fields with a declared number of digits
  3. It has no data types at all
  4. It only runs on personal computers

Which compiler is used to run the examples in this course?

  1. IBM Enterprise COBOL
  2. Micro Focus Visual COBOL
  3. GnuCOBOL 3.2
  4. COBOL-74 interpreter