Variables
Variables are user-defined symbol names that represent a data value that can change with each run of the report. Many Report-Writer statements accept variables as parameters. For example, in a .query statement you can use variables as substitutes for any part of a query. See .Query in the chapter “Report-Writer Statements.”
In Report-Writer, assign variable values in the following ways:
• At report runtime, as a parameter on the command line or in response to a default or custom prompt
• In a .declare statement, as an initial value for a variable (useful for variables evaluated during the loading of a report specification)
• In a .let statement, where you can assign a value to a variable for use within the body of the report. See .Let in the chapter “Report-Writer Statements.”
You define variables through the .declare statement, which allows you to name a variable. The .declare statement also allows you to:
• Create your own custom prompt
• Specify the data type and nullability of the variable
You are strongly encouraged to define all variables with the .declare statement. By declaring variables, there are no limits to the ways you can use them in your report. Although Report-Writer recognizes any name preceded by a dollar sign ($) as a variable, undeclared variables assume default types and characteristics that are often incompatible with their intended use.
If you use a variable in your report without declaring it, you can assign it a value only by using a command line parameter or by entering a value in response to a runtime prompt.
You cannot specify a value for an undeclared variable with a .let statement. In addition, unless the variable has been declared, attempting to pass a parameter with a null value to Report-Writer can produce incorrect results. For more information, see the .Declare statement in the chapter “Report-Writer Statements.”
Note: If you run reports from the RBF catalog, they cannot be run in the background if they contain undeclared variables.
When you specify variables for runtime substitution of values in expressions, precede the variable name with a dollar sign ($). The dollar sign cannot be embedded within the variable (for example, var$name). In addition, variable names must follow these rules:
• Must begin with a letter
• Cannot match any of the reserved words listed in the Reserved Words section
• Any commas (,), parentheses ( ), or colons (:) required in the statement syntax must be explicitly stated and cannot be part of the variable.
Some examples of variables are:
$myvar
$your_name
$salary
$start_date
A variable used in a query can be referenced in other parts of the report specification as well, but it must always be preceded by a dollar sign ($). The variable must logically correspond to its intended value. For example, if the variable is used as a number, its value must be a legal Ingres number. If the variable is used as a date, its value must be a legal Ingres date. Otherwise, the variable is interpreted as a character string.
Last modified date: 08/14/2024