You are here: Commands > Define Field

Define Field

Use the Define Field command to create a field in Analyzer.

This command can be issued only in command mode. For more information, see Issuing Commands.

Define Field lets you add a field to your table layout. You can only define computed fields within a procedure. Computed fields form part of the table layout.

If a field with the same name already exists, Analyzer asks for confirmation before replacing it. Analyzer does not let you redefine a field if it is referenced by a computed field or by the current View.

Fields can contain overlapping data types. For example, you can define bytes 1 to 10 as a numeric data type. You can then define the same or part of the same area, for example, bytes 5 to 9, as an ASCII data type.

Note: For a more powerful and convenient way to define fields, use the Table Layout window as described in Defining Physical Data Fields and Computed Fields . Use these techniques whenever possible.

Field Modifiers

In addition to the command parameters described below, the Define Field command supports the following field modifiers: As, If, Picture, Width. For a description of these parameters, see Command Parameters. For a description of supported field modifiers see Field Modifiers.

Computed

Identifies the field being defined as a computed field.

Command Mode Syntax

Data Fields

You must include the entire data field definition in a single command line. You cannot have Analyzer prompt you for parameters.

DEFINE FIELD field-name field-type start-position field-length <decimals|date format> <AS "alternate column title"> <WIDTH> <PIC "format">¿

An example of defining a new data field is:

DEFINE FIELD InvNum ASCII 1 6

This defines a new ASCII field containing invoice numbers called InvNum with a start position of byte 1 and a length of 6 bytes.

Computed Fields

You can manually define computed fields within a procedure. The syntax for defining computed fields requires parameters to be entered on multiple lines. Because the command line does not support multi-line commands, you must use this command in procedures to create computed fields.

In the syntax examples below, the carriage return symbol (¿) marks the end of each line of multi-line text. Do not enter a carriage return except where indicated by the carriage return symbol. If you enter a carriage return before the end of the line, the command will not work.

Single-Value Computed Field

A single value computed field can be created as a single line (with no descriptive information) or as multiple lines (with descriptive information). For a single value multi-line computed field, always put the expression on the third line. Leave the second line blank if you are not including descriptive information such as an IF condition, a static modifier, a field description or an AS, WIDTH or PIC clause.

DEFINE FIELD field-name COMPUTED expression¿

or

DEFINE FIELD field-name COMPUTED¿

<AS field-description> <WIDTH number> <PIC format> <IF condition> <STATIC>¿

expression¿

Examples of defining a new single-value computed field are:

DEFINE FIELD VALUE COMPUTED COST*QUANTITY AS “Cost Value”¿

or

DEFINE FIELD VALUE COMPUTED¿

AS “Cost Value”¿

COST*QUANTITY¿

Either of these examples defines a new computed field called Value that is the product of the Cost field multiplied by the Quantity field.

Multi-Value Computed Field

Always put the first condition and value pair on the third line. Leave the second line blank if not including any optional conditions, modifiers, descriptions or clauses.

DEFINE FIELD field-name COMPUTED¿

<AS field-description> <WIDTH> <PIC format> <IF condition> <STATIC>¿

<value IF condition>¿

<value IF condition>¿

default-value¿

An example of defining a multi-value computed field is:

DEFINE FIELD State-Name COMPUTED¿

¿

"Alaska" IF state = "AK"¿

"California" IF state = "CA"¿

"Not a valid State"¿

This defines a new computed field called State-Name provides the correct state name based on abbreviations found in the State field.

Field Parameters

field-name can contain up to 127 upper case and lower case alphanumeric characters, including the underscore character (_). Fill blanks between multi-word names with an underscore. Analyzer automatically inserts underscores between words in a dialog.
field-type identifies the appropriate field type. See Field Types.
start-position identifies the first byte position counting from 1 and going from left to right of the field being defined.
field-length specifies the length in bytes of the field being defined.
decimals applies only to numeric field types. Identifies the number of decimal places to the right of any decimal point.
expression can be any valid Analyzer expression. See Expressions - Examples for details.
condition specifies the condition that must be met.
STATIC allows you to treat the field as a static field. See Conditional Data Fields for details.
field-description specifies the value of the alternate column title.
value specifies a valid Analyzer expression based on the condition.
default-value specifies a valid Analyzer expression if none of the conditions is met.