DECLARE-VARIABLE

Syntax

DECLARE-VARIABLE [DEFAULT-NUMERIC={DECIMAL[(prec_lit)]|FLOAT|INTEGER}] [DECIMAL[(prec_lit)]num_var[(prec_lit)][num_var [(prec_lit)]]...] [FLOAT num_var[num_var]...] [DATE date_var[date_var]...] [INTEGER num_var[num_var]...] [TEXT string_var[string_var]...] END-DECLARE

Description

Enables you to explicitly declare a variable type.

You can set the default numeric type externally, using the -DNT command-line flag or the DEFAULT-NUMERIC setting in the Default-Settings section of the pssqr.ini file. However, the setting in the DECLARE-VARIABLE command takes precedence over all other settings. If the command has not been used, then the -DNT command-line flag takes precedence over the setting in the pssqr.ini file.

In addition to FLOAT, INTEGER, and DECIMAL, you can set DEFAULT-NUMERIC in the pssqr.ini file and the -DNT command-line flag to V30. With V30, the program acts in the same manner as in versions prior to release 4.0; that is, all variables are FLOAT. V30 is not a valid setting for the DEFAULT-NUMERIC setting in the DECLARE-VARIABLE command.

The DECLARE-VARIABLE command enables you to determine the type of variables to use. This command can appear only in the SETUP section or as the first statement of a local procedure. The placement of the command affects its scope. When used in the SETUP section, it affects all variables in the entire program. Alternatively, when it is placed in a local procedure, its effect is limited to the scope of the procedure. If the command is in both places, the local declaration takes precedence over the SETUP declaration.

In addition to declaring variables, this command enables you to specify the default numeric type using the DEFAULT-NUMERIC setting as FLOAT, INTEGER, or DECIMAL. When dealing with money or when more precision is required, use the DECIMAL qualifier.

The DECLARE-VARIABLE command, the -DNT command-line flag, and the DEFAULT-NUMERIC setting in the pssqr.ini file affect the way numeric literals are typed. If V30 is specified, then all numeric literals are FLOAT (just as in versions prior to release 4.0); otherwise, the use or lack of a decimal point determines the type of the literal as either FLOAT or INTEGER, respectively. Finally, not specifying the DECLARE-VARIABLE command, the -DNT command-line flag, and the DEFAULT-NUMERIC setting in the pssqr.ini file is the same as specifying V30.

Parameters

Parameter Description

DEFAULT-NUMERIC

Specifies the default type for numeric variables. Unless explicitly declared otherwise, a numeric variable assumes the variable type. This qualifier overrides any setting from the command-line flag -DNT or the DEFAULT- NUMERIC entry in the [Default-Settings] section of the pssqr.ini file. If -DNT was not specified on the command line and the pssqr.ini file entry has no DEFAULT-NUMERIC entry, then the default numeric type is FLOAT.

DECIMAL

Specifies that the numeric variables that follow are decimal variables with a precision specified with prec_lit. The precision can be assigned to the group of variables or to each individual variable. The precision is the total number of digits used to represent the number. This precision can range from 1 to 38. The default value is 16. The range of decimal numbers is from –9.9999999999999999999999999999999999999E±4096 to +9.9999999999999999999999999999999999999E±4096.

FLOAT

Specifies that the numeric variables that follow are used as double-precision floating points. The range and precision of these numbers are machine-dependent.

DATE

Specifies that the date variables that follow can contain a date in the range of January 1, 4713 BC to December 31, 9999 AD.

INTEGER

Specifies that the numeric variables that follow are used as integers with a range of –2147483648 to +2147483647.

TEXT

Specifies that the string variables that follow are text variables.

Example

The following example illustrates the DECLARE-VARIABLE command:

begin-setup
  declare-variable 
    default-numeric=float
    decimal  #decimal(10)
    integer  #counter
    date     $date
  end-declare
end-setup
.
.
let $date = strtodate('Jan 01 2004','Mon DD YYYY')
print $date (1,1)
position (+2,1)

let #counter = 0
while #counter < 10
 let #decimal = sqrt(#counter)
 add 1 to counter
 print #decimal  (+1,1) 9.999999999
end-while

do sub1($date, 'day', 10)

do sub2

.
.
begin-procedure sub1(:$dvar, $units, #uval)
declare-variable
 date $dvar
 integer #uval
end-declare
let $dvar = dateadd($dvar, $units, #uval)
print $dvar (+1,1)
position (+2,1)
end-procedure
.
.
begin-procedure sub2 LOCAL
declare-variable
 date $mydate
end-declare
let $mydate = dateadd($_date, 'year', 5)
print $mydate (+1,1)
position (+2,1)
end-procedure
.
.