Commands and Statements

Statement FIELD Foundation

Declares variables of the storage class FIELD.

Syntax
FIELD <FieldName,...> [IN <AliasName>]
Parameters
<FieldName,...>
<FieldName,...> is a comma separated list of field names.
<AliasName>
<AliasName> designates the alias of the work area to be implied when the field name is not prefaced by the alias and alias operator in the code.
Description

The FIELD statement declares variables whose contents are stored in a database file. By using the optional alias name, the compiler can resolve assignments for fields that are referenced without an alias name and alias operator in the source code. The alias name <AliasName>is used to resolve references to fields that are not explicitly aliased. The FIELD statement only affects the listed fields, and has no affect on macro expressions at runtime.

The maximum length of the variable name in <FieldName,...> is dependent on the actual database engine (DBE). With the DBFDBE, the maximum length for field names is 10 characters.

The FIELD statement must precede executable statements in the procedures or functions in which it is used. Its scope is the function or procedure in which it occurs. When the FIELD statement is placed at the beginning of the source code file, giving it filewide scope, it must precede all executable statements. The FIELD statement does not open any file, nor does it test for the existence of the fields. Referencing a field variable when the file is not in use at runtime causes a runtime error.

The FIELD statement allows for the correct referencing of variables without alias identifiers at compile time, which are declared neither as LOCAL, STATIC nor MEMVAR. The /W compiler switch causes warning messages for ambiguous (undeclared) variables.

Examples
FIELD statement usage
// In the example, field variables from two different 
// work areas are declared with the FIELD statement. The matching 
// files are opened and names of customers are output to a file 
// with "?". Only the customers who have not paid a bill are 
// listed. The billing file is linked to the customer file with the SET 
// RELATION command. 

PROCEDURE Main 
   FIELD CustNr, Last_name, First_name IN Cust 
   FIELD BillNr, Payment IN Bill 

   USE Customer ALIAS Cust NEW 
   INDEX ON CustNr TO CustA 

   USE Billing ALIAS Bill NEW 
   SET RELATION TO CustNr INTO Cust 
   GO TOP 

   SET ALTERNATE TO "PastDue" 
   SET ALTERNATE ON 

   DO WHILE .NOT. Eof() 
      IF Payment == 0 
         ? Last_name, First_name, CustNr, BillNr 
      ENDIF 
      SKIP 
   ENDDO 

   SET ALTERNATE TO 
   CLOSE ALL 
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.