COBOL
COBOL (Common Business-Oriented Language) was created in 1959 to process business records. A COBOL program reads almost like English sentences, runs paragraph by paragraph, and handles decimal money exactly. It still moves a large share of the world's banking and insurance transactions.
Paradigm: Linear Programming
What Makes COBOL Special
- Four divisions. Every program is organized into
IDENTIFICATION,ENVIRONMENT,DATAandPROCEDUREdivisions, always in that order. The layout is part of the language. - Data is described by pictures.
PIC 9(5)V99declares a number with five integer digits and two decimals. Fields, records and file layouts are defined by their exact shape. - Exact decimal arithmetic. Numbers are stored as decimal digits, so
0.10 + 0.20is exactly0.30. That is essential for money, and binary floating point cannot promise it. - Paragraphs and PERFORM. The procedure division is a list of named paragraphs. Control flows from one to the next, and
PERFORMruns a paragraph as a subroutine. - English-like statements.
MULTIPLY HOURS BY RATE GIVING GROSS-PAYis a complete, readable statement. This was meant to let auditors and managers follow the logic.
Example: Gross pay calculation
IDENTIFICATION DIVISION.
PROGRAM-ID. PAYROLL.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 HOURS PIC 99 VALUE 40.
01 RATE PIC 99V99 VALUE 15.50.
01 GROSS-PAY PIC 9(5)V99.
01 SHOW-PAY PIC Z(4)9.99.
PROCEDURE DIVISION.
MAIN-PARA.
MULTIPLY HOURS BY RATE GIVING GROSS-PAY.
MOVE GROSS-PAY TO SHOW-PAY.
DISPLAY "Gross pay: " SHOW-PAY.
STOP RUN.
How It Works
- The
DATA DIVISIONdeclares every variable up front.01marks a top-level item andPICgives its exact format. RATEholds two decimals (99V99; theVis an implied decimal point), so 15.50 is stored exactly.- The
PROCEDURE DIVISIONruns its statements in order: multiply, move to an edited field, display, stop. The result is620.00. PIC Z(4)9.99is an edited field: leading zeros are suppressed so the report shows620.00instead of00620.00.- Columns matter in fixed-format COBOL: code starts in column 8 and statements end with a period.
History and Where It Is Used
COBOL runs core banking, insurance, payroll, airline and government systems, typically on mainframes, and estimates run to hundreds of billions of lines still in production. Modern implementations include IBM Enterprise COBOL and the free GnuCOBOL, and modernization projects are a real career path.
Learn More
- GnuCOBOL
- COBOL (Wikipedia)
- Back to Linear Programming or the PGP roadmap.