Db2 Tools for zOS

Db2 Tools for z/OS

Connect with Db2, Informix, Netezza, open source, and other data experts to gain value from your data, share insights, and solve problems.

 View Only

How to Use QMF Global Variables in REXX Procedures

  • 1.  How to Use QMF Global Variables in REXX Procedures

    Posted 2 days ago

    Building Smart Reports: How to Use QMF Global Variables in REXX Procedures

    Introduction

    One of the hidden gems of QMF Z Client is the ability to use global variables.
    When combined with REXX procedures, global variables make your reports smarter, dynamic, and customizable - without changing the SQL every time.

    In this blog, we'll explore:

    • What global variables are
    • How to set and use them
    • How to pass values between QMF and REXX
    • A practical example: building parameterized smart reports

    What Are QMF Global Variables?

    QMF global variables are special placeholders that control various aspects of your session, commands, and reports.

    There are two types:

    1. System Global Variables (prefix DSQ)
      • Created during installation.
      • Control session behavior (e.g., DSQAO_CONNECT_ID sets user ID).
      • You can edit their values but cannot delete them.
    2. User-Defined Global Variables
      • Created by you, using SHOW GLOBALS → Add.
      • Can be temporary (session-only) or permanent.
      • Used to parameterize queries, procedures, and reports.

    Example:
    Instead of hardcoding a region in a query, define a global variable REGION and reuse it everywhere.


    Using Global Variables in REXX Procedures

    When writing procedures with logic, you can connect REXX variables with QMF global variables in three main ways:

    1. Set a QMF Global Variable from REXX

    /* REXX */

    region = 'APAC'

    ADDRESS QRW

    "SET GLOBAL (REPORT_REGION="region")"

    This creates or updates REPORT_REGION inside QMF.


    2. Get a QMF Global Variable into REXX

    /* REXX */

    ADDRESS QRW

    "GET GLOBAL (QMF_VER=DSQAO_QMF_RELEASE)"

    SAY "You are running QMF version: " QMF_VER

    Retrieves system variable DSQAO_QMF_RELEASE into QMF_VER.


    3. Use Global Variables in Queries

    Inside SQL, reference them with &:

    SELECT *

    FROM SALES

    WHERE REGION = '&REPORT_REGION'

    This makes the query reusable for different regions.


    Practical Example: Smart Regional Sales Report

    Let's build a report that adapts based on a user-specified region.

    Step 1: REXX Procedure

    /* REXX */

    SAY "Enter the region for the sales report (e.g., APAC, EMEA, NA):"

    PULL region

    ADDRESS QRW

    "SET GLOBAL (REPORT_REGION="region")"

    "RUN QUERY REGIONAL_SALES"

    Step 2: QMF Query REGIONAL_SALES

    SELECT PRODUCT, SUM(SALES) AS TOTAL_SALES

    FROM SALES

    WHERE REGION = '&REPORT_REGION'

    GROUP BY PRODUCT

    Step 3: Run

    • User enters APAC.
    • REXX sets global variable REPORT_REGION=APAC.
    • Query runs dynamically.

    Same procedure works for EMEA, NA, or any region - no SQL changes needed.


    Benefits of Using Global Variables

    • Parameterization → Make queries reusable across multiple scenarios.
    • Flexibility → Switch logic based on variables without modifying code.
    • Integration → Pass values between REXX and QMF seamlessly.
    • Automation → Combine with batch jobs for scheduled, parameter-driven reporting.

    Conclusion

    Global variables turn static reports into smart, reusable tools. By combining them with REXX procedures, you can:

    • Prompt users for input
    • Dynamically set filters
    • Build parameterized dashboards on z/OS

    With this technique, QMF Z Client evolves from a query tool into a dynamic reporting engine tailored to your business needs.



    ------------------------------
    Shashank Sonavane
    ------------------------------