Constrains the records in a table to those whose key field values falls within a range.

Syntax

SET KEY TO
 [ <exp1> | <exp list 1> |
 RANGE
  <exp2> [,] | ,<exp3> | <exp2>, <exp 3>
  [EXCLUDE] |
 LOW <exp list 2>] [HIGH <exp list 3>]
  [EXCLUDE] ]
[IN <alias>]

<exp1>

Shows only those records whose key value matches <exp 1>.

<exp list 1>

For tables indexed on a composite (multi-field) key index, shows only those records whose key field values match the corresponding values in <exp list 1>, separated by commas.

RANGE <exp2> [,] | ,<exp3> | <exp2>, <exp3>
LOW <exp list 2> HIGH <exp list 3>

Shows only those records whose key values fall within a range. Use RANGE for single key values and LOW/HIGH for composite keys. You may use either the RANGE clause or LOW/HIGH, but not both in the same command. The following table summarizes how SET KEY constrains records in the master index:

Option

Description

RANGE <exp2> [,]
LOW <exp list 2>

Shows only those records whose key values are greater than or equal to <exp2>/<exp list 2>

 

RANGE , <exp3>
HIGH <exp list 3>

Shows only those records whose key values are less than or equal to <exp3>/<exp list 3>

 

RANGE <exp2>, <exp3>
LOW <exp list 2> HIGH <exp list 3>

Shows only those records whose key values are greater than or equal to <exp2>/<exp list 2> and less than or equal to <exp3>/<exp list 3>

EXCLUDE

Excludes records whose key values are equal to <exp2>/<exp list 2> or <exp3>/<exp list 3>. If omitted, these records are included in the range.

IN <alias>

The work area in which to set the key constraint.

Description

SET KEY TO is similar to SET FILTER; SET KEY TO uses the table’s current master index and shows only those records whose key value matches a single value or falls within a range of values. This is referred to as a key constraint. Because it uses an index, a key constraint is instantaneous, while a filter condition must be evaluated for each record. SET KEY TO with no arguments removes any range of key values previously established for the current table with SET KEY TO.

The key range values must match the key expression of the master index. For example, if the index key is UPPER(Name), specify uppercase letters in the range expressions. In determining whether the specified range expressions match key field expressions, SET KEY TO follows the rules established by SET EXACT. The SET KEY TO range takes effect after you move the record pointer.

When you issue both SET KEY and SET FILTER for the same table, dBASE Plus processes only records that are within the SET KEY index range and that also meet the SET FILTER condition.

OODML

Use the Rowset object’s setRange( ) method.