---
title: "How to Run a Query in QMF Automatically"
description: "Best example to run SQL query automatically in QMF. Useful for mainframe developers."
url: https://srinimf.com/2016/03/10/how-to-run-a-query-in-qmf-automatically/
date: 2016-03-10
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2016/03/pexels-photo-7957902.jpeg?fit=1880%2C1253&ssl=1
categories: ["QMF"]
tags: ["How to Automate QMF query"]
type: post
lang: en
---

# How to Run a Query in QMF Automatically

[Before you write](https://srinimf.com/2018/05/13/sql-code-review-tips/) a Procedure, [here are the](https://srinimf.com/2015/05/23/alter-table-table_name-drop-column-column_name/) steps mandatorily to complet.

1. Create and save the query and form
2. Enter: **RESET PROC**

## **The PROC panel displays.**

**Example Proc:**
/* This procedure checks to see what day it is.
If it’s Monday, it runs a query and prints a report.
If it isn’t, a message is displayed informing the user.*/
signal on error
if date(‘w’) = ‘Monday’
then
do
“RUN QUERY MYQUERY (FORM = MYFORM”
“PRINT REPORT”
“MESSAGE (TEXT=’OK,
MONDAY report has been created and sent to printer.'”

Related[QMF: EXPORT Report to Dataset](https://srinimf.com/2010/09/04/qmf-export-report-to-dataset/)

end
else
do
“MESSAGE (TEXT=’Sorry, it is not Monday. Report cannot be created.'”

Related[QMF Export Report to Excel or Word document](https://srinimf.com/2016/02/02/qmf-export-report-to-excel-or-word-document/)

end
exit 0 /*Exit without errors */
error:
“MESSAGE (TEXT = ‘”dsq_message_text”‘”
exit 8 /*Exit with error condition*/

*** END ***

Related posts

- [QMF Export Report to Excel or Word document](https://srinimf.com/2016/02/02/qmf-export-report-to-excel-or-word-document/)DateFebruary 2, 2016
- [QMF Commands for Senior Mainframe Programmers](https://srinimf.com/2015/06/14/qmf-commands-for-senior-mainframe-programmers/)DateJune 14, 2015
- [1000 Useful SQL Queries for Practice](https://srinimf.com/2017/02/25/the-story-of-1000-sql-queries-has-just-gone-viral/)DateFebruary 25, 2017

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2016%2F03%2F10%2Fhow-to-run-a-query-in-qmf-automatically%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2016%2F03%2Fpexels-photo-7957902.jpeg%3Ffit%3D1200%252C800%26ssl%3D1&description=How%20to%20Run%20a%20Query%20in%20QMF%20Automatically)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2016/03/10/how-to-run-a-query-in-qmf-automatically/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2016/03/10/how-to-run-a-query-in-qmf-automatically/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2016/03/10/how-to-run-a-query-in-qmf-automatically/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2016/03/10/how-to-run-a-query-in-qmf-automatically/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20How%20to%20Run%20a%20Query%20in%20QMF%20Automatically&body=https%3A%2F%2Fsrinimf.com%2F2016%2F03%2F10%2Fhow-to-run-a-query-in-qmf-automatically%2F&share=email)
-

### Like this:

Like Loading…
