EQUATE Statement

The EQUATE statement allows a constant to be assigned at compile time.

Format

EQU[ATE] var TO value [, var2 TO value2, ...]

Parameter(s)

var

Name to be assigned to the constant.

value

A constant, another variable, or the CHAR function.

Description

The EQUATE statement may be used to define a constant or to make one variable equivalent to another. The value is compiled directly into the object code, so there is no storage location generated for the variable. It differs from the standard assignment statement (=) in that the assignment is made at compilation and does not have to be reassigned each time the program is executed.

Only literal constants or other variables may be used as the value. No operators or functions may be used in value; otherwise it could not be evaluated until run time. The one exception is the CHAR function.

The EQUATE statement is usually used to define constants and to provide more meaningful names for variables. Any number of variables may be assigned with a single EQUATE statement, with each clause separated by a comma. An EQUATE statement can be broken into two or more lines, provided that the new line occurs directly after the comma. Multiple EQUATE statements may be used in a program as long as the same variable is not equated twice. Once the EQUATE statement has been used to assign a value to a variable, the variable may not be changed.

A variable cannot be referred to prior to the EQUATE statement which defines it, or an error similar to this example will occur at compile time:

[B115]  LINE 9  LABEL 'ERR.BELL' IS USED BEFORE THE EQUATE STMT

This error message occurs if the variable is used in any way. This includes assignment via the standard assignment operator (=), or if the variable had been previously equated.

Common uses of the EQUATE statement are:

EQUATE AM TO CHAR(254),

VM TO CHAR(253),

SVM TO CHAR(252),

TRUE TO 1,

FALSE TO 0,

BELL TO CHAR(7)

ESC TO CHAR(27)

Example

In this application the EQUATE statement is used to give meaningful names to the elements of an array. It is also used to give meaningful names to the bell character (CHAR(7)) and to logical true and false (1 and 0), to make the program more readable.

DIMENSION CUST(6)

EQUATE BELL TO CHAR(7), TRUE TO 1, FALSE TO 0

EQUATE NAME TO CUST(1), ADDRESS TO CUST(2),

   CITY TO CUST(3), STATE TO CUST(4),

   ZIP TO CUST(5), PHONE TO CUST(6)

   .

   .

   .

See Also

Statement and Function Reference