%REPLACE

Purpose

Specifies that an identifier is a constant of a given value.

Syntax

%REPLACE name BY constant;

Description

The %REPLACE statement specifies that an identifier is a constant of a given value.

Beginning at the point at which the %REPLACE statement is encountered, each occurrence of name that follows the %REPLACE statement is replaced by the constant until the end of compilation.

The %REPLACE statement is normally used to supply the sizes of tables or to give names to special constants whose meaning would not otherwise be obvious.

Example

%REPLACE TRUE BY '1'B;
%REPLACE TABLE_SIZE BY 400;
%REPLACE MOTOR_POOL BY 5;
%REPLACE X BY -3.0E0;
DECLARE X(TABLE_SIZE) FIXED STATIC; 
DO K = 1 TO TABLE_SIZE;
IF DEPARTMENT_NUMBER = MOTOR_POOL 
   THEN DO;
      .
      .
      .

Restrictions

The %REPLACE statement operates on the program text without regard to the meaning of the text, which means that a replaced name can accidentally be a keyword such as STOP or READ. in this case, an "unrecognizable statement" error message is issued by the Compiler when it reads a subsequent STOP or READ statement. An error statement is also issued by the Compiler when an attempt is made to replace one name by two different constants.

The %REPLACE statement substitutes all subsequent occurrences of the name without regard to the block structure of the module.