Topic group Related topics
Indicates if a specified expression is found in an index.
KEYMATCH (<exp> [,<index number> [,<alias>]])
where <index number> is:
<index position expN> | [<.mdx filename expC>,] <tag expN>
The expression, of the same data type as the index, that you want to look for.
<index position expN>
The numeric position of the index in the list of open indexes for the table.
<.mdx filename expC>
The .MDX file that contains the index tag you want to check. The .MDX must be opened in the specified work area.
The numeric position of the index tag in the specified .MDX file.
The work area you want to check.
The KEYMATCH( ) function determines if a specified key expression is found in a particular index. KEYMATCH( ) returns true or false to indicate whether the specified expression was found. SET EXACT controls whether exact matches of character string data is required.
A primary use of the KEYMATCH( ) function is to check for duplicate values when adding records. Unlike SEEK( ), KEYMATCH( ) looks for a matching index value without moving the record pointer and disturbing the current state of the record buffer.
KEYMATCH( ) ignores the settings for SET FILTER and SET KEY TO, ensuring the integrity of data in a table even when you work with a subset of the table records. KEYMATCH( ) honors SET DELETED, so that when SET DELETED is ON, existing key values in records marked as deleted are ignored, as if those records did not exist.
If you specify only an expression (<exp>) whose value you want to match, KEYMATCH( ) searches the current master index for an index key with the same value.
To search indexes other than the current master index, you must specify the index by index position. There are two ways to do this:
By the index’s position in the list of open indexes. Index numbering is complicated if you have open .NDX indexes or open non-production .MDX files. For information on index numbering, see SET INDEX.
By an index tag’s position in an .MDX file. If you do not specify <.mdx filename expC>, the production .MDX is used.
Either way, it is often easier to reference an index tag by name by using the TAGNO( ) function to get the corresponding position number.