Xbasic

LOOKUPC Function

Syntax

Output_String as C = LOOKUPC(C matchtype,A keyvalue,C result_expression,C tablename,C tagname)

Arguments

matchtype

A 1-character string that specifies which lookup table record should supply the value if more than one record matches the Key_Value. "F" = First "L" = Last "C" = Closest match. Closest match uses the first occurrence of the closest inexact match if an exact match does not exist, otherwise it uses the first occurrence of an exact match.

keyvalue

The value of a key to search for. The type of Key_Value must be the same as the type of the keys in the index specified by Index_Name.

result_expression

The name of a field in the Lookup_Table or a valid expression which may contain one or more fields.

tablename

The fully qualified name of a table. If you omit the drive and path, Alpha Anywhere searches the directory of the current database.

tagname

The name of an index in the index lookup table that may contain the Key_Value.

Description

Returns the value of a character expression in an external table.

Discussion

LOOKUPC() searches an external lookup table ( Lookup_Table ) for an indexed record matching the Key_Value, and returns the character value in Lookup_Expression from the matching record. Alpha Anywhere performs an indexed search of the Lookup_Table using the Index_Name index. Note : If a record with a matching Key_Value is not found, Alpha Anywhere returns a blank value.

Example 

Assume that the Invoice and Customer tables contain the following records and that the index, CUSTOMER_ID, exists on the CUST_ID field in Customer :

INVOICE

INV_NO

CUST_ID and INV_DATE

I007

C003 06/08/1993

I008

C005 01/23/1993

I009

C002 06/25/1993

I010

C004 06/25/1993

CUSTOMER

CUST_ID

LAST_NAME

C002

Peabody

C003

Rebo

C004

Mesner

C005

Feld

If the following expression defines a calculated field or global variable for the Invoice table, Alpha Anywhere returns the first name in the customer record that matches the current invoice record:

dim tn as C
tn = table.filename_get("customer")
? tn
= "c:\program files\a5v6\samples\webappserverdemo\Customer.Dbf"
? lookupc("F", CUST_ID, "LAST_NAME", tn, "CUSTOMER_ID")
= "Feld" ' if current invoice record is I008 (making CUST_ID = C005)

Note : You can use TABLE.FILENAME_GET()to get the fully qualified name of a table.

See Also