The CONSTANT clause specifies that the 01 level item has a constant value, which cannot be modified.
General Format
Syntax Rules
- This clause can only be specified at the 01 level.
- This clause can only be specified in WORKING-STORAGE and LINKAGE SECTION.
- The data item can only be used as sending item in a COBOL statement, and cannot be used in an operand that the statement could
modify.
- Every elementary item must be subject to a VALUE clause; except, if CONSTANT is specified with a TYPEDEF definition.
- This clause cannot be used with the following qualifiers or usage: COMP-1, COMP-2, PIC 1, any pointer type, REDEFINES, EXTERNAL-FORM,
index-names, THREAD-LOCAL, or the REENTRANT"2" directive.
- If a CALL statement includes a CONSTANT parameter, and a matching call prototype is defined, the equivalent parameter in the
prototype must also include the CONSTANT clause.
- If the clause is used on a data item in a call prototype, the CONSTANT clause must also be specified for the corresponding
parameter used in the sub-program.
General Rules
- Data items specifying CONSTANT that will be allocated to WORKING-STORAGE will be placed in read-only memory for native code
execution.
- CONSTANT items used for EXTERNAL and LINKAGE SECTION means cannot be modified by COBOL statements in the program.
-
JVM COBOL has its own implementation of a CONSTANT qualifier, which can only be used with
Java native types.
- The CONSTANT clause on tables is limited to one level of OCCURS.
- In table initialization, if a Value clause is used with multiple values (which can initialize individual elements in the table),
any other Value clause that follows this one in the code must use multiple values as well or none at all.