10.14.6 Process File Records (FOR)

Syntax

FOR [EACH] fname statement

Fname is the internal file name declared earlier. Statement can be any valid statement as described in the beginning of the section on statements. Notice that only a single statement is allowed, however. For this reason, in order to process multiple statements for records accessed via the FOR statement, either the compound statement must by used, or a procedure must by called.

Any nonunique field references in statement will be resolved using fname.

Purpose

The FOR statement is used to read all of the records from a file and to execute a statement for each record read. If the last operation done on the file was a SELECT, the FOR statement will read the records returned by the SELECT. If a SELECT has not been done on the file, or if a FOR statement has already been done after the last SELECT, each active record in the file will be read.

Breaks and totals are handled automatically. The order of processing is:

Repeat until EOF

Read the next record

If end of file

process end of field breaks

exit loop

If not the first record

Check for end-of-field breaks

Store new values

Accumulate totals

Check for start-of-field breaks

Process statement

Examples:

FOR EACH master

DO process_master;

FOR EACH detail

IF last_pdate LT $todays_date - 30

THEN

DO over_due_acct;

ELSE

DO current_acct;