Previous Topic: DBCS Device Support

Next Topic: Undefined Variable Substitution

Variable Substitution

Before a procedure statement is analyzed or a command is executed, the record is scanned for the presence of variables, indicated by an ampersand (&). This process is called variable substitution. Variable substitution is performed from right to left of the statement. When a potential variable is detected by the presence of an ampersand, the variable is isolated by scanning to the right for a delimiting blank, comma, or other character not valid in a variable name.

Note: A single character ampersand is not treated as a variable and remains intact as a single ampersand.

Take the string &A.1 as an example. &A is processed as the variable and the resulting substitution inserted in its place (for example, 123.1).

Variables whose names are entirely numeric (for example, &99) have unique properties in that they are delimited by the first non-numeric character. For example:

&91 = 123
&A  = &91ABC

The variable &A in this example would yield the value 123ABC. This technique can provide an alternative to the use of &CONCAT with alphanumeric variables.

In the substitution process no spaces are added or deleted. The variable is removed and the text to the right of the variable is relocated to accommodate the data being substituted in place of the variable. A variable can be referenced as often as required. Left and right alignment of substituted data can be achieved using the &CONTROL ALIGNL and ALIGNR options to enhance tabular output or when displaying data in full-screen panels the #FLD statement can be used to assign specific alignment attributes to a field.