Progress
Language Tutorial
for Windows


Query and Selection Programming Example

This example demonstrates selecting records with a defined query:

  1. Open lt-09-01.p and run it.
  2. Choose the first Query button. The following browse widget appears with the results of the query. In the status area, notice the message that shows the selection syntax used in the particular OPEN QUERY statement:
  3. Choose the second and third Query buttons.
  4. Choose the fourth Query button. This example uses the USING option, so you have to provide a value to search for. A dialog box appears to prompt you for the Item-Num.
  5. Type an integer from 1 to 55, then choose OK. The browse widget displays the results.
  6. Choose Exit, then press SPACEBAR to return to the Procedure Editor.

Here is the code that created the display:

lt-09-01.p
      /**********  DEFINE QUERIES  **********/
/*1*/  DEFINE QUERY New-Query FOR Item 
          FIELDS (Item-Num Item-Name price).
      /**********  DEFINE WIDGETS  **********/
/*2*/  DEFINE BROWSE New-Browse QUERY New-Query
      DISPLAY Item-Num Item-Name Price WITH 22 DOWN.
      DEFINE BUTTON btn-Q1 LABEL "WHERE Expression Query".
      DEFINE BUTTON btn-Q2 LABEL "WHERE BEGINS Query".
      DEFINE BUTTON btn-Q3 LABEL "WHERE MATCHES Query".
      DEFINE BUTTON btn-Q4 LABEL "USING Item-Num Query".
      DEFINE BUTTON btn-OK LABEL "OK" AUTO-GO.
      DEFINE BUTTON btn-Cancel LABEL "Cancel" AUTO-ENDKEY.
      DEFINE BUTTON btn-Exit LABEL "Exit".
      /**********  DEFINE FRAMES  **********/
      DEFINE FRAME Frame1 
        SKIP(1) btn-Q1 COLON 48 SPACE(2) SKIP(1) btn-Q2 COLON 48 SKIP(1) 
        btn-Q3 COLON 48 SKIP(1) btn-Q4 COLON 48 SKIP(2) btn-Exit COLON 48
        New-Browse AT ROW 2 COLUMN 2 SKIP(1)
          WITH TITLE "Query Results" AT ROW 2 COLUMN 2.
    /**********  DEFINE TRIGGERS  **********/
      ON CHOOSE OF btn-Q1
       DO:
/*3*/        OPEN QUERY New-Query FOR EACH Item WHERE Item-Num > 45.
            DISPLAY New-Browse WITH FRAME Frame1.
            MESSAGE "FOR EACH Item WHERE Item-Num > 45".END.
      ON CHOOSE OF btn-Q2
       DO:
/*4*/        OPEN QUERY New-Query FOR EACH Item 
               WHERE Item-Name BEGINS "ski".
            DISPLAY New-Browse WITH FRAME Frame1.
            MESSAGE "FOR EACH Item WHERE Item-Name BEGINS ""ski""".END.
      ON CHOOSE OF btn-Q3
       DO:
/*5*/  OPEN QUERY New-Query FOR EACH Item WHERE Item-Name MATCHES "*ball".
         DISPLAY New-Browse WITH FRAME Frame1.
        MESSAGE "FOR EACH Item WHERE Item-Name MATCHES ""*ball""".END.
      ON CHOOSE OF btn-Q4
       DO:
         PROMPT-FOR Item.Item-Num SKIP btn-OK btn-Cancel
              WITH FRAME Frame3 VIEW-AS DIALOG-BOX TITLE "New Query".
/*6*/        OPEN QUERY New-Query FOR EACH Item USING Item-Num.
          DISPLAY New-Browse WITH FRAME Frame1.
          MESSAGE "FOR EACH Item USING Item-Num". END.
      /**********  MAIN LOGIC  **********/
      ENABLE ALL WITH FRAME Frame1.
      WAIT-FOR CHOOSE OF btn-Exit. 

NOTE: The THREE-D option is relevant only on a Windows client; it is ignored by a character client.

These notes help explain the code, describing how to query and use the browse widgets:

  1. Even though the procedure makes several queries, each query uses the same table (Item) and only one query is active at a time. Therefore, you need only one defined query.
  2. Similarly, although the procedure uses the browse widget to display several queries, only one is displayed at a time.
  3. The first query uses a WHERE expression to display all the inventory items with item numbers greater than 45.
  4. The second query uses a WHERE BEGINS query to list all the items with names that begin with "ski".
  5. The third query uses a WHERE MATCHES query to see if any of the item names end with "ball".
  6. The fourth query uses the USING option to allow the user to define the query. The USING item accepts a screen value for a table field, then finds the records that have that value.

Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095