Type
Procedural Command


Purpose
The define command is used to create a global or temporary variable. A variable is used to store a value such as a text string or a calculated result that can change during the processing of a script. By specifying the variable's name, the stored value can be used like any other value in a script.
The status of a variable can be global (denoted by the keyword global) or temporary (denoted by the keyword temp). A temporary variable maintains its value only during the current script. A global variable can pass its value from one script to another when several scripts are integrated within a Control Procedure. To pass a value from one script to another, a variable must be defined identically in each script.

Syntax
define [global|temp] "VARIABLE NAME" TYPE [LENGTH] .

Usage
The define command is followed by:
The status of the variable (global or temporary).
The name of the variable (enclosed in quotation marks).
The type of the variable (any field type except Choice, currency, or Yes/No, Sequenced ID, or Memo).
The length of the variable (optional, see below).
A period. The define command requires a concluding period.

If you do not specify temp or global in the define statement, DataEase automatically creates a temporary variable.
The length specifies the number of characters for Text and Numeric String variables. The default length is 25; you can specify any length up to 255 characters. Number variables are always 14 digits long. Date and Time variables are 8 characters long. The default length is used if you do not specify a length in the define command.

Note: You can define a variable as any field type except Choice, Dollar, or Yes/No.

Example
define temp "DISCOUNT" Number .
for RESERVATIONS with TOTAL DUE > 1500 ;
assign temp DISCOUNT :=
RESERVATIONS TOTAL DUE * 0.15 .
modify records
TOTALDUE := TOTAL DUE - temp DISCOUNT .
end

This script tells DataEase: (1) Create (define) a temporary variable called DISCOUNT in which to store a number while processing the current script, (2) find all the RESERVATIONS records that have a value greater than 1500 in the TOTAL DUE field, (3) give (assign) the DISCOUNT variable a value determined by multiplying the TOTAL DUE on each invoice by 15%, and (4) modify these RESERVATIONS records by subtracting the value of the DISCOUNT variable from the value in the TOTAL DUE field.