Caché MultiValue Basic Reference
User Variables
[Back] [Next]
   
Server:docs2
Instance:LATEST
User:UnknownUser
 
-
Go to:
Search:    

User-defined variables used for storing data values.
Description
A variable is a unique named entity used to store and retrieve a data value. The following are the available types of variables in Caché MVBasic:
Naming Conventions
The following are the naming conventions for local variables:
Be aware valid local variable names in MVBasic may not be valid in Caché ObjectScript. For example, in Caché ObjectScript all variable names that begin with a dollar ($) character are system-supplied special variables. For this reason, MVBasic local variable names containing punctuation characters should be avoided whenever possible.
You can use the Caché ObjectScript $ZNAME function to validate an MVBasic local variable name. If you specify $ZNAME(string,0,11), $ZNAME validates string using the MultiValue Basic naming conventions for local variables.
A global variable begins with the caret (^) character, indicating that it is a global variable. A global variable follows the Caché ObjectScript naming conventions, not the MultiValue variable naming conventions. For further details, see the Variables chapter of Using Caché ObjectScript.
A process-private global variable begins with the ^|| characters (or the ^|"^"| characters), indicating that it is a process-private global. The two syntactic forms are equivalent. A process-private global follows the Caché ObjectScript naming conventions, not the MultiValue variable naming conventions. For further details, see the Variables chapter of Using Caché ObjectScript.
Note that in D3 emulation, global variable names and process-private global variable names are case-sensitive, but local variable names are not case sensitive.
Assignment of Values
A variable is assigned a value by using the equal sign (=), as shown in the following examples. Spaces can be included or omitted before or after the equal sign.
x="fred"
y=+1234.5
z=x:y
A variable can be assigned multiple values as a dynamic array. For details on defining a dynamic array, refer to Dynamic Arrays.
Common Storage Areas
Caché MVBasic allows you to group user variables into common storage areas. This permits you to set, limit access to, or clear multiple variables with a single command. For further details, refer to the COMMON, CLEARCOMMON, and CLEAR commands.
Undefined Variables
By default, if an MVBasic routine references an undefined variable, Caché generates an <UNDEFINED> error. That is, MVBasic undefined variables are handled the same as Caché undefined variables. They are subject to the current settings of the Management Portal UndefVarBehavior configuration setting, and the Undefined property of the Config.Miscellaneous class and Undefined() method of the %SYSTEM.Process class settings. All of these default to generating an <UNDEFINED> error. Go to the Management Portal, select [Home] > [Configuration] > [Compatibility Settings]. View and edit the current setting of Undefined. The default is 0 (always throw an error).
You can change this MVBasic default behavior to substitute an empty string for an undefined variable, without signalling an error. You can do this in either of two ways:
To set these Caché ObjectScript functions, use the MVBasic $XECUTE statement, as shown in the following example:
$XECUTE "DO $ZUTIL(68,72,1)"
Maximum Number of Variables
A Caché MVBasic routine can contain a maximum of 32,759 private variables, and a maximum of 65,280 public variables. Exceeding these limits results in a compile error.