# Steps to Define a Key-field Lookup

Lookup Wizard | Position cursor on an empty "Then" line and press the Define Lookup key (F5, Ctl-R). (You can write the statement on the processing line yourself, by NOT pressing the Lookup wizard key.)
Select Lookup File | "Lookup From File:" Name of the other file, the lookup file.
"Name Of Lookup Is?" | You can give a shorter "alias" to this lookup filename.
"How Is The Record To Be Found?" | K Key Field, R Record Number, F Free Record, Z Fuzzy Search You are cross-referencing the files based on a key field. The key field in the current file has a corresponding field in the lookup file on which an index is built.
"What Index Is To Be Used?" | A-P or 0-9, must be built on the corresponding field in the lookup file.
"What Field In 'current filename' Contains The key:" | The field that contains the data that can be used to reference the correct record in the lookup file.
Lookup Match Criteria | X Key Must Match Exactly G Use Next Greater Match L Use Next Lower Match When you pick the "less than" or "greater than" modes, the program looks for an exact match first. If it finds no exact match, it selects a value just less or greater than the one requested.
Lookup Fail Action | B Blank The Field N Do Nothing E Report An Error B Allows the user to fill in and save despite incomplete entries in the lookup file. When data cannot be looked up from the lookup file, the program puts blanks in the affected fields. N The lookup filename holds a true/false value for the success of the lookup and this can be used for testing. This allows you to maintain control of the failure yourself. (i.e., put up a message like "Product not on file, do you want to add it?") E Displays the message "Lookup Failed - Try Again". Then it returns you to the update mode in the field where the lookup failed (the key field) In automatic processing with E flag, the error is displayed before the record appears, but you can't get into the record to change the problem. Do not use E on automatic processing tables. In when-field processing, you cannot use the -E flag. In output processing, the -E flag halts the processing and kicks you out. Do not use E on output processing tables.
Create Browse Lookup? | This allows you to build elaborate row-oriented display lookups. You are returned to the processing table. The lookup statement is now written on the "Then" line.

Handling Lookup Failure

Definition

The lookup fails if no match is found in the "lookup" file. The lookup filename will "hold" the success or failure of the lookup. You must tell the program what to do.

Sample

If: not filename
Then: s how "@Not on file, try again.";goto again

Making Field Assignments

Once the lockup file and record(s) are specified, you must tell the program how the data is to be used. Usually, this means "assigning" the lookup fields to fields in the current file. This just means setting the fields in this file equal to the ones you found in the lookup file (or vice versa). Result fields ALWAYS go to the LEFT of the equal sign. Make sure the edit types of the two fields match.

You can make assignments in either direction once you have done a lookup. You can change things in the lookup file or change things in the current file.

Receive - Data is received into the current file from the lookup file

| x=filename(n)
|  | filename is the name of the lookup file
|  | x is the field in the current file which receives the data
|  | n is the field in the lookup file that contains the looked-up data

Send - data is posted from the current file into the lookup file.

| filename(n)=x
|  | filename is the name of the lookup file
|  | n is the field in the lookup file to which data is sent
|  | x is the field in the current file that contains the data to be sent