Kbase P58230: How to modify a browse's query at runtime
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  5/1/2006 |
|
Status: Verified
GOAL:
How to modify a browse's query at runtime
GOAL:
How to change the sort order of a browse based on user input
GOAL:
How to filter the data in a browse
FACT(s) (Environment):
Progress 9.x
FIX:
To do this, the underlying query of the browse should be reopened with the appropriate WHERE clauses and BY phrases.
In Progress version 9 and later releases, this can be done by obtaining the handle of the query (hHandle = BROWSE <browse-name>:QUERY), and invoking the QUERY-PREPARE() and QUERY-OPEN() methods on it.
The QUERY-PREPARE() method will accept the query predicate - this is a character string that looks like an OPEN QUERY <query-name> FOR EACH .... , but without the OPEN QUERY <query-name> part.
The QUERY-OPEN() method will actually reopen the query according to the new predicate.
A small example (using sports database):
DEFINE QUERY cust FOR customer.
DEFINE BROWSE cust QUERY cust
DISPLAY customer.cust-num customer.name
WITH 6 DOWN.
DEFINE VARIABLE byName AS LOGICAL NO-UNDO VIEW-AS TOGGLE-BOX.
DEFINE VARIABLE firstOnly AS LOGICAL NO-UNDO VIEW-AS TOGGLE-BOX.
OPEN QUERY cust FOR EACH customer NO-LOCK.
ENABLE byName firstOnly cust WITH FRAME X.
ON 'value-changed':U OF byName, firstOnly
DO:
DEFINE VARIABLE hQuery AS HANDLE NO-UNDO.
DEFINE VARIABLE cQuerystring AS CHARACTER NO-UNDO.
/* building the Query predicate string */
cQuerystring = "FOR EACH customer NO-LOCK ".
IF firstOnly:CHECKED THEN cQuerystring = cQuerystring + "WHERE cust-num = 1 ".
IF byName:CHECKED THEN cQuerystring = cQuerystring + "BY name ".
/* prepare & reopen query */
hQuery = BROWSE cust:QUERY.
hQuery:QUERY-PREPARE(cQueryString).
hQuery:QUERY-OPEN().
DISPLAY cQuerystring NO-LABEL VIEW-AS EDITOR SIZE 60 BY 2 WITH FRAME X.
END.
WAIT-FOR GO OF THIS-PROCEDURE.