Use the FIND statement in a REPEAT block
- Last Updated: December 18, 2023
- 2 minute read
- OpenEdge
- Version 13.0
- 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 nextCustomer. - You must use the
AVAILABLEkeyword to check for the presence of aCustomerand display fields only if it evaluates toTRUE. - You must write an
ELSEstatement to match theIF-THENstatement, to leave the block when there is noCustomeravailable. Otherwise, your block goes into an infinite loop when it reaches the end of theCustomerrecords. 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 are 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 FIRST Customer 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.