Appendix A: COBOL Language Reference Card

This appendix provides a compact, quick-lookup reference for the COBOL language elements covered throughout this textbook. It is not a replacement for your compiler's language reference manual — it is a working programmer's cheat sheet, organized by division and verb, with syntax diagrams rendered in text format and short examples you can adapt immediately.

Throughout this reference, optional elements appear in square brackets [ ], alternatives are separated by vertical bars |, and repeating elements are indicated with ellipsis .... Uppercase words are COBOL reserved words; lowercase italicized descriptions represent programmer-supplied names or values.


A.1 IDENTIFICATION DIVISION

The IDENTIFICATION DIVISION is the simplest division, but precision here prevents downstream confusion in program libraries and documentation systems.

IDENTIFICATION DIVISION.
PROGRAM-ID. program-name [IS INITIAL | IS RECURSIVE | IS COMMON].
[AUTHOR. author-name.]
[INSTALLATION. installation-name.]
[DATE-WRITTEN. date.]
[DATE-COMPILED. date.]
[SECURITY. security-note.]

Key points:

  • PROGRAM-ID is the only required paragraph. The name must follow your compiler's rules (typically 1–30 characters, alphanumeric plus hyphen, no leading digit).
  • IS INITIAL causes the program's working storage to be reinitialized each time it is called, which is important for reentrant subprogram design (see Chapter 12).
  • IS RECURSIVE permits recursive CALL to the same program — required when implementing recursive algorithms in COBOL 2002 and later.
  • IS COMMON makes a nested program visible to all programs in the same nesting structure.
  • AUTHOR, INSTALLATION, DATE-WRITTEN, DATE-COMPILED, and SECURITY are obsolete in COBOL 2002 and later but still accepted by most compilers. Many shops retain them as comment-like documentation.

A.2 ENVIRONMENT DIVISION

A.2.1 CONFIGURATION SECTION

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. computer-name [WITH DEBUGGING MODE].
OBJECT-COMPUTER. computer-name
    [PROGRAM COLLATING SEQUENCE IS alphabet-name].
[SPECIAL-NAMES.
    special-name IS mnemonic-name
    [CURRENCY SIGN IS literal]
    [DECIMAL-POINT IS COMMA]
    [CLASS class-name IS {literal-1 THRU literal-2} ...]
    .]
[REPOSITORY.
    CLASS class-name IS class-external-name ...]
  • WITH DEBUGGING MODE activates lines marked with D in column 7 — an underused feature for toggling diagnostic DISPLAY statements without removing them.
  • DECIMAL-POINT IS COMMA swaps the roles of period and comma in numeric editing, essential for European locale programs.
  • REPOSITORY paragraph is used in object-oriented COBOL (COBOL 2002+) for CLASS and INTERFACE declarations.

A.2.2 INPUT-OUTPUT SECTION

INPUT-OUTPUT SECTION.
FILE-CONTROL.
    SELECT [OPTIONAL] file-name
        ASSIGN TO assignment-name
        [ORGANIZATION IS {SEQUENTIAL | INDEXED | RELATIVE | LINE SEQUENTIAL}]
        [ACCESS MODE IS {SEQUENTIAL | RANDOM | DYNAMIC}]
        [RECORD KEY IS data-name]
        [ALTERNATE RECORD KEY IS data-name [WITH DUPLICATES]] ...
        [RELATIVE KEY IS data-name]
        [FILE STATUS IS data-name]
        [PASSWORD IS data-name].

Organization and Access Mode combinations:

Organization Sequential Access Random Access Dynamic Access
SEQUENTIAL Yes (default) No No
INDEXED Yes Yes Yes
RELATIVE Yes Yes Yes
LINE SEQUENTIAL Yes No No
  • Always code FILE STATUS IS — silent file failures are among the most common production bugs in COBOL applications.
  • OPTIONAL allows OPEN INPUT on a file that may not exist (file status 05).

A.3 DATA DIVISION

A.3.1 File Section

DATA DIVISION.
FILE SECTION.
FD file-name
    [BLOCK CONTAINS integer-1 [TO integer-2] {RECORDS | CHARACTERS}]
    [RECORD {CONTAINS integer CHARACTERS |
             IS VARYING IN SIZE FROM integer-1 TO integer-2 CHARACTERS
               DEPENDING ON data-name |
             CONTAINS integer-1 TO integer-2 CHARACTERS}]
    [LABEL {RECORDS ARE | RECORD IS} {STANDARD | OMITTED}]
    [DATA {RECORDS ARE | RECORD IS} data-name ...].
01 record-name.
    ...

A.3.2 Data Item Definitions

level-number data-name | FILLER
    [REDEFINES other-data-name]
    [PIC | PICTURE IS picture-string]
    [USAGE IS {DISPLAY | COMP | COMP-1 | COMP-2 | COMP-3 | COMP-4 | COMP-5
              | BINARY | PACKED-DECIMAL | INDEX | POINTER | NATIONAL}]
    [VALUE IS literal]
    [OCCURS integer TIMES
        [ASCENDING | DESCENDING KEY IS data-name ...]
        [INDEXED BY index-name ...]]
    [OCCURS integer-1 TO integer-2 TIMES
        DEPENDING ON data-name
        [ASCENDING | DESCENDING KEY IS data-name ...]
        [INDEXED BY index-name ...]]
    [SIGN IS {LEADING | TRAILING} [SEPARATE CHARACTER]]
    [JUSTIFIED | JUST RIGHT]
    [BLANK WHEN ZERO]
    [SYNCHRONIZED | SYNC [LEFT | RIGHT]]
    [88-level condition values].

Common PICTURE Strings:

Pattern Meaning Example Value Edited Result
9(5) 5-digit numeric 123 00123
X(10) 10-char alphanumeric HELLO HELLO
S9(7)V99 Signed, 7.2 decimal -1234.56 (internal)
Z(4)9.99 Suppressed leading zeros 42.50 42.50
$$$,$$9.99 Floating dollar 1234.56 $1,234.56
-(5)9.99 Floating minus -42.50 -42.50
9(5).9(2)+ Trailing sign 123.45 00123.45+

Level Numbers:

Level Purpose
01 Record or independent item
02–49 Group or elementary subordinate items
66 RENAMES clause
77 Independent elementary item (WORKING-STORAGE only)
88 Condition name (value-based boolean)

A.3.3 USAGE Clause Summary

USAGE Storage Precision Typical Use
DISPLAY 1 byte/digit, EBCDIC/ASCII Exact Human-readable output, flat files
COMP (BINARY) 2, 4, or 8 bytes Exact to 18 digits Subscripts, counters, binary interfaces
COMP-1 4 bytes (IEEE single) ~7 digits Scientific computation
COMP-2 8 bytes (IEEE double) ~15 digits Scientific computation
COMP-3 (PACKED-DECIMAL) ⌈(n+1)/2⌉ bytes Exact to 18 digits Financial calculations
COMP-5 Native binary, 2/4/8 bytes Full binary range API/system interfaces
NATIONAL 2 bytes/character (UTF-16) N/A Unicode text
INDEX System-dependent N/A Table index values
POINTER System-dependent (4/8 bytes) N/A Address manipulation

A.3.4 Condition Names (Level 88)

88 condition-name VALUE IS literal-1 [THRU literal-2]
                  [literal-3 [THRU literal-4]] ...
                  [WHEN SET TO FALSE IS literal].

Example:

05 WS-STATUS        PIC X(02).
   88 STATUS-ACTIVE  VALUE 'AC'.
   88 STATUS-CLOSED  VALUE 'CL' 'CA' 'CX'.
   88 STATUS-VALID   VALUE 'AC' 'CL' 'CA' 'CX' 'SU'.

Use SET condition-name TO TRUE to assign the first VALUE to the parent data item.

A.3.5 COPY and REPLACE

COPY copybook-name [OF | IN library-name]
    [REPLACING {==pseudo-text-1== BY ==pseudo-text-2==} ...
              | {identifier-1 BY identifier-2} ...].
REPLACE {==pseudo-text-1== BY ==pseudo-text-2==} ... .
REPLACE OFF.
  • COPY brings in external definitions at compile time — the cornerstone of COBOL modularity.
  • REPLACE applies text substitution across subsequent source lines until REPLACE OFF or end of compilation unit.
  • Pseudo-text delimiters == are required for multi-word or partial-word replacements.

A.4 PROCEDURE DIVISION — Arithmetic Verbs

A.4.1 COMPUTE

COMPUTE identifier-1 [ROUNDED [MODE IS {AWAY-FROM-ZERO | NEAREST-AWAY-FROM-ZERO
    | NEAREST-EVEN | NEAREST-TOWARD-ZERO | TOWARD-GREATER | TOWARD-LESSER
    | TRUNCATION}]]
    = arithmetic-expression
    [ON SIZE ERROR imperative-statement-1]
    [NOT ON SIZE ERROR imperative-statement-2]
[END-COMPUTE]

Example:

COMPUTE WS-MONTHLY-PAYMENT ROUNDED MODE IS NEAREST-EVEN
    = (WS-PRINCIPAL * WS-MONTHLY-RATE)
    / (1 - (1 + WS-MONTHLY-RATE) ** (0 - WS-NUM-PAYMENTS))
    ON SIZE ERROR
        DISPLAY 'Payment calculation overflow'
        SET WS-CALC-ERROR TO TRUE
END-COMPUTE

Operator precedence (highest to lowest):

  1. ** (exponentiation)
  2. Unary +, -
  3. *, / (multiplication, division)
  4. +, - (addition, subtraction)

Parentheses override precedence. Always use parentheses in complex expressions for clarity — COBOL programmers maintain code for decades.

A.4.2 ADD, SUBTRACT, MULTIPLY, DIVIDE

ADD {identifier | literal} ... TO identifier-1 [ROUNDED] ...
    [ON SIZE ERROR imperative-statement]
    [NOT ON SIZE ERROR imperative-statement]
[END-ADD]

ADD {identifier | literal} ... TO {identifier | literal}
    GIVING identifier-1 [ROUNDED] ...

ADD CORRESPONDING group-1 TO group-2 [ROUNDED]
SUBTRACT {identifier | literal} ... FROM identifier-1 [ROUNDED] ...
    [ON SIZE ERROR imperative-statement]
    [NOT ON SIZE ERROR imperative-statement]
[END-SUBTRACT]

SUBTRACT {identifier | literal} ... FROM {identifier | literal}
    GIVING identifier-1 [ROUNDED] ...

SUBTRACT CORRESPONDING group-1 FROM group-2 [ROUNDED]
MULTIPLY {identifier | literal} BY identifier-1 [ROUNDED] ...
MULTIPLY {identifier | literal} BY {identifier | literal}
    GIVING identifier-1 [ROUNDED] ...
DIVIDE {identifier | literal} INTO identifier-1 [ROUNDED] ...
DIVIDE {identifier | literal} INTO {identifier | literal}
    GIVING identifier-1 [ROUNDED]
    [REMAINDER identifier-2]
DIVIDE {identifier | literal} BY {identifier | literal}
    GIVING identifier-1 [ROUNDED]
    [REMAINDER identifier-2]

A.5 PROCEDURE DIVISION — Control Flow

A.5.1 PERFORM

PERFORM procedure-name-1 [THRU procedure-name-2]
    [{identifier | integer} TIMES]

PERFORM procedure-name-1 [THRU procedure-name-2]
    [WITH TEST {BEFORE | AFTER}]
    UNTIL condition

PERFORM procedure-name-1 [THRU procedure-name-2]
    [WITH TEST {BEFORE | AFTER}]
    VARYING identifier-1 FROM {identifier | literal}
        BY {identifier | literal}
        UNTIL condition
    [AFTER identifier-2 FROM {identifier | literal}
        BY {identifier | literal}
        UNTIL condition] ...

Inline PERFORM:

PERFORM [WITH TEST {BEFORE | AFTER}]
    VARYING identifier FROM start BY increment UNTIL condition
    imperative-statements
END-PERFORM

A.5.2 EVALUATE

EVALUATE {identifier | expression | TRUE | FALSE}
    [ALSO {identifier | expression | TRUE | FALSE}] ...
    {WHEN {literal | identifier | condition | ANY
           | {literal-1 | identifier-1} THRU {literal-2 | identifier-2}
           | NOT {literal | identifier | condition}}
        [ALSO {same alternatives}] ...
        imperative-statement} ...
    [WHEN OTHER imperative-statement]
[END-EVALUATE]

Example — multi-subject EVALUATE:

EVALUATE TRUE ALSO WS-REGION-CODE
    WHEN WS-BALANCE > 10000    ALSO 'NE'
        PERFORM 2100-HIGH-VALUE-NORTHEAST
    WHEN WS-BALANCE > 10000    ALSO 'SE'
        PERFORM 2200-HIGH-VALUE-SOUTHEAST
    WHEN WS-BALANCE > 10000    ALSO ANY
        PERFORM 2300-HIGH-VALUE-OTHER
    WHEN WS-BALANCE > 0        ALSO ANY
        PERFORM 2400-STANDARD-PROCESS
    WHEN OTHER
        PERFORM 2500-ZERO-BALANCE
END-EVALUATE

A.5.3 IF / ELSE

IF condition
    imperative-statement-1
[ELSE
    imperative-statement-2]
[END-IF]

Condition types:

  • Relation: identifier {= | > | < | >= | <= | NOT =} {identifier | literal}
  • Class: identifier IS [NOT] {NUMERIC | ALPHABETIC | ALPHABETIC-LOWER | ALPHABETIC-UPPER | class-name}
  • Condition-name: condition-name (level 88)
  • Sign: identifier IS [NOT] {POSITIVE | NEGATIVE | ZERO}
  • Combined: conditions joined with AND, OR, NOT
  • Abbreviated combined: IF A > B AND C AND D means IF A > B AND A > C AND A > D

A.5.4 GO TO

GO TO procedure-name

GO TO procedure-name-1 procedure-name-2 ...
    DEPENDING ON identifier

Use sparingly — GO TO is acceptable for paragraph exit patterns (GO TO paragraph-EXIT) but should not be the primary control flow mechanism in modern COBOL.


A.6 PROCEDURE DIVISION — String Handling

A.6.1 STRING

STRING {identifier-1 | literal-1}
       [DELIMITED BY {identifier-2 | literal-2 | SIZE}] ...
    INTO identifier-3
    [WITH POINTER identifier-4]
    [ON OVERFLOW imperative-statement-1]
    [NOT ON OVERFLOW imperative-statement-2]
[END-STRING]

Example:

STRING WS-LAST-NAME   DELIMITED BY SPACES
       ', '           DELIMITED BY SIZE
       WS-FIRST-NAME  DELIMITED BY SPACES
    INTO WS-FULL-NAME
    WITH POINTER WS-PTR
    ON OVERFLOW
        DISPLAY 'Name truncated'
END-STRING

A.6.2 UNSTRING

UNSTRING identifier-1
    DELIMITED BY [ALL] {identifier-2 | literal-1}
        [OR [ALL] {identifier-3 | literal-2}] ...
    INTO identifier-4 [DELIMITER IN identifier-5] [COUNT IN identifier-6]
         [identifier-7 [DELIMITER IN identifier-8] [COUNT IN identifier-9]] ...
    [WITH POINTER identifier-10]
    [TALLYING IN identifier-11]
    [ON OVERFLOW imperative-statement-1]
    [NOT ON OVERFLOW imperative-statement-2]
[END-UNSTRING]

Example — parsing a CSV line:

UNSTRING WS-CSV-LINE
    DELIMITED BY ',' OR X'0D' OR X'0A'
    INTO WS-FIELD-1   COUNT IN WS-CNT-1
         WS-FIELD-2   COUNT IN WS-CNT-2
         WS-FIELD-3   COUNT IN WS-CNT-3
    TALLYING IN WS-FIELD-COUNT
    ON OVERFLOW
        DISPLAY 'More fields than expected'
END-UNSTRING

A.6.3 INSPECT

INSPECT identifier-1
    TALLYING {identifier-2 FOR
        {CHARACTERS | {ALL | LEADING} {identifier-3 | literal-1}}
        [{BEFORE | AFTER} INITIAL {identifier-4 | literal-2}]} ...

INSPECT identifier-1
    REPLACING {CHARACTERS BY {identifier-3 | literal-1}
              | {ALL | LEADING | FIRST} {identifier-4 | literal-2}
                BY {identifier-5 | literal-3}}
        [{BEFORE | AFTER} INITIAL {identifier-6 | literal-4}] ...

INSPECT identifier-1
    CONVERTING {identifier-2 | literal-1}
    TO {identifier-3 | literal-2}
    [{BEFORE | AFTER} INITIAL {identifier-4 | literal-3}]

Example — count and replace:

INSPECT WS-INPUT-STRING
    TALLYING WS-SPACE-COUNT FOR ALL SPACES
    REPLACING ALL LOW-VALUES BY SPACES

Example — uppercase conversion:

INSPECT WS-TEXT
    CONVERTING 'abcdefghijklmnopqrstuvwxyz'
    TO         'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

A.7 PROCEDURE DIVISION — Table Handling

A.7.1 SEARCH (Linear)

SEARCH identifier-1
    [VARYING {identifier-2 | index-name}]
    [AT END imperative-statement-1]
    {WHEN condition imperative-statement-2} ...
[END-SEARCH]
  • Linear search — O(n) — scans from the current index position.
  • You must SET index TO 1 before SEARCH unless you want to start mid-table.

A.7.2 SEARCH ALL (Binary)

SEARCH ALL identifier-1
    [AT END imperative-statement-1]
    WHEN {data-name = {identifier | literal | arithmetic-expression}}
         [AND {data-name = ...}] ...
        imperative-statement-2
[END-SEARCH]
  • Binary search — O(log n) — requires the table be sorted on the search key.
  • The WHEN condition must use = (equality only) and reference the ASCENDING/DESCENDING KEY field(s).
  • Only one WHEN clause is allowed with SEARCH ALL.

A.7.3 SET (for indexes and conditions)

SET index-name-1 ... TO {index-name-2 | identifier | integer}
SET index-name-1 ... {UP BY | DOWN BY} {identifier | integer}
SET condition-name TO TRUE
SET {identifier | POINTER} TO {identifier | POINTER | NULL | NULLS}

A.8 PROCEDURE DIVISION — File I/O

A.8.1 OPEN / CLOSE

OPEN {INPUT | OUTPUT | I-O | EXTEND} file-name-1 [file-name-2] ...
CLOSE file-name-1 [WITH {NO REWIND | LOCK}] [file-name-2 ...] ...

A.8.2 READ

READ file-name [NEXT | PREVIOUS] RECORD [INTO identifier]
    [AT END imperative-statement-1]
    [NOT AT END imperative-statement-2]
[END-READ]

READ file-name RECORD [INTO identifier]
    [KEY IS data-name]
    [INVALID KEY imperative-statement-1]
    [NOT INVALID KEY imperative-statement-2]
[END-READ]

A.8.3 WRITE

WRITE record-name [FROM identifier]
    [{BEFORE | AFTER} ADVANCING {identifier | integer} {LINES | LINE}
                               | {PAGE | mnemonic-name}]
    [INVALID KEY imperative-statement-1]
    [NOT INVALID KEY imperative-statement-2]
[END-WRITE]

A.8.4 REWRITE

REWRITE record-name [FROM identifier]
    [INVALID KEY imperative-statement-1]
    [NOT INVALID KEY imperative-statement-2]
[END-REWRITE]

A.8.5 DELETE

DELETE file-name RECORD
    [INVALID KEY imperative-statement-1]
    [NOT INVALID KEY imperative-statement-2]
[END-DELETE]

A.8.6 START

START file-name KEY IS {= | > | >= | < | <= | NOT < | NOT >} data-name
    [INVALID KEY imperative-statement-1]
    [NOT INVALID KEY imperative-statement-2]
[END-START]

A.9 PROCEDURE DIVISION — SORT and MERGE

A.9.1 SORT

SORT sort-file
    ON {ASCENDING | DESCENDING} KEY data-name-1 ...
    [ON {ASCENDING | DESCENDING} KEY data-name-2 ...] ...
    [WITH DUPLICATES IN ORDER]
    [COLLATING SEQUENCE IS alphabet-name]
    {INPUT PROCEDURE IS procedure-name-1 [THRU procedure-name-2]
     | USING file-name-1 [file-name-2] ...}
    {OUTPUT PROCEDURE IS procedure-name-3 [THRU procedure-name-4]
     | GIVING file-name-3 [file-name-4] ...}
  • INPUT PROCEDURE lets you filter or transform records via RELEASE before sorting.
  • OUTPUT PROCEDURE lets you process sorted records via RETURN before writing.
  • WITH DUPLICATES IN ORDER preserves the original sequence of records with equal keys.

A.9.2 MERGE

MERGE merge-file
    ON {ASCENDING | DESCENDING} KEY data-name-1 ...
    [COLLATING SEQUENCE IS alphabet-name]
    USING file-name-1 file-name-2 [file-name-3] ...
    {OUTPUT PROCEDURE IS procedure-name [THRU procedure-name-2]
     | GIVING file-name-4 [file-name-5] ...}

A.9.3 RELEASE and RETURN

RELEASE record-name [FROM identifier]
RETURN sort-merge-file RECORD [INTO identifier]
    AT END imperative-statement
    [NOT AT END imperative-statement]
[END-RETURN]

A.10 PROCEDURE DIVISION — Subprogram Interface

A.10.1 CALL

CALL {identifier | literal}
    [USING {[BY REFERENCE | BY CONTENT | BY VALUE] {identifier | OMITTED}} ...]
    [RETURNING identifier]
    [ON OVERFLOW imperative-statement-1]
    [ON EXCEPTION imperative-statement-1]
    [NOT ON EXCEPTION imperative-statement-2]
[END-CALL]

Parameter passing modes:

Mode Caller's Data Callee Can Modify? Callee Sees Changes?
BY REFERENCE (default) Address passed Yes — changes visible to caller Yes
BY CONTENT Copy passed Callee modifies copy only No
BY VALUE Value passed (binary) Callee modifies local copy No

A.10.2 CANCEL

CANCEL {identifier | literal} ...

Releases the subprogram from memory and ensures the next CALL will reinitialize it.

A.10.3 GOBACK and STOP RUN

GOBACK
STOP RUN [RETURNING {integer | identifier}]
  • GOBACK returns control to the calling program (or the operating system if it is the main program). Preferred over STOP RUN in subprograms.
  • STOP RUN terminates the entire run unit — never use in a subprogram called by CICS or another framework.

A.11 Embedded SQL (EXEC SQL)

EXEC SQL
    sql-statement
END-EXEC

Common patterns:

EXEC SQL
    SELECT COL1, COL2
    INTO :WS-HOST-VAR1, :WS-HOST-VAR2
    FROM TABLE1
    WHERE KEY_COL = :WS-KEY
END-EXEC

EXEC SQL
    DECLARE CURSOR cursor-name FOR
    SELECT columns FROM table WHERE condition
    ORDER BY column
END-EXEC

EXEC SQL OPEN cursor-name END-EXEC
EXEC SQL FETCH cursor-name INTO :host-variables END-EXEC
EXEC SQL CLOSE cursor-name END-EXEC

EXEC SQL INSERT INTO table (columns) VALUES (:host-vars) END-EXEC
EXEC SQL UPDATE table SET col = :host-var WHERE condition END-EXEC
EXEC SQL DELETE FROM table WHERE condition END-EXEC

EXEC SQL INCLUDE SQLCA END-EXEC
EXEC SQL INCLUDE copybook-name END-EXEC

SQLCODE checking pattern:

EVALUATE SQLCODE
    WHEN 0
        CONTINUE
    WHEN 100
        SET WS-NO-MORE-ROWS TO TRUE
    WHEN -803
        DISPLAY 'Duplicate key on INSERT'
    WHEN OTHER
        DISPLAY 'SQL Error: ' SQLCODE
        PERFORM 9999-ABEND-ROUTINE
END-EVALUATE

A.12 EXEC CICS Commands

EXEC CICS command option(value) ... END-EXEC

Frequently used commands:

Command Purpose Key Options
SEND MAP Send a BMS map to terminal MAP, MAPSET, ERASE, CURSOR
RECEIVE MAP Receive data from terminal MAP, MAPSET, INTO
READ Read a VSAM record FILE, INTO, RIDFLD, UPDATE
WRITE Write a new record FILE, FROM, RIDFLD
REWRITE Update a record FILE, FROM
DELETE Delete a record FILE, RIDFLD
LINK Call a program, expect return PROGRAM, COMMAREA, LENGTH
XCTL Transfer control, no return PROGRAM, COMMAREA, LENGTH
RETURN Return to CICS TRANSID, COMMAREA, LENGTH
STARTBR Start a browse FILE, RIDFLD, GTEQ
READNEXT Read next in browse FILE, INTO, RIDFLD
ENDBR End browse FILE
HANDLE CONDITION Legacy exception handling condition(label)
HANDLE ABEND Abend handler PROGRAM, LABEL

RESP/RESP2 pattern (modern exception handling):

EXEC CICS READ FILE('CUSTFILE')
    INTO(WS-CUST-RECORD)
    RIDFLD(WS-CUST-KEY)
    RESP(WS-RESP)
    RESP2(WS-RESP2)
END-EXEC

EVALUATE WS-RESP
    WHEN DFHRESP(NORMAL)
        CONTINUE
    WHEN DFHRESP(NOTFND)
        PERFORM 3100-CUSTOMER-NOT-FOUND
    WHEN OTHER
        PERFORM 9000-CICS-ERROR
END-EVALUATE

A.13 DL/I (IMS) Calls

CALL 'CBLTDLI' USING function-code
                      pcb-mask
                      io-area
                      [ssa-1] [ssa-2] ...

Common function codes:

Code Function Purpose
GU Get Unique Direct retrieval using full key
GN Get Next Sequential retrieval
GNP Get Next within Parent Sequential under current parent
GHU Get Hold Unique Retrieve for update
GHN Get Hold Next Sequential retrieve for update
GHNP Get Hold Next within Parent Sequential under parent for update
ISRT Insert Add a new segment
REPL Replace Update a held segment
DLET Delete Delete a held segment

SSA (Segment Search Argument) format:

segment-name(field-name operator value)

Operators: =, >=, <=, >, <, !=


A.14 Common Compiler Options (IBM Enterprise COBOL)

Option Purpose Recommended
APOST / QUOTE String delimiter character Shop standard
ARITH(EXTEND) 31-digit precision Yes for financial
CODEPAGE(1140) EBCDIC code page Match your system
COMPILE / NOCOMPILE(S) Compile even with errors? NOCOMPILE(S)
DBCS / NODBCS Double-byte character support If needed
DYNAM / NODYNAM Dynamic vs. static CALL DYNAM for flexibility
FLAG(I,E) Diagnostic message level FLAG(I,I) during dev
LIST Generate assembler listing Debug only
MAP Generate data map Yes
OPTIMIZE(0\|1\|2) Optimization level 2 for production
RENT / NORENT Reentrant code RENT for CICS
SQL / NOSQL DB2 precompiler If using SQL
SSRANGE / NOSSRANGE Subscript range checking Yes during testing
TEST / NOTEST Debug information TEST during dev
THREAD / NOTHREAD Thread safety If multi-threaded
TRUNC(STD\|OPT\|BIN) Binary field truncation Know your shop std
VBREF Verb cross-reference Useful for review
XREF(FULL) Cross-reference listing Yes

A.15 Intrinsic Functions Quick Reference

FUNCTION function-name (argument ...)

Frequently used intrinsic functions:

Function Returns Example
CURRENT-DATE 21-char date/time string FUNCTION CURRENT-DATE
INTEGER-OF-DATE(date) Integer day number FUNCTION INTEGER-OF-DATE(20260115)
DATE-OF-INTEGER(int) YYYYMMDD from day number FUNCTION DATE-OF-INTEGER(val)
WHEN-COMPILED Compilation date/time FUNCTION WHEN-COMPILED
LENGTH(item) Length in bytes FUNCTION LENGTH(WS-NAME)
BYTE-LENGTH(item) Length in bytes (DBCS-safe) FUNCTION BYTE-LENGTH(WS-DATA)
MAX(a b ...) Maximum value FUNCTION MAX(A B C)
MIN(a b ...) Minimum value FUNCTION MIN(A B C)
MOD(a b) Modulus FUNCTION MOD(17 5) = 2
ORD-MAX(a b ...) Position of max FUNCTION ORD-MAX(A B C)
ORD-MIN(a b ...) Position of min FUNCTION ORD-MIN(A B C)
NUMVAL(string) Numeric value of string FUNCTION NUMVAL(WS-TEXT)
NUMVAL-C(string) Numeric value (currency) FUNCTION NUMVAL-C(WS-AMT)
INTEGER(number) Truncate to integer FUNCTION INTEGER(3.7) = 3
INTEGER-PART(num) Integer part FUNCTION INTEGER-PART(-3.7) = -3
REM(a b) Remainder FUNCTION REM(17 5) = 2
REVERSE(string) Reversed string FUNCTION REVERSE('ABC') = 'CBA'
LOWER-CASE(str) Lowercase FUNCTION LOWER-CASE(WS-NAME)
UPPER-CASE(str) Uppercase FUNCTION UPPER-CASE(WS-NAME)
TRIM(str [LEADING\|TRAILING]) Remove spaces FUNCTION TRIM(WS-NAME)
SUBSTITUTE(str a b ...) Replace substrings COBOL 2014
CONCATENATE(a b ...) Join strings COBOL 2014
MEDIAN(a b ...) Median value FUNCTION MEDIAN(A B C)
MEAN(a b ...) Arithmetic mean FUNCTION MEAN(A B C)
VARIANCE(a b ...) Statistical variance FUNCTION VARIANCE(A B C)
STANDARD-DEVIATION(...) Std deviation FUNCTION STANDARD-DEVIATION(A B C)
RANDOM(seed) Pseudo-random 0 to 1 FUNCTION RANDOM(0)

A.16 File Status Codes — Quick Reference

Code Meaning
00 Successful completion
02 Duplicate key (read), record found with duplicate alternate key
04 Record length mismatch
05 File not present (OPTIONAL file)
10 End of file
21 Sequence error
22 Duplicate key (write)
23 Record not found
24 Disk full / boundary violation
30 Permanent I/O error
34 Boundary violation on sequential write
35 File not found on OPEN
37 File mode conflict
39 Attribute mismatch
41 File already open
42 File not open
43 No prior READ for DELETE/REWRITE
44 Record length error on REWRITE
46 No valid next record (sequential READ)
47 READ after file not opened INPUT/I-O
48 WRITE after file not opened OUTPUT/I-O/EXTEND
49 DELETE/REWRITE after file not opened I-O
90–99 Vendor-specific

This reference card covers the essential COBOL language elements used throughout Intermediate COBOL: Beyond the Basics. For complete syntax and semantic rules, consult your compiler's Language Reference manual — IBM's Enterprise COBOL for z/OS Language Reference or Micro Focus's COBOL Language Reference are the authoritative sources. When in doubt, compile with FLAG(I,I) and SSRANGE enabled, and let the compiler tell you what it expects.