CUCO study materials
CUCO study resources

CUCO cheat sheet

CUCO · Keep the key ideas within reach.

Quick reference

Fundamentals of COBOL Programming

  • COBOL source is organized into four divisions in fixed order: IDENTIFICATION, ENVIRONMENT, DATA, PROCEDURE; only IDENTIFICATION is required by the standard, but most compilers require all four for a runnable program.

  • In fixed-format source, columns 1-6 are the sequence area, column 7 is the indicator area (* comment, / page eject, - continuation, D debug), columns 8-11 Area A (division, section, paragraph, 01/77 level), columns 12-72 Area B (statements, other levels).

  • Free-format source is requested with >>SOURCE FORMAT FREE or compiler option (e.g., -free / FREE); in free format there are no column rules and *> introduces a comment to end of line.

  • Program names are limited to 30 characters in COBOL 85 and 31 in COBOL 2002+; the PROGRAM-ID name should match the load module name to avoid dynamic CALL failures.

  • COBOL is not case-sensitive for reserved words and user-defined names; literals in quotes preserve case.

  • A COBOL word may contain letters, digits, and hyphens, must contain at least one letter, cannot begin or end with a hyphen, and cannot be a reserved word.

  • Numeric literals have no sign or decimal point except optionally a leading sign; nonnumeric literals are enclosed in quotes (" or ') and the chosen quote doubles to embed itself.

  • Figurative constants: ZERO/ZEROS/ZEROES, SPACE/SPACES, HIGH-VALUE/HIGH-VALUES, LOW-VALUE/LOW-VALUES, QUOTE/QUOTES, NULL/NULLS; ALL literal repeats the literal to the size of the receiving item.

  • The sentence ends with a period; a period terminates scope for IF/PERFORM/EVALUATE, so a misplaced period changes control flow - a common exam trap.

Quick reference

Data Division and Data Description

  • Section order in DATA DIVISION: FILE SECTION, WORKING-STORAGE SECTION, LOCAL-STORAGE SECTION, LINKAGE SECTION; LOCAL-STORAGE is allocated and initialized on every program invocation, WORKING-STORAGE only once.

  • PICTURE characters: 9 numeric, S sign (not counted in size), V implied decimal (not counted), P scaling (counted), A alphabetic, X alphanumeric, Z and * editing for zero suppression, comma, period, $, +, -, CR, DB, 0 (zero insertion), B blank insertion, / slash insertion.

  • USAGE: DISPLAY (default, zoned), COMP/COMP-4/BINARY (native binary, halfword/fullword/doubleword by digit count), COMP-1 (single float, no PICTURE), COMP-2 (double float, no PICTURE), COMP-3/PACKED-DECIMAL, COMP-5 (native binary, full range), INDEX, POINTER, NATIONAL/UTF-8.

  • COMP-3 size in bytes = INT((number of digits + 1) / 2) rounded up (the +1 is the sign nibble); a PIC S9(5) COMP-3 occupies 3 bytes.

  • A group item has no PICTURE and no USAGE; its USAGE is DISPLAY unless all subordinate items share a usage, and elementary moves into a group are treated as alphanumeric.

  • The 88 level is a condition-name attached to an elementary or group item; VALUES ARE ... THRU ... define ranges; SET condition-name TO TRUE moves the associated value.

  • The 66 level (RENAMES) re-groups previously defined elementary items in the same record, cannot overlap other 66 entries, and cannot rename an item containing an OCCURS.

  • REDEFINES must immediately follow the redefined item at the same level, have the same level number, and the redefining item cannot be shorter than the original for file records; REDEFINES does not initialize storage.

  • The JUSTIFIED RIGHT clause applies to alphanumeric items only; BLANK WHEN ZERO applies to numeric-edited items; SIGN IS LEADING/TRAILING SEPARATE CHARACTER affects DISPLAY sign placement and size.

Quick reference

Procedure Division and Control Structures

  • PERFORM ... UNTIL is test-before (may execute zero times); PERFORM ... WITH TEST AFTER executes at least once; PERFORM VARYING ... UNTIL combines initialization, increment, and test.

  • PERFORM ... TIMES with a count of zero or negative executes zero times; the count is evaluated once at the start.

  • Inline PERFORM ... END-PERFORM is preferred over out-of-line paragraphs because it avoids fall-through and simplifies scope terminators.

  • EVALUATE TRUE evaluates each WHEN as a condition; EVALUATE identifier WHEN value uses equality; EVALUATE ALSO supports multiple subjects with ANY as a wildcard.

  • GO TO ... DEPENDING ON branches by ordinal value of the identifier; values outside 1..n cause no branch and control falls to the next statement.

  • IF/ELSE nest with END-IF; the ELSE binds to the nearest unmatched IF unless scope terminators are used - always terminate to avoid ambiguity.

  • CONTINUE is a no-op statement; NEXT SENTENCE skips to the next period (deprecated), which differs from CONTINUE when inline scope terminators are used.

  • CALL 'literal' USING BY REFERENCE (default), BY CONTENT, BY VALUE; the subprogram must declare LINKAGE SECTION items matching the caller's BY REFERENCE items.

  • The INITIAL clause on a subprogram resets WORKING-STORAGE and internal state on each CALL; without it, WORKING-STORAGE retains values between calls.

Quick reference

File Handling and I/O Operations

  • File ORGANIZATION: SEQUENTIAL, LINE SEQUENTIAL, INDEXED, RELATIVE; ACCESS MODE: SEQUENTIAL, RANDOM, DYNAMIC (DYNAMIC requires a SELECT with an optional RECORD KEY).

  • INDEXED files require a RECORD KEY; ALTERNATE RECORD KEYs are optional and may have WITH DUPLICATES; RELATIVE files use RELATIVE KEY.

  • OPEN INPUT, OUTPUT, I-O, EXTEND; EXTEND is output-only and appends; I-O is required for READ ... INTO with REWRITE/DELETE.

  • READ ... AT END / NOT AT END; READ ... INVALID KEY for random reads; WRITE ... INVALID KEY for indexed/relative output; REWRITE and DELETE require the file opened I-O and a valid key.

  • START positions an indexed/relative file at a key; the next READ NEXT reads from that position.

  • FILE STATUS is a two-character item; '00' success, '10' end of file, '22' duplicate key, '23' record not found, '35' file not found on OPEN.

  • SELECT ... ASSIGN TO ... uses a name that the runtime maps via environment variables or JCL DD statements; the ASSIGN name is implementation-defined.

  • A file must be CLOSEd before the program ends; a CLOSE with LOCK prevents reopening in the same run unit.

  • Sequential files with variable-length records use RECORD IS VARYING IN SIZE with RECORD CONTAINS min TO max CHARACTERS and a RECORD DEPENDING ON item.

Quick reference

Tables, Arrays, and Subprograms

  • OCCURS n TIMES defines a table; the subscript is 1-relative, and INDEXED BY creates an index whose values are implementation-defined and only usable with SET, SEARCH, and relative subscripting.

  • SEARCH is for serial tables; SEARCH ALL requires the table to be sorted ascending or descending on the key and the key to be the first or only data item - it performs a binary search.

  • SET index-name TO 1, SET index-name UP BY 1, SET index-name DOWN BY 1 manipulate indices; PERFORM VARYING index-name FROM 1 BY 1 UNTIL ... is the classic table loop.

  • A subscript may be a numeric literal, data name, or arithmetic expression (COBOL 2002+); an index may be used only in subscripting, SET, SEARCH, and relative subscripting.

  • OCCURS DEPENDING ON (ODO) makes the table variable length; the ODO object must be an integer item defined before the table, and the table must be the last item in the record for file I/O.

  • Nested OCCURS requires a subscript for each dimension, listed outermost first; a two-dimensional table T(I,J) is defined by OCCURS at level 05 then OCCURS at level 10.

  • CALL ... USING passes parameters; the LINKAGE SECTION defines them; PROCEDURE DIVISION USING must list them in the same order and with compatible PICTUREs.

  • BY REFERENCE passes a pointer to the caller's item (default); BY CONTENT passes a copy that the subprogram cannot change in the caller; BY VALUE passes the value for non-COBOL interoperability.

  • A subprogram can be made recursive with the RECURSIVE clause; LOCAL-STORAGE is then allocated per invocation, and the program must be compiled as RECURSIVE or INITIAL as appropriate.

Quick reference

Debugging, Testing, and Maintenance

  • WITH DEBUGGING MODE and column 7 'D' lines compile only when debugging mode is active; the DEBUG-LINE and DEBUG-ITEM special registers expose the last debug line.

  • DISPLAY of a group item shows the raw storage, which is the fastest way to inspect COMP-3, COMP, and REDEFINES overlays.

  • Common abend codes: S0C7 data exception (nonnumeric data in a numeric field), S0C4 protection exception (bad address, often a bad CALL USING or subscript out of range), S0CB divide by zero.

  • File status '10' is normal end of file, not an error; '22' is a duplicate key on a WRITE or REWRITE with an alternate key; '23' is record not found on a random READ.

  • A subscript out of range in a table is undefined behavior in standard COBOL; runtime checks (e.g., SSRANGE) catch it, and production code should test the subscript before use.

  • Test data should include boundary values for numeric fields (PIC 9(3) max 999), empty files, duplicate keys, and truncated records.

  • A COPY statement pulls in copybook source at compile time; changing a copybook requires recompiling every program that copies it - a common maintenance defect.

  • The EVALUATE TRUE / WHEN OTHER pair is the standard way to implement a default branch; missing WHEN OTHER silently does nothing.

  • Paragraph and SECTION names in PERFORM must exist; a PERFORM of a paragraph that falls through into the next paragraph executes unintended code unless the paragraph ends with EXIT or a scope terminator.

Quick reference

Modern COBOL and Integration

  • COBOL 2002 added free format, user-defined functions, object-oriented COBOL (CLASS-ID, METHOD-ID), and the EVALUATE ALSO/ANY extensions.

  • COBOL 2014 added dynamic capacity tables, the VALIDATE facility, and UTF-8 support; COBOL 2023 added asynchronous messaging and JSON support.

  • GnuCOBOL (formerly OpenCOBOL) is the common open-source compiler; it supports most COBOL 85 and many 2002+ features and compiles to C.

  • Micro Focus (now OpenText) Enterprise Developer and IBM Enterprise COBOL are the mainframe/enterprise compilers; IBM Enterprise COBOL for z/OS supports COBOL 2002 and 2014 features.

  • CALL ... BY VALUE and the USAGE NATIONAL / UTF-8 items are used for interoperation with C, Java (via JNI or JVM COBOL), and .NET (Micro Focus).

  • JSON GENERATE and JSON PARSE (COBOL 2014+) convert between COBOL data structures and JSON text; XML GENERATE and XML PARSE provide the XML equivalent.

  • The CALL ... RETURNING clause and the EXTERNAL clause allow subprograms to return values and share data across programs in a run unit.

  • CICS and IMS are the mainframe transaction environments where COBOL programs run; EXEC CICS ... END-EXEC embeds transaction commands in the PROCEDURE DIVISION.

  • Containerization: COBOL programs compiled with GnuCOBOL run in Linux containers, and Micro Focus provides a native COBOL runtime for Docker/Kubernetes deployments.