10.11 VARIABLE Declarations

Syntax

varname

VARIABLE[S] IS varname [ const ]

ARE varname TOTAL [OF] fldref

varname RUNNING TOTAL [OF] fldref

Varname must be a valid internal Report Writer name. These names must be unique from any other field or variable names. Const is a single integer constant which is used to declare the size of an array of variables. Fldref can be the name of a previously declared variable or the name of a declared field. Fldref can also reference a single element of a field array: fieldname [const].

A variable may either be a simple variable, or it may be a total of some other field or variable. Simple variables may be declared as arrays. The pair of brackets ([]) are required when declaring a variable as an array.

Purpose

Variable declarations create areas to store intermediate results and to do total accumulations.

When a totaling variable is declared as a TOTAL, each time the variable is used in an expression it is reset to zero. If the totaling variable is declared as RUNNING TOTAL, the variable will remain unchanged when used in an expression. Variables may total fields or other previously declared variables. If the item being totaled is an array, the totaling variable will be set up as an array; each element being the total of the corresponding element of the item being totaled. If the item being totaled is an array element, the totaling variable will be set up as a single value. Each time a value is stored into the item being totaled the corresponding totaling variable will be incremented by the value being stored.

Example:

VARIABLES ARE

amount,

save_tr_codes [20],

total_amount TOTAL OF amount,

balance RUNNING TOTAL OF amount,

current TOTAL balances [1],

total_aged TOTAL OF aged_balances;