PreviousNextIndex

DEFINE QUERY statement

Defines a query that is created at compile time for use in one or more procedures, or within a single class or class hierarchy. A query can be opened with an OPEN QUERY statement, and records can be retrieved using a GET statement, BROWSE widget, or the FILL( ) method on a ProDataSet object handle.

Syntax

DEFINE { [ [ NEW ] SHARED ] | [ PRIVATE | PROTECTED ] [ STATIC ] } 
  QUERY query 
  FOR buffer-name [ field-list ] [ , buffer-name [ field-list ] ] ... 
  [ CACHE n ] 
  [ SCROLLING ] 
  [ RCODE-INFORMATION ] 

NEW SHARED QUERY query
SHARED QUERY query
[ PRIVATE | PROTECTED ] [ STATIC ] QUERY query
QUERY query
FOR buffer-name [ field-list ] [ , buffer-name [ field-list ] ] ...
CACHE n
SCROLLING
RCODE-INFORMATION
Note: This option is the default behavior (thus, it has no effect). It is supported only for backward compatibility.
Examples

The following example defines two queries, q-salesrep and q-cust. The first is opened in the main procedure block and is used to find all SalesRep records. The q-cust query is used to find all Customers associated with a SalesRep. The results of the q-cust query are displayed in a browse widget. The q-cust query is reopened each time you find a new SalesRep.

r-defqry.p
DEFINE QUERY q-salesrep FOR SalesRep  
  FIELDS(SalesRep RepName Region MonthQuota). 
DEFINE QUERY q-cust FOR Customer 
  FIELDS(CustNum Name Phone). 
DEFINE BROWSE cust-brws QUERY q-cust 
  DISPLAY Customer.CustNum Customer.Name Customer.Phone 
    WITH 5 DOWN TITLE "Customer Information". 
DEFINE BUTTON b_next LABEL "Next". 
DEFINE BUTTON b_quit LABEL "Quit" AUTO-ENDKEY. 
FORM 
  SalesRep.SalesRep SalesRep.RepName SalesRep.Region SaleRep.MonthQuota 
  WITH FRAME rep-info SIDE-LABELS TITLE "Sales Rep. Info". 
FORM b_next space(5) b_quit  
  WITH FRAME butt-frame COLUMN 60. 
ON CHOOSE OF b_next DO: 
  GET NEXT q-salesrep. 
  IF NOT AVAILABLE SalesRep THEN GET FIRST q-salesrep. 
  RUN disp-rep. 
END. 
OPEN QUERY q-salesrep FOR EACH SalesRep NO-LOCK. 
GET FIRST q-salesrep. 
RUN disp-rep. 
ENABLE cust-brws WITH FRAME cust-info. 
ENABLE ALL WITH FRAME butt-frame. 
   
WAIT-FOR WINDOW-CLOSE OF CURRENT-WINDOW. 
PROCEDURE disp-rep: 
  DISPLAY SalesRep.SalesRep Salesrep.RepName SalesRep.Region 
    SalesRep.MonthQuota 
    WITH FRAME rep-info CENTERED SIDE-LABELS TITLE "Sales Rep. Info". 
  OPEN QUERY q-cust FOR EACH Customer OF SalesRep NO-LOCK. 
END PROCEDURE. 

Notes
See also

Class-based data member access, CLOSE QUERY statement, CREATE QUERY statement, CURRENT-RESULT-ROW function, DEFINE BROWSE statement, DEFINE DATASET statement, GET statement, NUM-RESULTS function, OPEN QUERY statement, REPOSITION statement, RUN statement


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex