COBOL Textbook

All articles

23 articles, newest first. Browse by topic or subscribe to the RSS feed.

October 2026

  1. 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

  2. 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

  3. 5.4

    COBOL STRING and UNSTRING: splitting a CSV line into fields

    A GnuCOBOL program that splits a comma-separated export with UNSTRING, checks each field with COUNT IN and TALLYING IN, and builds a label with STRING.

    10 min

  4. 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

  5. 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

September 2026

  1. 5.2

    Reconciling two files in COBOL: matched, left-only, right-only

    A complete GnuCOBOL match of two sorted files that reports every reference as matched, amount differs, bank only or book only, with control totals that must balance.

    6 min

  2. 4.3

    Calling a C function from COBOL, and being called back

    CALL BY VALUE, BY REFERENCE and RETURNING across the C ABI, then the other direction with cob_init and cob_resolve, with both listings and the build lines.

    7 min

  3. 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

  4. 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

  5. 3.3

    COBOL indexed files: ORGANIZATION INDEXED, START, READ KEY, REWRITE

    A GnuCOBOL program loads a parts master into an indexed file, reads by key, rewrites a record, browses a key range with START and READ NEXT, and deletes; data ships.

    14 min

  6. 3.2

    COBOL WRITE a report file: headers, detail lines, page breaks

    A GnuCOBOL program writes a paginated report: page header with the run date, column headings, edited detail lines, a page total, and a break every 23 lines.

    10 min

  7. 4.1

    Generating fixed-width test data with Python and reading it in COBOL

    A Python script writes a 64-byte fixed-width transaction file, a copybook pins the layout, and a GnuCOBOL program reads it back and prints control totals.

    7 min

  8. 2.4

    COBOL REDEFINES example: one memory area, two views of a date

    REDEFINES overlays a second description on the same bytes: a date as text and as three numbers, record variants switched by type code, and a NUMERIC test first.

    5 min

  9. 3.1

    COBOL sequential files: read a fixed-width file to end of file

    SELECT, FD, OPEN, the priming READ and AT END: a complete program reads a 60-byte customer file to end of file and prints control totals; data and copybook ship.

    6 min

  10. 1.2

    COBOL PICTURE clause: 9, X, A, V, S and how a number is stored

    What each PICTURE symbol means, how PIC 9(3)V99 occupies five bytes with no decimal point, and what S and P really do, shown by one GnuCOBOL program.

    6 min

  11. 1.5

    PERFORM VARYING, PERFORM UNTIL, and inline PERFORM in COBOL

    Every common COBOL loop in one GnuCOBOL program: PERFORM TIMES, UNTIL with TEST BEFORE and TEST AFTER, inline VARYING over a table, nested AFTER, and EXIT PERFORM.

    6 min

  12. 2.3

    COBOL OCCURS and subscripts: a table of monthly totals

    OCCURS builds a table; subscripts index it from 1. A worked program sums twelve monthly totals, finds the best month, fills a 3-by-4 grid and uses DEPENDING ON.

    5 min

  13. 1.3

    COBOL MOVE statement and the truncation rules that surprise everyone

    Seven MOVEs in one GnuCOBOL program show where COBOL truncates on the right, on the left, drops a sign, or copies bytes blindly in a group move, with a rules table.

    11 min

  14. 1.1

    Your first COBOL program: all four divisions, DISPLAY, STOP RUN

    A complete first COBOL program for GnuCOBOL, explained division by division, with DISPLAY, WITH NO ADVANCING, signed and unsigned numbers, and STOP RUN.

    7 min

  15. 2.1

    COBOL group items and elementary items: the record layout as a struct

    How level numbers 01 to 49, 77 and 88 build a record; what a group move does to the bytes; a worked 80-byte customer record with its byte offsets.

    7 min

  16. 2.2

    COBOL edited pictures: money with Z, comma, period, CR and minus

    Numeric-edited PICTURE strings format amounts for people. Eight edited items receive the same five values; a table shows every result and the rules that produce it.

    6 min

  17. 1.4

    COMPUTE, ROUNDED, ON SIZE ERROR: COBOL arithmetic without overflow

    One GnuCOBOL program: COMPUTE with and without ROUNDED, ROUNDED MODE IS NEAREST-EVEN on a tie, an overflow caught by ON SIZE ERROR, and a trapped divide by zero.

    9 min

  18. 5.1

    A COBOL bank-statement batch job: read, validate, total, report

    A complete GnuCOBOL batch program that reads sorted transactions, rejects bad records to a file, breaks on account change, and writes a statement with totals.

    6 min