Progress
Language Reference


PRESELECT Phrase

Interfaces
OS
SpeedScript
All
All
Yes

Specifies a set of records to preselect for a DO or REPEAT block.

SYNTAX

PRESELECT
  [ EACH | FIRST | LAST ] record-phrase
  [ , [ EACH | FIRST | LAST ] record-phrase ] ...
  [ [ BREAK ]
       { BY expression [ DESCENDING ]
          | COLLATE ( string , strength [ , collation ] ) [ DESCENDING ]
       } ...
  ] 

[ EACH | FIRST | LAST ] record-phrase

Goes through a table, selecting records that meet the criteria you specify in record-phrase. PRESELECT creates a temporary index that contains pointers to each of the preselected records in the database table. Then you can use other statements, such as FIND NEXT, within the block to process those records.

The record-phrase option identifies the criteria to use when preselecting records.

SYNTAX
{ record [ field-list ] }
[ constant ]
[ [ LEFT ] OUTER-JOIN ] 
[ OF table ]
[ WHERE expression ]
[ USE-INDEX index ] 
[ USING [ FRAME frame ] field
    [ AND [ FRAME frame ] field ] ...
]
[ SHARE-LOCK | EXCLUSIVE-LOCK | NO-LOCK ]
[ NO-PREFETCH ] 

Specifying multiple occurrences of record-phrase preselects the tables using an inner join. Also, any sorting you specify applies to all the tables. If you then do a FIND on the last table in the PRESELECT list, Progress reads records into the buffers for all of the tables in the list.

For more information on record-phrase and inner joins, see the Record Phrase reference entry.

BREAK

When used in combination with the FIRST function, LAST function, FIRST-OF function, and LAST-OF function, BREAK indicates that subgroups are used for aggregation. If you use BREAK, you must also use BY.

BY expression [ DESCENDING ]

Sorts the preselected records by the value of expression. If you do not use the BY option, PRESELECT sorts the records in order by the index used to extract the records. The DESCENDING option sorts the records in descending order as opposed to the default ascending order.

string

A CHARACTER expression that evaluates to the string whose collation value you want to compute.

strength

A CHARACTER expression that evaluates to one of the following:

collation

A CHARACTER expression that evaluates to the name of a collation table.

If collation does not appear, COLLATE uses the collation table of the client.

Progress reports an error and stops execution if one of the following occurs:

EXAMPLES

To process a multi-table collection gathered by the PRESELECT option, use the last table named in the collection when you want to read the selected records. Progress then automatically retrieves records from the other tables.

r-presl1.p
REPEAT PRESELECT EACH order, customer OF order, EACH order-line OF order
            BY order.order-date BY order.cust-num BY order-line.item-num:
   FIND NEXT order-line.
   DISPLAY order.order-date order.cust-num customer.name
           order-line.item-num.
END. 

The PRESELECT option in this example selects the logically joined record that consists of order, order-line, and customer, and makes all of these records available in the REPEAT block. Usually you perform more complex processing within the PRESELECT block.

If, within a PRESELECT block, you find a record using the ROWID of that record, Progress disregards any other selection criteria you applied to the PRESELECT. For example, suppose the ROWID of order number 4 is stored in the variable ord-rowid.

DO PRESELECT EACH order WHERE order-num > 5:
  FIND FIRST order WHERE ROWID(order) = ord-rowid.
  DISPLAY order.
END. 

In this example, Progress finds and displays order number 4 even though the selection criteria specifies that the order number must be greater than 5. The ROWID always overrides other selection criteria. Furthermore, if you use FIND...WHERE ROWID(record) =..., the index cursor is not reset in the preselected list. That is, even if record ROWID(record) is in the preselected list, FIND NEXT does not find the record that follows it in the preselected list.

NOTE

The COLLATE option computes the collation value of a string after applying a particular “strength” (RAW, CASE-SENSITIVE, or CASE-INSENSITIVE) and, optionally, a particular collation table.

SEE ALSO

DEFINE BUFFER Statement, DO Statement, FIND Statement, REPEAT Statement


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