:DEFINE
Script Statement: Defines a variable and declares the data type of the variable.
Syntax
:D[EFINE] Script variable, data type [, array size]
Syntax |
Description/Format |
---|---|
Script variable |
The name of the script variable that is created together with a data type. You must always use an ampersand symbol (&) that precedes the script variable's name, and it is recommended that you use a hash (#) symbol to signal the end of the variable's name. The length of a script variable's name is limited to 32 characters. All characters of the alphabet, the numbers 0-9, and the following special characters can be used:"$", "_", "@", "ยง" and "#". German Umlauts are not allowed. The first character after the leading "&", which is not part of the 32-character limit, must neither be a number nor a "$" symbol. For more details about the syntax, see Syntax. Format: script variable |
Data type |
The data type of the defined script variable. Allowed values: "unsigned", "string", "float" or "signed" unsigned: positive integers without signs |
Array size |
If this script variable should be generated as an array, you use this parameter to define its size.
Allowed values: |
Comments
You can directly create script variables by using the script element :SET and assign the required value when you use the data types "string" or "unsigned". In this case, the data type is automatically retrieved via the specified value. A scripting error occurs if a floating point number or a negative number has been specified.
Important!
- Directly assigning the value of a different data type is only possible for script variables that have been created by using :SET and only with positive integers and strings.
- If you assign a value to a script variable that lies outside of the range of its data type, the value will be converted to the target data type automatically.
- Using the script element :DEFINE without a data type or with a data type that is invalid results in a scripting error.
The following value ranges are available for the different data types:
Data Type | Value Range |
---|---|
unsigned | 0 to +9 999 999 999 999 999 |
signed | -9 999 999 999 999 999 to +9 999 999 999 999 999 |
string | Alphanumeric string with arbitrary length. |
float | -9 999 999 999 999 999.9999999999999999 to +9 999 999 999 999 999.9999999999999999 |
The following value ranges are different for Sun Solaris operating system. They are:
Data Type | Value Range |
---|---|
unsigned |
0 to +9 999 999 999 999 998 |
signed | -9 999 999 999 999 998 to +9 999 999 999 999 998 |
float | -9 999 999 999 999 998.9999999999999999 to +9 999 999 999 999 998.9999999999999999 |
Use the parameter Array size to have the script variable generated as an array with a defined length. The size must not exceed the value 99999. No square brackets [] are required for the array declaration. For further details, see Arrays .
Use the script statement :FILL to fill script arrays with several different values.
Examples
Declaration of several variables with different data types and subsequent value assignment:
:DEFINE &a#, unsigned
:DEFINE &b#, signed
:DEFINE &c#, float
:DEFINE &d#, string
:SET &a# = 12
:SET &b# = -5
:SET &c# = 0.50
:SET &d# = "string"
The following example converts the data type of the variable's value automatically:
:DEFINE &unsigned#, unsigned
:DEFINE &string#, signed
:SET &unsigned# = 12
:SET &string# = &unsigned#
The following example shows a valid assignment because the variable "&unsigned#" is converted to the correct data type via the function CONVERT:
:DEFINE &unsigned#, unsigned
:DEFINE &string#, signed
:SET &unsigned# = 12
:SET &string# = CONVERT(string,&unsigned#)
A direct value assignment with the data types "unsigned" and "string" is possible if a script variable is created by using the script element :SET.
:SET &setvar#= 12
:SET &setvar2#="string"
:SET &setvar# = &setvar2#
The last example shows how to create and fill an array.
:DEFINE &array#, unsigned, 5
:FILL &array#[] = GET_VAR(VARA1, ARRAY)
The following example rounds the result of the arithmetic operation 3.0 - 0.1 into a string, using the script function FORMAT while taking a common arithmetical error Epsilon = 0.0000005 and one decimal place into account.
:DEFINE &SCRIPT_VERSION_ORIG#, float
:DEFINE &SCRIPT_VERSION_ORIG1#, float
:DEFINE &EPSILON#, float
:SET &SCRIPT_VERSION_ORIG# = 3.0
:SET &EPSILON# = 0.0000005
:P &SCRIPT_VERSION_ORIG#
:SET &SCRIPT_VERSION_ORIG# = &SCRIPT_VERSION_ORIG# - 0.1
:P BEFORE FORMAT: &SCRIPT_VERSION_ORIG#
:SET &SCRIPT_VERSION_ORIG# = &SCRIPT_VERSION_ORIG# + &EPSILON#
:SET &SCRIPT_VERSION_ORIG# = FORMAT(&SCRIPT_VERSION_ORIG#, "0.0")
:P AFTER FORMAT: &SCRIPT_VERSION_ORIG#
For details concerning the problem of representing floating-point numbers, see Floating-point numbers in the Automation Engine
See also:
Script Elements | Description |
---|---|
Stores a value in a script variable. |
Script Elements - Script Structure and Processing
About Scripts
Script Elements - Alphabetical Listing
Script Elements - Ordered by Function