xHarbour Reference Documentation > Statement Reference |
Declares a field variable
FIELD <fieldName,...> [IN <aliasName>]
The FIELD statement declares symbolic names of variables whose values are stored in database files. This instructs the compiler to resolve unaliased variable names to field variables, not memory variables. All variables listed in <fieldNames,...> that appear in program code without alias name and alias operator, are treated as if they are listed with the FIELD-> alias name, or the one specified with the IN clause.
The FIELD statement does not verify if the field variables exist at runtime or if a database is open with <aliasName> as name. When the declared field variable does not exist at runtime, an error is generated.
The scope of the FIELD variable depends on the place of declaration:
1. | When the FIELD declaration appears at the top of a PRG file before any other executable statement, the declaration has file wide scope, i.e. it is valid throughout the entire PRG file. |
2. | When the FIELD declaration follows a FUNCTION, METHOD or PROCEDURE declaration, the variable is treated as FIELD variable only in the routine that declares the FIELD. |
The lines in PRG source code preceding the FIELD declaration may not call executable code. They can only contain declaration statements, i.e. only the FUNCTION, METHOD, PROCEDURE statements, and the LOCAL, MEMVAR, PARAMETERS, or STATIC variable declarations are allowed to precede the FIELD statement.
See also: | FUNCTION, GLOBAL, LOCAL, MEMVAR, PROCEDURE, STATIC |
Category: | Declaration , Statements |
PROCEDURE Main FIELD InvoiceNo, AmountDue, Payment IN Inv FIELD CustNo , FirstName, LastName IN Cust USE Customer ALIAS Cust SHARED INDEX ON CustNo TO CustA USE Invoice ALIAS Inv SHARED NEW SET RELATION TO CustNo INTO Cust GO TOP SET ALTERNATE TO NotPaid.txt SET ALTERNATE ON DO WHILE .NOT. Eof() IF Payment == 0 ? CustNo, Lastname, FirstName, InvoiceNo, AmountDue ENDIF SKIP ENDDO SET ALTERNATE TO DbCloseAll() RETURN
http://www.xHarbour.com