CONST{(constant)}
- To specify the value of a named constant
- To indicate that a parameter passed by reference is read-only.
- To indicate that a standalone field or data structure cannot be changed.
Named constants
When specifying the value of a named constant, the CONST keyword itself is optional. That is, the constant value can be specified with or without the CONST keyword.
The parameter must be a literal, figurative constant, or built-in-function. The constant may be continued on subsequent lines by adhering to the appropriate continuation rules (see Continuation Rules for further details).
If a named constant is used as a parameter for the keywords DIM, OCCURS, PERRCD, or OVERLAY, the named constant must be defined prior to its use.
See Examples of literals used to initialize fields for examples of defining named constants.
Read-only reference parameters
When specifying a read-only reference parameter, you specify the keyword CONST on the definition specification of the parameter definition on both the prototype and procedure interface. No parameter to the keyword is allowed.
When the keyword CONST is specified, the compiler may copy the parameter to a temporary defined with the same data type and length as the prototyped parameter and pass the address of the temporary. Some conditions that would cause this are: the passed parameter is an expression or the passed parameter has a different format.
Do not use this keyword on a prototype definition unless you are sure that the parameter will not be changed by the called program or procedure.
If the called program or procedure is compiled using a procedure interface with the same prototype, you do not have to worry about this, since the compiler will check this for you.
Although a CONST parameter cannot be changed by statements within the procedure, the value may be changed as a result of statements outside of the procedure, or by directly referencing a global variable.
Passing a parameter by read-only reference has the same advantages as passing by value. In particular, it allows you to pass literals and expressions.
See OPTIONS(*NOPASS *OMIT *VARSIZE *EXACT *STRING *TRIM *RIGHTADJ *NULLIND *CONVERT) for examples of defining read-only reference parameters.
Constant variables
- See Constant standalone field for an example of a constant standalone field.
- See Defining a constant data structure for an example of a constant data structure.