Function OrdKey() Foundation

Returns the index expression of an index.

Syntax
OrdKey( [<cTagName>|<nIndex>] ) --> cIndexKey
Parameters
<cTagName>
<cTagName> is a character string specifying the name of the index whose index expression is returned. <cTagName> is comparable to the alias name of a work area.
<nIndex>
<nIndex> is a positive integer specifying the ordinal position within the work area of the index whose index expression is to be returned. The indexes are numbered in the order that they were opened using OrdListAdd() or SET INDEX TO.
Return

The return value of OrdKey() is a character string containing the index expression (index key) used to create the index. If no index file is open, the function returns a null string (""). If no value is specified for <nIndex> or <cTagName>, the index expression of the controlling index is returned.

Description

The index function OrdKey() determines the index key expression of an open index in a work area. When the function is used without the alias operator, it returns an index expression from the current work area. The index can be specified by a numeric value or by its name.

The ability to manage several indexes within an index file depends on whether the active database engine (DBE) can support multiple indexes. If the current DBE does not support multiple indices, a recoverable runtime error occurs.

Knowing the index expression of the controlling index is important for data input routines. When data input changes the logical record order of a DBF file, the screen must be refreshed following the input. This is generally required when data is displayed in BROWSE mode. The function OrdKey() allows the index expression and its current value to be recorded before and after data input. If the index value after input differs from the index value before input, the screen display must be refreshed.

Examples
OrdKey()
// In the example, two indexes are created for a customer file 
// and the return values of OrdKey() are shown. 

PROCEDURE Main 
   USE Customer NEW EXCLUSIVE 

   INDEX ON CUSTNO ; 
        TAG C_Number ; 
         TO CustA 

   INDEX ON Upper(LASTNAME+FIRSTNAME) ; 
        TAG C_LastName ; 
         TO CustB 

   SET INDEX TO CustA, CustB 

   ? OrdNumber()              // result: 1 

   ? OrdKey(0)                // result: CUSTNO 
   ? OrdKey(1)                // result: CUSTNO 
   ? OrdKey(2)                // result: Upper(LASTNAME+FIRSTNAME) 

   ? OrdKey("C_Number")       // result: CUSTNO 
   ? OrdKey("C_LastName")     // result: Upper(LASTNAME+FIRSTNAME) 

   CLOSE Customer 
RETURN 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.