SET GLOBAL

The SET GLOBAL command assigns values to global variables from the QMF command line, from a procedure, or through the callable interface. You cannot change the value of a global variable that is defined as read-only.

You can define up to 10 substitution variables from the QMF command line or in a procedure. In the callable interface, the number of variables is limited only by your environment, and the exact syntax of the command depends on the language used. Use this linear syntax of the command with QMF procedures and REXX applications. Use the extended syntax to change the values of variables in callable interface languages other than REXX.

TSO with ISPF TSO without ISPF CICS®
X X X

Set a global variable in a QMF procedure or REXX application

Read syntax diagramSkip visual syntax diagramSETGLOBAL(,variablename1=value2&variable3)
Notes:
  • 1 Identifies the global variable to which a value is assigned.
  • 2 The character string that makes up the content of the global variable.
  • 3 A global variable name that contains the content of the global variable.

Description

variablename
Identifies the global variable to which a value is assigned.
value
The character string that makes up the content of the global variable.

A value that contains blank characters must be surrounded with delimiters. Valid delimiters for a global variable value are single quotation marks, parentheses, and double quotation marks. When the delimiters are double quotation marks, the quotation marks are included as part of the global variable.

When a SET GLOBAL command is entered from a linear procedure and the variable value spans multiple lines, the value must be enclosed in quotation marks and a continuation character (+) must be used in the first position of each line. Parentheses cannot be used as a delimiter when spanning multiple lines.

Usage notes

  • 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:
     ¢  !  $   ~   {  }  ? @  #  %  \
    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 cannot begin with DSQ, because QMF reserves these letters for QMF predefined global variables.

  • A global variable name cannot contain blanks or any of the following characters:
     .  ,  ;  :  <  >  (  )  |  +  -  *  / =  &   ¬  '  "
  • Variable names are limited to 18 single-byte characters (or the equivalent in double-byte characters) unless the variable is to be used as a substitution variable. Substitution variable names are limited to 17 characters. Character constants do not need to be enclosed in single quotation marks.
  • You can assign a variable value of 55 or fewer bytes with the SET GLOBAL command. To define variable values over 55 bytes, use the SHOW GLOBALS command to display the GLOBALS panel.
  • Global variable names with question marks are not recognized in QMF forms.
  • Global variables set to form variable names or aggregation variable names are not recognized by the QMF form.
  • 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, suppose that the SELECT statement is the following:
      SELECT DEPT, &COL FROM &TABLE
    The SET GLOBAL command that sets the variables for this SELECT statement might be something like the following:
      SET GLOBAL (COL='NAME', TABLE='Q.STAFF'
  • If the variable value that you are setting is a character string that contains quotation marks, you can use quotation marks or parentheses to delimit the value. For example, consider the following query:
    SELECT *
    FROM Q.STAFF
    WHERE NAME = &STAFF_NAME
    To set the STAFF_NAME variable to a value of 'JAMES' using quotation marks, issue the following command:
    SET GLOBAL (STAFF_NAME = '''JAMES''')
    To set the STAFF_NAME variable using parentheses, issue the following command:
    SET GLOBAL  (STAFF_NAME=('JAMES'))
  • If the variable contains a blank, comma, single quotation mark, double quotation mark, 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 quotation marks instead.
    For example, consider the following SELECT statement:
      SELECT &COLS FROM Q.STAFF

    To specify more than one column name in this SELECT statement, you need to include commas and, optionally, blanks to separate the values. Therefore, the SET GLOBAL command must be surrounded by parentheses, as shown in the following example:

      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 a 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 the variable name is found, the new value replaces the old value.

Examples

  1. To display a prompt panel where you can enter the variables and values that you want to set, issue the following command:
      SET GLOBAL ?
  2. To assign a value of 38 to the variable DEPT and a value of 'SALES' to the variable JOB, enter the following command:
      SET GLOBAL (DEPT = 38, JOB = '''SALES'''
  3. One way to assign the value of 'O''BRIEN' to the variable NAME is to use the following command:
      SET GLOBAL (NAME ='''O''''BRIEN'''