Try OpenEdge Now
skip to main content
ABL Essentials
Procedure Blocks and Data Access : Language statements that define blocks : FOR blocks
 

FOR blocks

You're already familiar with starting a block definition with the FOR keyword. You've seen the common FOR EACH table-name form, but there are a number of variations on the FOR statement. In contrast to the DO block, every FOR block provides all of the following services for you automatically:
*Loops automatically through all the records that satisfy the record set definition in the block
*Reads the next record from the result set for you as it iterates
*Scopes those records to the block
*Scopes a frame to the block, and you can use the WITH FRAME phrase to specify that frame
*Provides database update services within a transaction
The FOR statement defines the set of records you want the block to iterate through. Typically you use the EACH keyword to specify this set:
FOR EACH Customer NO-LOCK WHERE Customer.State = "NH":
  DISPLAY Customer.CustNum Customer.Name.
END.
When the block begins, the AVM evaluates the expression and retrieves the first record that satisfies it. This record is scoped to the entire block. Each time the block iterates, the AVM retrieves the next matching record and makes it available to the rest of the block. When the set of matching records is exhausted, the AVM automatically terminates the block. You don't have to add any checks or special syntax to exit the block at this point.
* Sorting records by using the BY phrase
* Joining tables using multiple FOR phrases
* Alternatives to the EACH keyword
* Using indexes to relate and sort data
* Using the USE-INDEX phrase to force a retrieval order
* Using the LEAVE statement to leave a block
* Using block headers to identify blocks
* Using NEXT, STOP, and QUIT to change block behavior
* Qualifying a FOR statement with a frame reference