Previous Topic: Undefined Variable Substitution

Next Topic: Align Substitution Data

Complex Variable Substitution

Complex or multi-level variables are supported. If after one substitution, the value generated remains a variable (commences with an &), substitution is again performed.

Example 1: Complex Variable Substitution

&A = 1
&1 = MESSAGE
&WRITE DATA=TEST &&A

Because the current value of &A (1) is substituted into the statement, the first pass of the &WRITE statement yields:

&WRITE DATA=TEST &1

The second pass then resolves &1, and yields:

&WRITE DATA=TEST MESSAGE

Example 2: Complex Variable Substitution

Complex variables are important when performing matrix processing where an unknown number of variables must be dynamically generated to accommodate data.

&FILE OPEN ID=MYFILE
&FILE SET ID=MYFILE KEY=MYKEY
&LIMIT = 100
&CNT = 1
&DOWHILE &CNT LT &LIMIT
         &FILE GET ID=MYFILE OPT=KEQ VARS=MYFIELD1
         &SAVE&CNT = &MYFIELD1
         &CNT = &CNT + 1
&DOEND