Try OpenEdge Now
skip to main content
ABL Essentials
Using Queries : Defining and using queries : OPEN and CLOSE QUERY statements : Sorting the query results
 
Sorting the query results
You can specify a BY phrase on your OPEN QUERY statement just as you can in a FOR EACH block. In this case, the AVM either uses an index to satisfy the sort order if possible or, if no index can allow the AVM to retrieve the data in the proper order, preselects and sorts all the query results before any data is made available to the application.
Over a series of query iterations, you might want to do some work based on whether the value of a certain field changes. This field defines a break group. For example, you might be accumulating some value, such as a total. In this example, the BREAK option is used to define Customer.State as the break group:
OPEN QUERY CustOrd FOR EACH Customer BREAK BY Customer.State NO-LOCK.
When using the BREAK option you must also use the BY option to name a sort field.
Note: To test whether a break group has changed, you can use the FIRST-OF( ) and LAST-OF( ) methods of the query object handle. For more information on the query object handle, see OpenEdge Development: ABL Reference.