COBOL Textbook

COBOL, one tutorial at a time.

Every lesson here is a complete program written for GnuCOBOL, desk-checked against its guide and, for 14 of the 23 so far, compiled and run with GnuCOBOL 3.2, explained line by line, with the standard it follows named at the top. The language is sixty-plus years old and still runs the payroll, the ledger, and the claims system; this site teaches it the way those systems use it.

Lessons
23, in five parts
Listings written for
GnuCOBOL 3.x
Run status
Compiled and run with GnuCOBOL 3.2: 14 of 23 lessons; the other 9 desk-checked
Contents current to

Six lessons that go furthest past restating the manual: findings from the GnuCOBOL 3.2 source and dialect files, comparisons with IBM’s dialect, and our own companion scripts. The full contents follow below.

  1. 4.4

    COBOL JSON GENERATE and JSON PARSE: what GnuCOBOL 3.2 can do

    A GnuCOBOL program that turns fixed-width records into JSON Lines with JSON GENERATE, the exact output it should write, and why JSON PARSE does nothing in 3.2.

    15 min

  2. 4.5

    GnuCOBOL -std=ibm and other dialects: what each one changes

    What cobc -std=ibm actually switches in GnuCOBOL 3.2, read from its dialect files, and one program whose output changes when the dialect does.

    11 min

  3. 5.3

    COBOL input validation: class tests, INSPECT and TEST-NUMVAL

    A GnuCOBOL edit program that checks every field of a fixed-width feed with CLASS, INSPECT, TEST-NUMVAL and TEST-DATE-YYYYMMDD, and logs every error with a code.

    17 min

  4. 2.5

    COBOL INSPECT REPLACING and CONVERTING, BEFORE and AFTER

    A GnuCOBOL program that cleans an order export in place with INSPECT REPLACING, CONVERTING and BEFORE/AFTER, and the size and order rules behind them.

    14 min

  5. 4.2

    Free-format COBOL in GnuCOBOL: what changed from columns 8 and 12

    The same COBOL program written twice, in fixed format and in free format, with the column rules that shaped it and where GnuCOBOL and IBM disagree.

    12 min

  6. 3.4

    COBOL copybooks: COPY, REPLACING, and one layout in three programs

    One 39-byte copybook in three GnuCOBOL programs: plain COPY, REPLACING LEADING, and REPLACE, with where GnuCOBOL and IBM differ on search paths and nesting.

    13 min

Contents

Lessons are numbered by part. Times are reading times.

About this textbook

Each lesson is one complete program. Not a fragment, not pseudocode: a listing with all four divisions, written for GnuCOBOL, the free compiler that implements the ISO standard plus most of the IBM and Micro Focus extensions people meet at work. The listing is explained line by line, the dialect and format (free or fixed) are stated at the top, and anything that is IBM-only or GnuCOBOL-only is called out where it appears rather than smoothed over.

Where a program reads or writes a file, the sample file and the copybook ship with the lesson, so nothing the program needs is missing. Where a lesson touches the modern world, Python does the other half: generating fixed-width test data, parsing a copybook, checking a report, calling a COBOL module from something newer.

Note: Lessons are published under the owner’s direction and desk-checked against the GnuCOBOL Programmer’s Guide; each one says what was run and what was not. How this site is made.

All 23 articles