Using the FIND statement in a REPEAT block
- Last Updated: March 30, 2020
- 2 minute read
- OpenEdge
- Version 12.2
- Documentation
Notice the use of the REPEAT block
to cycle through the remaining Customers.
Within that block, you must write a FIND statement
to get the next Customer because the REPEAT block
itself, unlike the FOR EACH block, does not do
the navigation for you. Also, the REPEAT block
does not automatically terminate when the end of the Customers is reached,
so you need to program the block with these three actions:
- You must do the
FINDwith theNO-ERRORqualifier at the end of the statement. This suppresses the error message that you would ordinarily get when there is no next Customer. - You must use the
AVAILABLEkeyword to check for the presence of a Customer and display fields only if it evaluates toTRUE. - You must write an
ELSEstatement to match theIF-THENstatement, to leave the block when there is no Customer available. Otherwise, your block goes into an infinite loop when it reaches the end of the Customer records. And notice that this truly is a separate statement. TheIF-THENstatement ends with a period and theELSEkeyword begins a statement of its own.
All of these are actions that the FOR EACH block
does for you as it reads through the set of Customers.
In the REPEAT block, though, where you're doing
your own navigation, you need to do these things yourself.
Remember also that the REPEAT block scopes the statements
inside the block to its own frame, unless you tell it otherwise.
Therefore, you get one frame for the FIRSTCustomer and
a new frame for all the Customer records
retrieved within the REPEAT block.
The keyword AVAILABLE is an ABL built-in function,
so its one argument properly belongs in parentheses, as in IF AVAILABLE
(Customer). However, to promote the readability of the
ABL statement, the syntax also accepts the form as if it were a
phrase without the parentheses, as in IF AVAILABLE Customer.
This alternative is not generally available with other built-in
functions.
Finally, the FORMAT "X(20)" phrase reduces the display
size of the Name field from its default (defined
in the Data Dictionary) of 30 characters, to make room for the PostalCode field.