Previous Topic: Explicit Assignment: Assignment Statement

Next Topic: Implicit Assignment: Using &ASSIGN

Complex Variables in Assignment Statements

Use of complex variables within an assignment is supported. A complex variable requires multiple substitutions to determine the final variable required. For example:

&&1
&A&1

An example of the use of complex variables is the accumulation of counts for different values. A counter is initialized for each possible value. A single statement can then be used to increment the associated counter.

Example: Complex Variables in Assignment Statements

In this example, a variable (&1) can have the values A, B, or C and you want to count the occurrences of each of these. This could be achieved in the following way:

&CNTA = 0
&CNTB = 0
&CNTC = 0
   .
   .
   .
&DOWHILE &CNT&1 NE &LIMIT
   .
   .
   processing to receive input and set &1 to A, B or C
   .
   .
   &CNT&1 = &CNT&1 + 1
&DOEND

The assignment statement target (&CNT&1) will be resolved to &CNTA, &CNTB or &CNTC prior to execution.