Progress
Language Tutorial
for Windows
Using the FOR EACH Block
The FOR EACH block has implicit looping, frame allocation, and record reading block properties. FOR EACH is an essential structure for moving through the records of a database table. Each iteration of the block reads a new record from the table. When no records are left, the block ends. While the FOR EACH header reads a record, the statements inside the FOR EACH block typically work with the data of that record. Therefore, the main use of this structure is to move through and process the data of a database table. "Using Database Records," and "Selecting, Sorting, and Relating Records," extensively describe the use of FOR EACH as a record-reading tool. This section introduces the properties of the FOR EACH block.
This is the basic syntax of FOR EACH.
This simple example of FOR EACH shows the implicit block properties:
The following notes describe the implicit block properties:
- The record phrase defines the implicit looping of a FOR EACH block. The actual number of iterations of the FOR EACH statement is the sum of all records of all tables referenced in the record phrase. However, the FOR EACH statement does not necessarily execute the statements inside the block for each record of the database table. FOR EACH executes these statements when the current record matches the criteria specified in the record phrase. In this example, the statements execute for every record, since no selection criteria exist.
- The record phrase is a Progress language structure that lets you specify options for selecting, sorting, and relating records. In the last chapter, you learned how to create record-selection expressions using the WHERE syntax. You’ve also seen that specifying a table name, as in this example, selects all the records of the table. Both of these techniques are uses of the record phrase.
- This statement performs screen output, so Progress creates a default frame for the FOR EACH block to use.
This example of FOR EACH shows the explicit block properties:
These notes describe the explicit block properties:
- The WHERE expression in the record phrase restricts the number of records that execute the statement of the block body. Although Progress reads every record and compares it to the WHERE expression, Progress executes the block statements for only those records where the Balance field is less than 1000. On the other hand, the default implicit record reading property executes the block for every record.
- The frame phrase here names a frame for use with the screen-output statements of the block. Frame3 could be either a previously defined frame or a new frame created for the block.
Although the TO and WHILE syntaxes for explicit looping are valid with FOR EACH, they are not commonly used.
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |