Language basics
27 steps in 9 sets of COBOL.
COBOL is the oldest language in this collection and the one most likely to be moving your money right now: designed in 1959 for business data processing, it still clears credit card batches, settles insurance claims, and prints statements on mainframes that have outlived every rewrite plan. It reads like memos from a very careful office — data described down to the digit, verbs that spell out what they do, a period at the end of every sentence.
This tour covers the modern free-format core as GnuCOBOL compiles it: the division skeleton, PICTURE clauses and edited output, MOVE and REDEFINES, the arithmetic verbs, IF and EVALUATE and level 88 condition names, the PERFORM family of loops, OCCURS tables with STRING and INSPECT, and intrinsic functions with CALL. The encore ships complete programs. Every seed compiles warning-free and runs. COBOL's words run long, so the pace bars sit lower here than in any other language — the typing is the same, the tokens are just bigger.
The program shape
- The program shapeThe smallest COBOL program: two divisions, two sentences, and a full stop on each.
- WORKING-STORAGEThree level 01 items declare the lighthouse's data before any statement runs.
- ACCEPT FROMACCEPT reads system values — the date and the clock — without touching the keyboard.
Pictures
- PICTURE clausesThe PIC clause is the type system: 9 for digits, X for anything, V and S invisible.
- Edited picturesMOVE into an edited picture is how COBOL formats numbers for people.
- Group itemsLevel numbers build a record: the 01 owns the group, the 05s are its fields.
Moving data
- MOVE semanticsMOVE fits the sender to the receiver: padding with spaces one way, cutting the other.
- INITIALIZEOne INITIALIZE wipes a whole record: numbers to zero, text to spaces.
- REDEFINESREDEFINES lays a second layout over the same bytes: one date, two views.
Arithmetic
- ADD and SUBTRACTVerb-first arithmetic that reads like an order to a stockroom clerk.
- COMPUTE and ROUNDEDCOMPUTE takes a whole expression at once; ROUNDED tidies the result.
- DIVIDE with REMAINDEROne DIVIDE fills the boxes and the basket: quotient and remainder in a single verb.
Conditions
- IF and END-IFA sailing call in a nested IF: no braces, just END-IF closing each block.
- EVALUATEEVALUATE is COBOL's switch: one subject, a WHEN per cargo code, OTHER for the rest.
- Level 88 conditionsLevel 88 gives a data value a name you can test and SET like a flag.
Loops
- PERFORM TIMESThe simplest loop: ring the ship's bell a counted number of times.
- PERFORM VARYINGThe counted loop: FROM, BY, and an UNTIL test driving a sled-dog workout.
- PERFORM paragraphsParagraphs are COBOL's subroutines: named blocks that PERFORM visits and returns from.
Tables & strings
- OCCURS tablesOCCURS turns one picture into a five-slot tide table, subscripts starting at 1.
- STRING ... DELIMITEDSTRING splices fields into one tag, trimming each by its delimiter.
- INSPECTINSPECT reads or rewrites characters in place: count the DOTs, then patch the tape.
Functions & calls
- Intrinsic functionsFUNCTION calls compute a value right where a field would sit.
- CURRENT-DATE and slicingOne function call returns the whole timestamp; reference modification slices it.
- CALL and LINKAGETwo programs in one file: CALL passes fields through the LINKAGE SECTION.
Encore
- word_freq.cobA word-frequency table built from UNSTRING, a linear search, and a hash-mark chart.
- grade_report.cobQuiz scores fold into averages and letter grades, then a formatted class report.
- temp_stats.cobA week of daily highs reduced to low, high and mean, with a scaled bar per day.