Constants: level 78 and VALUE

Level 78 items

Level 78 declares a named constant. It cannot be assigned to, and it appears in expressions like a variable:

78 MAX-EMPLOYEES VALUE 50. 78 TAX-RATE VALUE 0.13.

Using constants

Use constants everywhere a literal would go. The name documents the number, and one edit changes every use:

COMPUTE WS-LIMIT = MAX-EMPLOYEES * 2. COMPUTE WS-TAX = WS-SALARY * TAX-RATE.

CONSTANT phrase

COBOL 2014 adds the CONSTANT phrase to VALUE, which rejects redefinition at compile time. Level 78 remains the common way, and both styles are case-insensitive like all COBOL.

The code on this page was run with GnuCOBOL 3.2.0 on Alpine Linux 3.24.3 (x86_64) in a Docker container.

Article author: Arthur Isaev