Try OpenEdge Now
skip to main content
ABL Essentials
Using Queries : Defining and using queries : GET statements : Using the QUERY-OFF-END function
 
Using the QUERY-OFF-END function
There is a built-in ABL function that you can use for the same purpose as the AVAILABLE statement:
QUERY-OFF-END ( query-name ).
QUERY-OFF-END is a logical function that returns TRUE if the query is positioned either before the first result set row or after the last row, and FALSE if it is positioned directly on any row in the result set. The query-name parameter must be either a quoted literal string with the name of the query or a variable name that has been set to the name of the query. In this way, you can use the statement programmatically to test potentially multiple different active queries in your procedure.
For example, here is the same procedure used previously, this time with the QUERY-OFF-END function in place of AVAILABLE:
DEFINE VARIABLE iCount AS INTEGER NO-UNDO.

DEFINE QUERY CustOrd FOR Customer, Order.

OPEN QUERY CustOrd FOR EACH Customer, EACH Order OF Customer.
GET FIRST CustOrd.

DO WHILE NOT QUERY-OFF-END('CustOrd'):
  iCount = iCount + 1.
  GET NEXT CustOrd.
END.
DISPLAY iCount.
The difference between QUERY-OFF-END and AVAILABLE is simply that AVAILABLE requires a buffer name as a parameter, whereas QUERY-OFF-END requires a query name. If you use the AVAILABLE function with the name of the first buffer in the query, it is equivalent to using QUERY-OFF-END with the query name. Just for stylistic reasons, it is more appropriate to use the QUERY-OFF-END function in most cases, since it is the position of the query and not the presence of a record in a particular buffer that you're really interested in. By contrast, if you really want to test for the presence of a record, especially when your query does an outer join that might not always retrieve a record into every buffer, then use the AVAILABLE function.