xHarbour Reference Documentation > Statement Reference xHarbour Developers Network  

FIELD

Declares a field variable

Syntax

FIELD <fieldName,...> [IN <aliasName>]

Arguments

FIELD <fieldNames,...>
This is a comma separated list of symbolic names identifying field variables.
IN <aliasName>
Optionally, the alias name of the work area that holds field variables can be specified.

Description

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.

Info

See also:FUNCTION, GLOBAL, LOCAL, MEMVAR, PROCEDURE, STATIC
Category: Declaration , Statements

Example

   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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe