In this section: |
How to: |
Reference: |
The DECLARE command creates global and local variables (including objects), and gives you the option of assigning an initial value.
Where you place a DECLARE command within a procedure depends on whether you want it to define local or global variables. See Local and Global Declarations for more information.
The syntax of the DECLARE command is
DECLARE [(] objectname/datatype [DFC cc YRT yy] [missing]][= expression]; . . . [)] missing:[MISSING {ON|OFF} [NEEDS] [SOME|ALL] [DATA]]
where:
Is the name of the object or other variable that you are creating. The name is subject to the standard naming rules of the Maintain Data language. See Specifying Names for more information.
Is a data type (a class or built-in format).
Is an optional expression that will provide the initial value of the variable. If the expression is omitted, the initial value of the variable is the default for that data type: a space or null for character and date and time data types, and zero (0) or null for numeric data types. When declaring a new variable using a class data type, you must omit expression.
Specifies a default century that will be used to interpret any dates with unspecified centuries in expressions assigned to this variable. cc is a two-digit number indicating the century (for example, 19 would indicate the twentieth century). If this is not specified, it defaults to 19.
This is optional if the data type is a built-in format. It is not specified if the data type is a class, as it is relevant only for scalar variables.
Specifies a default threshold year for applying the default century identified in DFC cc. yy is a two-digit number indicating the year. If this is not specified, it defaults to 00.
When the year of the date being evaluated is less than the threshold year, the century of the date being evaluated defaults to the century defined in DFC cc plus one. When the year is equal to or greater than the threshold year, the century of the date being evaluated defaults to the century defined in DFC cc.
This is optional if the data type is a built-in format. It is not specified if the data type is a class, as it is relevant only for scalar variables.
Is used to allow or disallow null values. This is optional if the data type is a built-in format. It is not specified if the data type is a class, as it is relevant only for scalar variables.
If the MISSING syntax is omitted, the default value of the variable is zero (0) for numeric variables and a space for character and date and time variables. If it is included, its default value is null.
Sets the default value to null.
Sets the default value to zero (0) or a space.
Is an optional keyword that clarifies the meaning of the command for a reader.
Indicates that for the target variable to have a value, some (at least one) of the variables in the expression must have a value. If all of the variables in the expression are null, the target variable will be null. This is the default.
Indicates that for the target variable to have a value, all the variables in the expression must have values. If any of the variables in the expression is null, the target variable will be null.
Is an optional keyword that clarifies the meaning of the command for a reader.
Groups a sequence of declarations into a single DECLARE command. The parentheses are required for groups of local declarations, otherwise they are optional.
When you declare a new variable, you choose between making the variable:
To declare a local variable in the Top function, note that you cannot issue a DECLARE command in an implied Top function, but you can issue it within an explicit Top function.
We recommend declaring your variables locally, and to work with a variable outside the function in which it was declared, passing it to the other function as an argument. Local variables are preferable to global variables because they are protected from unintended changes made in other functions.