DECLARE

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.


Top of page

x
Syntax: How to Use the DECLARE Command

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:

objectname

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.

datatype

Is a data type (a class or built-in format).

expression

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.

DFC cc

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.

YRT yy

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.

missing

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.

MISSING

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.

ON

Sets the default value to null.

OFF

Sets the default value to zero or a space.

NEEDS

Is an optional keyword that clarifies the meaning of the command for a reader.

SOME

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.

ALL

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.

DATA

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.


Top of page

x
Reference: Commands Related to DECLARE

Top of page

x
Local and Global Declarations

When you declare a new variable, you choose between making the variable:

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