Try OpenEdge Now
skip to main content
ABL Essentials
Procedure Blocks and Data Access : Language statements that define blocks : Data access without looping: the FIND statement : Using the FIND statement in a REPEAT block
Using the FIND statement in a REPEAT block
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:
1. You must do the FIND with the NO-ERROR qualifier at the end of the statement. This suppresses the error message that you would ordinarily get when there is no next Customer.
2. You must use the AVAILABLE keyword to check for the presence of a Customer and display fields only if it evaluates to TRUE.
3. You must write an ELSE statement to match the IF-THEN statement, 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. The IF-THEN statement ends with a period and the ELSE keyword 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.