Use the SET STATICVAR command to define or redefine a static variable value and/or data type.
Options
colname
Specifies a column name. The column name is limited to 128 characters. In a command, you can enter #c, where #c is the column number shown when the columns are listed with the LIST TABLES command. In an SQL command, a column name can be preceded by a table or correlation name and a period (tblname.colname).
datatype
Specifies an R:BASE data type for the static variable. See Data Types.
(expression)
Determines a value using a text or arithmetic formula. The expression can include constant values, functions, or system variables such as #date, #time, and #pi.
IN tblview
Specifies a table or view.
NULL
Sets the static variable equal to NULL.
value
Sets the static variable equal to a specified value. A value is a constant amount, text string, date, or time, or the value assigned to varname.
varname
Specifies a static variable name, which must be unique among both the static variable names within the database and the global variable names for the R:BASE session. The static variable name is limited to 128 characters.
&varname
Sets the first variable equal to the exact contents of a second variable; the ampersand tells R:BASE to evaluate the contents of the variable first.
For example, if varname is the text string (2+3), then &varname is the value 5.
.varname
Sets the first variable equal to the exact contents of a second variable.
For example, if varname is the text string (2+3), then .varname is (2+3).
WHERE clause
Limits rows of data. For more information, see the WHERE Clause.
About the SET STATICVAR Command
The SET STATICVAR command defines static variables, which are part of a connected database. Once defined, the variables are created every time the database is connected. When a database is disconnected, the static variables associated with the database are cleared. Static variable can be used just like normal variables with SET VARIABLE commands and in expressions. The basic syntax is just like the SET VARIABLE command except you use the word STATICVAR instead of VARIABLE (or VAR).
The UNLOAD command will create SET STATICVAR commands for the static variables defined for the connected database.
To display the current static variables use the SHOW STATICVAR command. To clear one or more static variables use the CLEAR command. CLEAR ALL VAR will clear all variables (global and static), but immediately recreates the static variables, just like R:BASE does with system variables.
Important: It is recommended to define each static variable as a separate entry in the database. Defining multiple static variables with a single SET STATICVAR command should be avoided, as the multiple variables are defined as a group and are retained as a single database entry. If the variable group are always used as a set, then they are more ideal to manage. If the intent is to store each static variable as a separate item, each variable must be defined with a separate SET STATICVAR command.
The benefits of static variables include:
•Database unloads will no longer trip over missing global variables
•Users would not have to remember to define required variables used in views
•With CVAL functions, the current computer and environment may be easily captured
•Distributed applications could contain static variables specific to each customer
Static variable have the following restrictions:
•The variable name is not an R:BASE reserved word.
•The variable name begins with a letter, contains only letters, numbers, and the following special characters: #, $, _ , and %.
•The variable definitions are limited to 512 characters.
It is good programming practice to always define the data type for the variable before assigning it a value. When defining an variable as a text string, enclose the text string in single quote marks (or the current QUOTES character); otherwise, it might be interpreted as an arithmetic expression.
Assigning a Data Type to a Static Variable
The datatype option refers to one of the valid R:BASE data types. You can define a static variable to have a NOTE data type, but R:BASE treats it as TEXT for most uses. You can also specify the precision and scale for NUMERIC data types.
The datatype option creates a static variable, determines its data type, and sets its value to null. Use this option to define a static variable's data type before assigning a value to the variable.
For an existing static variable, you can use the datatype option to change the data type, but it is recommended to use one of the conversion functions. If you change the data type, the new data type must be compatible with the current variable value; if the variable is not compatible, R:BASE displays an error message and leaves the value and data type unchanged. If you change a variable with a TEXT data type to a non-compatible data type, R:BASE changes the value to null.
Assigning a Value to a Static Variable
The value option is a data value or constant, such as 10, TOM, 3.1416, or $17.23. If the static variable already exists, any new value must have a data type that is compatible with that variable. If the static variable does not exist, R:BASE defines the variable's data type. You can also define the variable's data type in this command before assigning it a value.
Setting the Value of a Static Variable to Another Variable
When you set a static variable to the value of another variable, the second variable must be a dot variable (.) or an ampersand (&) variable.
When you precede a variable with a dot (.), R:BASE uses the value stored in the variable as if it were a constant.
When you precede a variable with an ampersand (&), R:BASE first evaluates the value contained in the ampersand variable. For example, consider the following uses of the command:
SET STATICVAR vM TEXT = 'Multi'
SET STATICVAR vP TEXT = 'Purpose'
SET STATICVAR vMP TEXT = '(vM + vP)'
SET STATICVAR vMPValue = .vMP
SET STATICVAR vMPCompute = &vMP
When the third command line runs, the variable vMP will contain (vM + vP). When the forth command line runs, variable vMPValue will also contain (vM + vP) because the dot tells R:BASE to set the value as an exact match to the contents of variable vMP. When the fifth command line runs, variable vMPCompute will contain MultiPurpose (the concatenation of Multi and Purpose) because the ampersand tells R:BASE to compute the contents of variable vMP.
As shown in the example above, an ampersand variable can contain one command or part of one command, such as an expression. The first variable is set to the computed value of the ampersand variable. Below is an example:
1.SET STATICVAR v1 TEXT
2.SET STATICVAR v2 INTEGER
3.SET STATICVAR v1 = '((50 + 100)/ 2)'
4.SET STATICVAR v2 = &v1
5.SHOW STATICVAR
1.Sets the data type for the variable v1 to TEXT.
2.Sets the data type for the variable v2 to INTEGER.
3.Sets variable v1 to a text value that is a valid arithmetic expression.
4.Sets variable v2 to &v1.
5.Displays the value of all static variables.
R:BASE computes the expression contained in v1 and assigns the calculated value to v2. When R:BASE sees a variable name preceded by ampersand, it treats the contents of the variable as if it was entered from the keyboard. The SHOW STATICVAR display would like the following:
Variable = Value Type
------------------ ------------------------------ -------
v1 = ((50 + 100)/ 2) TEXT
v2 = 75 INTEGER
Setting a Static Variable to an Expression
An (expression) can be either an arithmetic operation that combines two or more items in an arithmetic computation, or a string expression that concatenates two or more text items, or uses a TEXT function. The items can be values or the values contained in variables.
If you do not predefine the data type of a static variable, the original data type of each item determines the data type of the result. For example, if you add a variable that has an INTEGER data type to a variable that has a REAL data type, the resulting variable has a REAL data type unless you define the result to be an INTEGER data type.
If any item in an arithmetic expression is null, the result will be null unless you specify SET ZERO ON.
Assigning Column Values in a Table or View
If you specify a table or view in a SET STATICVAR command, you can include an optional WHERE clause to indicate which row to use. If you do not include the WHERE clause, R:BASE uses the value for the column in the first row.
You must have SELECT privileges on the table to use this form of SET STATICVAR.
Examples
Defines the vMessage static variable to have a TEXT data type.
SET STATICVAR vMessage TEXT
Defines the vReal static variable to have a REAL data type, and assigns it the value 100.9.
SET STATICVAR vReal REAL = 100.9
Defines the vNumer static variable to have a NUMERIC data type having a precision of 9 and scale of 3.
SET STATICVAR vNumer NUMERIC (9,3)
Assigns the integer value 14322 to the vNum static variable.
SET STATICVAR vNum = 14322
Assigns the value of the above vNum variable to the vTwo static variable.
SET STATICVAR vTwo =.vNum
Assigns the value 03/25/2022 to the vLtrDate static variable.
SET STATICVAR vLtrDate = ('12/25/2021' + 90)
Assigns the vCompanyName static variable from the row in the LicenseInformation table where the LicenseNumber value is equal to BM-68215.
SET STATICVAR vCompanyName TEXT = CompanyName IN LicenseInformation WHERE LicenseNumber = 'BM-68215'