Named constants

In this section, the names of constants are shown containing the underscore character (_) as part of the name. In COBOL, use the hyphen character (-) in place of the underscore.

Constants that have character-string values use the single quotation mark as the string delimiter ('). In some environments, you might have to specify an appropriate compiler option to cause the compiler to accept the single quotation mark as the string delimiter in place of the double quotation mark.

The named constants are declared in the COPY files as level-10 items. To use the constants, declare the level-01 item explicitly, and then use the COPY statement to copy in the declarations of the constants:
* Declare a structure to hold the constants
 01  MY-MQ-CONSTANTS.
     COPY CMQV.
The preceding method causes the constants to occupy storage in the program even if they are not referenced. If we include the constants in many separate programs within the same run unit, multiple copies of the constants exist, consuming main storage unnecessarily. Avoid this effect by using one of the following techniques:

  • Add the GLOBAL clause to the level-01 declaration:
    * Declare a global structure to hold the constants
     01  MY-MQ-CONSTANTS GLOBAL.
         COPY CMQV.
    

    This causes allocates storage for only one set of constants within the run unit. The constants, however, can be referenced by any program within the run unit, not just the program that contains the level-01 declaration.

    Note: The GLOBAL clause is not supported in all environments.
  • Manually copy into each program only those constants that are referenced by that program. Do not use the COPY statement to copy all the constants into the program.

Parent topic: COBOL programming