COBOL Tutorial
Learn COBOL step by step: 38 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Tables and Arrays
- Tables with OCCURS Learn how COBOL builds arrays with the OCCURS clause - table layout in memory, subscripts, loading and reading tables, PERFORM VARYING, REDEFINES tricks and out-of-range bugs.
- Indexes and SEARCH Learn COBOL table lookups with INDEXED BY, SET, SEARCH and SEARCH ALL - linear versus binary search, key ordering rules, AT END handling and the difference between an index and a subscript.
- Multi-Dimensional and Variable-Length Tables Build two- and three-level COBOL tables with nested OCCURS, address them with several subscripts, and use OCCURS DEPENDING ON for variable-length tables and records.
File Handling
- Sequential Files Learn COBOL sequential file processing - SELECT and ASSIGN, FD record layouts, OPEN, READ, WRITE, CLOSE, the read-ahead loop, fixed and variable records, and the classic copy and merge patterns.
- File Status and Error Handling Learn COBOL FILE STATUS codes, USE declaratives, AT END, INVALID KEY, ON SIZE ERROR and defensive patterns so batch programs fail loudly instead of corrupting data.
- Indexed and Relative Files Learn COBOL indexed and relative file organizations - RECORD KEY, ALTERNATE KEY, access modes, READ by key, START, REWRITE, DELETE, and how VSAM KSDS maps to these statements.
- Sorting and Merging Files Learn the COBOL SORT and MERGE statements - SD files, keys, USING and GIVING, INPUT and OUTPUT PROCEDURE with RELEASE and RETURN, duplicates and control-break reports on sorted data.
Subprograms
- CALL and the Linkage Section Learn how COBOL programs call subprograms - CALL, USING BY REFERENCE, BY CONTENT and BY VALUE, the LINKAGE SECTION, GOBACK versus STOP RUN, static and dynamic calls, return codes and CANCEL.
- Copybooks and Nested Programs Learn how COBOL shares code with COPY and copybooks, customizes them with REPLACING, and structures a run unit with nested programs, GLOBAL and COMMON, EXTERNAL data and CALL conventions.
- User-Defined Functions and Recursion Learn COBOL user-defined functions with FUNCTION-ID and REPOSITORY, recursive programs with LOCAL-STORAGE, intrinsic function calls, and how to write a factorial and tree walk safely.
Modern COBOL and Mainframes
- The Mainframe Environment Understand where most COBOL runs - IBM z/OS, TSO and ISPF, datasets and record formats, EBCDIC, packed decimal COMP-3 storage, batch versus online work, and how a COBOL program becomes a job.
- JCL for COBOL Jobs Learn the Job Control Language needed to run COBOL on z/OS - JOB, EXEC and DD statements, DISP, SPACE and DCB, compile-link-go procedures, SYSIN and SYSOUT, return codes with IF/THEN, and sort steps.
- Embedded SQL and DB2 Learn how COBOL programs talk to relational databases such as DB2 - EXEC SQL blocks, host variables, SQLCA and SQLCODE, singleton SELECT, cursors with FETCH, NULL indicators, updates and commit.
- CICS and Online Transactions A COBOL programmer's introduction to CICS - transactions and tasks, EXEC CICS commands, BMS maps, SEND and RECEIVE MAP, pseudo-conversational design with COMMAREA, file access, RESP codes and LINK or XCTL.
- JSON, XML and Object-Oriented COBOL Learn modern COBOL features that connect old systems to new ones - JSON GENERATE and JSON PARSE, XML GENERATE and XML PARSE, calling web services and the object-oriented extensions CLASS-ID, METHOD-ID and INVOKE.
- GnuCOBOL and Modernizing COBOL Set up GnuCOBOL on your own machine, compile with cobc, understand fixed and free source format, debug and test COBOL, and learn modernization strategies - APIs, refactoring, version control and migration.
Projects and Practice
- Project: A Payroll Report Build a complete COBOL batch program step by step - read a sorted employee file, compute overtime and tax with a SEARCH table, print a formatted report with department subtotals, grand totals and error handling.
- Project: Updating an Account Master Build the classic COBOL master and transaction update - sequential balance-line matching with HIGH-VALUES, add, rename, deposit, withdraw and close, an error report, and the indexed-file alternative.
- Practice Problems and Interview Questions Test your COBOL skills with graded practice exercises on tables, files, subprograms and reports, a debugging checklist, and the interview questions about PICTURE, COMP-3, SEARCH, file status, JCL and abends.
Getting Started
- What Is COBOL and Why Does It Still Matter? Learn what COBOL is, where it came from, why banks, insurers and governments still run on it, and what a modern COBOL developer actually does.
- Hello, World with GnuCOBOL Install GnuCOBOL, write your first COBOL program, compile it with cobc, run it, and read the most common compiler messages. Includes a mini DISPLAY simulator.
- Source Format and Coding Rules Learn COBOL fixed and free source format: columns 1-72, area A and B, comments, continuation lines, names, literals, figurative constants and reserved words.
- Program Structure: Divisions, Sections and Paragraphs See how a COBOL program is organised: four divisions, sections, paragraphs, sentences and statements, scope terminators, and a complete annotated example.
Divisions and Data Description
- Identification and Environment Divisions Learn PROGRAM-ID, optional identification paragraphs, the CONFIGURATION SECTION, SPECIAL-NAMES (DECIMAL-POINT IS COMMA, CLASS) and FILE-CONTROL basics.
- Data Division, Sections and Level Numbers Learn the COBOL data division: file, working-storage, local-storage and linkage sections, level numbers 01-49, 66, 77 and 88, group and elementary items, and FILLER.
- PICTURE Clauses: 9, X, A, V, S and P Master the COBOL PIC clause: numeric 9, alphanumeric X, alphabetic A, implied decimal V, sign S, scaling P, repeat counts, sizes and what MOVE does to over-long values.
- USAGE and VALUE: DISPLAY, COMP, COMP-3 and Initial Values Understand COBOL storage formats: USAGE DISPLAY, BINARY/COMP, packed decimal COMP-3, COMP-1/COMP-2, sign handling, VALUE clauses and how many bytes each format needs.
- REDEFINES, RENAMES and Level 88 Condition Names Learn how REDEFINES gives one memory area several layouts, how RENAMES (level 66) regroups fields, and how level-88 condition names make flags and code checks readable.
- COPY, REPLACING and Copybooks Share record layouts across programs with COBOL copybooks: the COPY statement, COPY REPLACING pseudo-text, the REPLACE statement, search paths and good copybook practice.
Procedures and Control Flow
- ACCEPT and DISPLAY: Input and Output Learn COBOL console I/O: DISPLAY with several operands, NO ADVANCING, UPON, ACCEPT from the keyboard, and ACCEPT FROM DATE, TIME and DAY-OF-WEEK.
- IF, ELSE and Conditions in COBOL Master COBOL decisions: IF/ELSE/END-IF, relational, class, sign and condition-name tests, AND/OR/NOT, abbreviated conditions, nested IFs, CONTINUE and the period trap.
- EVALUATE: Multi-Way Decisions in COBOL Use COBOL's EVALUATE like switch/case: WHEN values and ranges, WHEN OTHER, EVALUATE TRUE for conditions, ALSO for decision tables, with a safe no-fall-through behaviour.
- PERFORM, Paragraphs, Sections and GO TO Learn how COBOL organises logic: paragraphs and sections, PERFORM and PERFORM THRU, fall-through, EXIT, GO TO, STOP RUN versus GOBACK, and structured top-down design.
- PERFORM Loops: TIMES, UNTIL and VARYING Write loops in COBOL: PERFORM n TIMES, PERFORM UNTIL, TEST BEFORE and AFTER, PERFORM VARYING with nested counters, inline PERFORM, EXIT PERFORM and the read-until-EOF pattern.
Data Manipulation
- MOVE, CORRESPONDING and Edited Pictures Learn COBOL's MOVE rules, group moves, MOVE CORRESPONDING, INITIALIZE and numeric edited pictures with Z, comma, period, $, asterisk, + - CR DB and B for print-ready output.
- Arithmetic in COBOL: ADD, SUBTRACT, MULTIPLY, DIVIDE, COMPUTE Do exact decimal maths in COBOL: ADD, SUBTRACT, MULTIPLY, DIVIDE with GIVING and REMAINDER, COMPUTE expressions, ROUNDED, truncation, ON SIZE ERROR and intermediate precision.
- String Handling: STRING, UNSTRING and INSPECT Handle text in COBOL: STRING to join with POINTER and ON OVERFLOW, UNSTRING to split on delimiters with COUNT and TALLYING, and INSPECT to count, replace and convert characters.
- Reference Modification and Intrinsic Functions Slice fields with COBOL reference modification (start:length) and use intrinsic functions: LENGTH, TRIM, UPPER-CASE, REVERSE, NUMVAL, CURRENT-DATE, INTEGER-OF-DATE, MOD, MAX and more.