Previous Next

CLOSE QUERY statement
Closes a query that was opened by a previous OPEN QUERY statement.
Syntax 
 
CLOSE QUERY query
query
The name of an open query.
Example 
The r-clsqry.p procedure defines a query, q-cust, which it shares with r-query.p. Each time you choose the Ascending, Descending, or CustNum button, the procedure opens a new query for q-cust. To do this, the procedure must first close an open query for each q-cust. Therefore, the CLOSE QUERY statement is used in the CHOOSE trigger for each of these buttons.
 
DEFINE NEW SHARED BUFFER x-cust FOR Customer.
DEFINE NEW SHARED QUERY  q-cust FOR x-cust.
 
DEFINE BUTTON b_quit LABEL "Quit"
  TRIGGERS:
    ON CHOOSE QUIT.
  END.
  
DEFINE BUTTON b_ascend  LABEL "Ascending".
DEFINE BUTTON b_descend LABEL "Descending".
DEFINE BUTTON b_num     LABEL "CustNum".
 
FORM b_ascend b_descend b_num b_quit
  WITH FRAME butt-frame ROW 1.
 
ON CHOOSE OF b_ascend DO:
  CLOSE QUERY q-cust.
  OPEN QUERY q-cust FOR EACH x-cust NO-LOCK BY x-cust.name.
  DISABLE ALL WITH FRAME butt-frame.
  RUN r-query.p.
END.
 
ON CHOOSE OF b_descend DO:
  CLOSE QUERY q-cust.
  OPEN QUERY q-cust FOR EACH x-cust NO-LOCK
    BY x-cust.name DESCENDING.
  DISABLE ALL WITH FRAME butt-frame.
  RUN r-query.p.
END.
 
ON CHOOSE OF b_num DO:
  CLOSE QUERY q-cust.
  OPEN QUERY q-cust FOR EACH x-cust NO-LOCK
    BY x-cust.CustNum.
  DISABLE ALL WITH FRAME butt-frame.
  RUN r-query.p.
END.
 
DO WHILE TRUE:
  ENABLE ALL WITH FRAME butt-frame.
  WAIT-FOR CHOOSE OF b_ascend, b_descend, b_num, b_quit.
END.
 
DEFINE SHARED BUFFER x-cust FOR Customer.
DEFINE SHARED QUERY  q-cust FOR x-cust.
 
GET FIRST q-cust.
 
DO WHILE AVAILABLE(x-cust):
  DISPLAY x-cust.name x-cust.custnum
    WITH FRAME cust-info CENTERED DOWN ROW 3 USE-TEXT.
  DOWN 1 WITH FRAME cust-info.
  GET NEXT q-cust.
END.
Notes 
*
*
*
After you close a query, you can reopen it with the OPEN QUERY statement. However, you cannot reuse the query’s buffers for a different table. For example, a buffer, buff1, is created for the customer table in a DEFINE QUERY or OPEN QUERY for the query, qry1. The query is run and closed. You cannot now DEFINE or OPEN qry1 with buff1 for the item table. You can reuse buffers with CREATE QUERY, but you must re‑run QUERY-PREPARE.
*
See also 
CURRENT-RESULT-ROW function, DEFINE QUERY statement, GET statement, NUM-RESULTS function, OPEN QUERY statement, REPOSITION statement

Previous Next
© 2013 Progress Software Corporation and/or its subsidiaries or affiliates.