Topic group Related topics Example
Searches a field for a specified expression and, if the expression is found, returns the value of a field within the same record.
LOOKUP(<return field>, <exp>, <lookup field>)
The field whose value you want to return if a match is found.
The expression to look for in the <lookup field>. Specify an alias when referring to fields outside the current work area.
The field you want to search for the value <exp>.
The <return field> and <lookup field> are usually fields in the same table, a table that is not in the current work area. Use the alias name and alias operator (->) to reference fields in other tables.
LOOKUP( ) looks for the first record where <lookup field> matches the specified expression <exp>. The record pointer is left at the matching record. If no match is found, the record pointer is left at the end-of-file. Either way, LOOKUP( ) then returns the value of <return field>.
Therefore, if no match is found, LOOKUP( ) returns the blank value for that field, either an empty string (""), zero, a blank date, or false, depending on the data type of <lookup field>. Calling FOUND( ) will also return true or false to indicate if the search was successful.
LOOKUP( ) performs a sequential search, unless an index whose key matches <lookup field> is available in the lookup table. To minimize the time LOOKUP( ) takes to search a table, you should create index keys for your most common lookups.
Because LOOKUP( ) moves the record pointer you can perform a lookup with related tables, where the <lookup field> is in the parent table, and <return field> is in the child table.