Module 4: QMF Tables and Procedures
QMF- Tables and Procedures
So far everything lived on panels. This module makes it permanent: SAVE DATA turns query results into a real Db2 table, EXPORT/IMPORT moves objects in and out of QMF, and procedures chain QMF commands together so a whole reporting job runs with one RUN PROC — interactively or on a schedule in batch.
Saving query results as a table: SAVE DATA
RUN QUERY Q1
SAVE DATA AS DEPT38_STAFF
- Run the query first so the answer rows are on the REPORT panel, then SAVE DATA AS tablename creates a real Db2 table holding those rows.
- The new table gets the columns of the report (headings become column names, sanitized) and is immediately queryable with normal SQL.
- If the table already exists, QMF prompts before overwriting — never assume it replaced the old data.
- You need authority to create tables (CREATETAB privilege or rights in a tablespace); without it SAVE DATA fails with a -551.
Working with saved tables
SELECT NAME, SALARY FROM DEPT38_STAFF ORDER BY SALARY DESC
LIST TABLES
ERASE TABLE DEPT38_STAFF (CONFIRM=NO
- A saved table is an ordinary Db2 table: query it, join it, grant on it, or drop it like any other.
- LIST TABLES shows the tables you created with SAVE DATA; ERASE TABLE removes one.
- Saved tables are a handy way to snapshot a point-in-time result for auditing or month-end comparisons.
EXPORT and IMPORT
EXPORT QUERY TO 'MYID.QMF.QUERY(Q1)'
EXPORT REPORT TO 'MYID.QMF.REPORT(RPT1)'
IMPORT QUERY FROM 'MYID.QMF.QUERY(Q1)'
- EXPORT writes a QMF object (QUERY, DATA, FORM, PROC, REPORT) to a data set or file — for backup or moving it to another system.
- IMPORT reads it back into the QMF catalog on any system with QMF installed.
- EXPORT REPORT captures the formatted report text, useful for archiving exactly what was printed.
QMF procedures: automating command sequences
- A procedure (PROC) is a saved list of QMF commands that execute top to bottom — QMF's built-in scripting.
- Build one on the PROC panel (DISPLAY PROC name), save it like any object, and run it with RUN PROC name.
- Procs accept parameters: &1 through &9 are replaced by the values you pass on RUN PROC.
- A proc can also call another proc, prompt the user with substitution variables, and branch on conditions — but most shop procs are simple command lists like the example below.
A real PROC example
-- PROC: MONTHLY_DEPT_REPORT
-- Run as: RUN PROC MONTHLY_DEPT_REPORT (38, F1, PRT1
RUN QUERY DEPT_STAFF_QRY (FORM=&2
PRINT REPORT (PRINTER=&3
SAVE DATA AS DEPT&1_SNAPSHOT
- Line 1 runs the saved query DEPT_STAFF_QRY under the form passed as &2 (e.g. F1).
- Line 2 prints the report to the printer passed as &3 (e.g. PRT1).
- Line 3 snapshots the rows into a table named from &1 (e.g. DEPT38_SNAPSHOT).
- Invoke it with RUN PROC MONTHLY_DEPT_REPORT (38, F1, PRT1 — the three values fill &1, &2, &3 in order.
- Save the proc with SAVE PROC AS MONTHLY_DEPT_REPORT; manage it with LIST PROCS, DISPLAY PROC, ERASE PROC.
Scheduling: running QMF in batch
- QMF runs under TSO, so a batch job uses IKJEFT01 (TSO in batch) to invoke QMF and run a proc unattended.
- The batch job runs under its own authorization ID, which needs the same Db2 privileges your interactive ID has.
- Schedule the job with your site's scheduler (Control-M, CA-7/TWS, or similar) for nightly, weekly, or month-end runs.
- Always test the proc interactively first — debugging is far easier on panels than in a batch SYSTSPRT listing.
//QMFBATCH JOB (ACCT),'QMF BATCH',CLASS=A,MSGCLASS=X
//STEP1 EXEC PGM=IKJEFT01
//STEPLIB DD DSN=QMF.LOADLIB,DISP=SHR * your QMF load library
//SYSTSPRT DD SYSOUT=*
//SYSTSIN DD *
QMF
RUN PROC MONTHLY_DEPT_REPORT (38, F1, PRT1
EXIT
/*
- SYSTSIN feeds TSO commands: QMF starts the session (program DSQQMFE), then the proc runs, then EXIT ends it.
- Replace QMF.LOADLIB with your installation's QMF load library name — ask your QMF administrator.
- Check SYSTSPRT after the run: it shows each command, any errors, and the governor messages.
