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 Maintain language's standard naming rules; see Specifying Names.
Is a data type (a class or built-in format).
Is an optional expression that will provide the variable's initial value. If the expression is omitted, the variable's initial value is the default for that data type: a space or null for alphanumeric and date and time data types, and zero 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.
For information about working with cross-century dates, see Developing Applications.
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.
For information about working with cross-century dates, see Developing Applications.
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 variable's default value is zero for numeric variables and a space for alphanumeric 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 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:
If you wish 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 (when you need 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.
Information Builders |