You are here: Commands > Group > Variables in Groups

Variables in Groups

Using variables is an effective method of storing information from one record for use with information in later related records. Variables also allow values to be accumulated for a set of related records.

For example, assume you have an accounts receivable transaction file sorted on the CustNo field from which you want to create a running total for each customer’s transaction Amount field and output all transactions with their running total for subsequent analysis to a new file.

V_CUSTNO=CustNo¿

V_AMOUNT=0.00¿

GROUP IF V_CUSTNO=CustNo¿

V_AMOUNT=V_AMOUNT+Amount¿

EXTRACT V_CUSTNO Amount V_AMOUNT TO “TotalsCust.fil”¿

ELSE¿

V_AMOUNT=Amount¿

V_CUSTNO=CustNo¿

EXTRACT V_CUSTNO Amount V_AMOUNT TO “TotalsCust.fil”¿

END¿

For more information, see Variables.

Note: When accumulating information in a Group for subsequent extraction or other command processing that is triggered when key values change or the end of file is reached (see EOF), it is mandatory that you store all required field and key information in variables to ensure that it is available to be processed when the command is triggered.