ARRAY TEMP

<< Click to Display Table of Contents >>

Navigation:  Reference > Commands >

ARRAY TEMP

For use in Data stages only.

The form of the ARRAY TEMP command is:

ARRAY TEMP t $array (numindex [,numindex] [,numindex]),

ARRAY TEMP t $array (numindex [,numindex] [,numindex]) (length),

where t is S, M, I or W to indicate the variable type, array is a normal CL variable name up to 30 characters and numindex are constant values which specify the number of index entries in the array dimension (1 to 10000). For svars and mvars the length (number of bits) for each array must also be specified. Each array has up to three dimensions and is specified once before it is used.

Arrays are used to hold temporary arrays of any type of variable except cvars. There is no practical limit on the number of values to be held and each array may have up to 32000 entries. The array temporary area is separate from the existing temporary area and it is automatically allocated during execution. The TEMPORARY command is not used.

To save execution time the array temp area is initialised to zero only at the beginning of the Data Stage execution; the values are not reinitialised for each new record (similar to PRESERVE TEMPORARY). A Z (zero) command can be used at the beginning of a Data Stage (after the ARRAY TEMP command) to reset the whole array for a new record.

ARRAY TEMP is a non-executable command which will not alter any values currently held. This command must appear before any references to the array. This command will normally be followed immediately with:

Z $array,

which sets all the array contents to zero or empty.

Whenever the array is used the name must always be followed by the index numbers separated by commas in parentheses. The index numbers can be any arithmetic expression with a value between 1 and numindex. If any attempt is made to refer to an index out of bounds (less than 1 or greater than numindex) an execution error will occur.

Array contents may be set individually using a D (define) command anywhere a normal variable of the same type could be defined. For mvars ORD (or define) may also be used. Only define commands can be used to set array contents - so for example, M (make) cannot be used to set array contents and L (list) cannot be used to output contents.

Examples of array settings:

array temp i $iarr(10,15,2), ! 300 ivars

di $ival=15,

di $iarr(1,1,1)=($ival*45)/2, ! sets first

di $iarr($ival-5,$ival,2)=4, ! sets last

array temp w $wset (4), ! 4 wvars

dw $wset($ival/5)=15.3, ! sets third

array temp s $sall(10,10)(3) ! 100 svars of 10 bits

ds $sall(1,1)=$ival/13-15, ! sets first

array temp m $mkeep(900)(16), ! 900 mvars of 16 bits

dm $mkeep(900)=t,$ival/1-15, ! sets last

Where individual array contents can be used varies, depending on the type of array. Broadly speaking they can be used in D (define) and IF commands; listed below are the only places that individual array contents can be used:

ivars and wvars

Can be used in arithmetic expressions and logical expressions anywhere a normal ivar or wvar could be used.

svars

Can be used in logical expressions and string definitions anywhere a normal svar could be used.

Can also be used in arithmetic expressions anywhere a normal svar could be used as a value but you must not use it to index into a set of values or a table as in:

array temp s $sarr(15)(5), 

di $i3=$sarr(1)(1,2,3,4,5), ! NOT ALLOWED

dw $w3=$sarr($ii)(#15), ! NOT ALLOWED

mvars

Can be used in logical expressions anywhere a normal mvar could be used except when a count of bits is involved or testing against other mvars:

array temp m $mkeep(10)(5),

if $mkeep(1)/b, ! NOT ALLOWED

if $mkeep(1)/s, ! NOT ALLOWED

if $mkeep(1)/m, ! NOT ALLOWED

if ct($mkeep(1))/3, ! NOT ALLOWED

if $mkeep(1).eq.$mkeep(2) ! NOT ALLOWED

Can be used in string definitions anywhere a normal mvar could be used, but see above concerning tests.

The following contains some examples of valid references to array temp variables:

array temp i $ithis(33,10),

array temp s $sthis(10)(5),

array temp m $mthis(2,3,5)(20),

array temp w $wthis(4),

z $sthis.$ithis.$mthis.$wthis,

 

di $ithis(1,1)=1,

di $ithis(2,3)=23,

di $ithis(3,2)=$ithis(3,2)+32,

di $iset=10,

di $ithis(33,$iset)=99,

di $ithis($iset-6,$iset)=1+$ithis(2,3)+3,

if $ithis(4,$iset)/n27, show 'ithis(4,10) not 27',

if $ithis(3,2)/n32, show 'ithis(3,2) not 32',

di $i1=$ithis(1,$iset)+1,

 

ds $sthis(1)=t,f,f,f,f,

di $iset=3,

ds $sthis(3)=$iset/1-5,

ds $sthis(10)=f,f,$iset/1-3,

if $ithis(1,1).eq.$ithis(3,2), show 'OK',

di $i2=$sthis(3),

di $i3=($sthis(10)*10)/2,

ck $sthis(3)/3,

ds $ss2=$sthis(10)/1-5,

ds $ss3=f,$sthis(1)/1-3,f,

 

di $iset=1,

dm $mthis(1,1,1)=$iset/1-20,

di $iset=5,

dm $mthis(1,2,3)=t,$iset/1-18,t,

di $iset=19,

dm $mthis(2,3,5)=$iset/1-20,

dm $mthis(2,2,2)=t,f,f,t,t,t,t,f,t,t,t,t,t,t,f,t,t,t,f,t,

ordm $mthis(2,2,2)=f,t,$mthis(1,2,3)/1-18,

dm $mm2=$mthis(2,2,2),

dm $mm3=t,$mthis(2,3,5)/14-20,19,19-20,

$mthis(1,2,3)/1..2,2..3,2..6,1-6, 

 

di $iset=2,

dw $wthis($iset+1)=8.0,

dw $wthis($iset)=$wthis($iset+1),