- Global variables can be used in queries, procedures, and forms.
Preface a variable with one or more ampersands (&) when
you use it in a QMF object.
- A global variable name can contain a numeric character, but
the first character of a global variable name cannot be numeric.
- The first character of a global variable name must be an alphabetic
character (A through Z) or one of these special characters:
¢ ! $ ~ { } ?
@ # % \
- A global variable name cannot contain blanks or any of the following characters:
. , ; : < > ( ) | + - * /
= & ¬ ' "
- Variable names are limited to 17 single-byte characters (or
the equivalent in double-byte characters). Character constants do
not need to be enclosed in single quotes.
- On the SET GLOBAL command, variable names are not preceded with
an ampersand like they are on the RUN and CONVERT commands.
- Global variable names with question marks are not recognized
by the QMF form.
- Global variables set to form variable names or aggregation variable
names are not recognized by the QMF form.
- Global variable names cannot begin with DSQ, because QMF reserves
these letters for QMF predefined global variables.
- Trailing blanks are not recognized in global variable names.
- If a variable is a character string that is a name (such as
the name of a column, a table, or an operator):
- Double all embedded quotation marks.
- Enclose the complete string in a set of single quotation marks.
(These quotation marks are not considered part of the value.)
For example, if the SELECT statement is:
SELECT DEPT, &COL FROM &TABLE
The SET GLOBAL command is:
SET GLOBAL (COL='NAME', TABLE='Q.STAFF'
- If the variable is a character string that is to be used as
a value contained within a column (unique to the WHERE clause in
an SQL statement) you can use either of two methods to specify a
string.
Method 1 (quotes)
- Start with the original string.
- Double all quotation marks (if any).
- Enclose the string in two sets of single quotation marks.
- Double all the embedded quotes (all but the outermost ones).
Method 2 (parentheses)
- Start with the original string.
- Enclose the string in one set of parentheses.
For example, if the SELECT statement is:
SELECT DEPT FROM &TABLE WHERE NAME=&ABC
The Method 1 SET GLOBAL command is (substituting JAMES for variable ABC):
SET GLOBAL (ABC='''JAMES''', TABLE='Q.STAFF'
The Method 2 example for the same SELECT statement is (substituting O'BRIEN
for variable ABC):
SET GLOBAL (ABC=(O'BRIEN), TABLE='Q.STAFF'
- If the variable contains a blank, comma, single quote, double
quote, or an equal sign, the entire value must be enclosed in a
set of parentheses. However, if the value includes an unmatched
set of left or right parentheses or begins or ends with a left or
right parenthesis respectively, you must use quotes instead.
For example, if the SELECT statement is:
SELECT &COLS FROM Q.STAFF
The SET GLOBAL command is:
SET GLOBAL (COLS=(NAME, JOB, SALARY)
- At least one variable must be specified.
- If a quotation mark is required within a variable value, use
two single quotation marks.
- Do not use a query comment as variable value. A query comment
is preceded by two dashes (--), which the database interprets as
minus signs.
- When you are setting many variables, it is easier to keep track
of them if you use a procedure.
- If the variable is a numeric string, you do not need to use
quotation marks.
- If the variable name is not found in the QMF product global
variable pool, a new variable is created.
- If variable name is found, the new value replaces the old value.
- When a SET GLOBAL command is entered from a linear proc and
the variable value spans multiple lines, the value must be enclosed
in quotes and a continuation character (+) must be used in the first
position of each line. When the delimiters are double quotes, the
double quotes are included as part of the global variable value.
Parentheses cannot be used as a delimeter when spanning multiple
lines