Using QMF


Creating a procedure with logic

You can print the same commissions report as in the previous example, but add REXX logic to check whether the day is Monday. If it is Monday, the procedure can automatically print the report.

The rules and the structure of procedures with logic follow those of any REXX program. For more information about the REXX procedural language, see either of the following:

To create a procedure with logic:

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

    The PROC panel displays.

  3. Type a REXX comment line as the first line of the procedure. REXX comment lines begin with /* and end with */.
  4. Type the QMF commands you want the procedure to run in the order you want them to run.

    Because QMF does not convert any text in a procedure, type all QMF commands in uppercase, or they do not run.

    Enclose all QMF commands in quotes, otherwise any QMF command identical to a REXX command (such as EXIT) is processed as a REXX command.

    If you want to display and interact with panels just as you would if you entered a command on the QMF command, type INTERACT before the command name.

    For more information on the INTERACT command, see the QMF Reference, SC26-4716-05.

  5. Type the logic statements for the procedure. You can use any REXX function in a procedure with logic.

    You can also include internal functions for arithmetic operations, character manipulation, data conversion, and information gathering, and you can write your own external functions.

  6. Type REXX comment lines (instead of QMF comment lines) if you need them.
  7. Type a REXX exit statement at the end of the procedure.

    The procedure in Figure 148 has two exit statements. One has an exit code of 0, meaning that the procedure ran successfully. The other has a return code of 8, meaning that an error occurred while the procedure was running.

  8. To insert lines in a procedure, move the cursor to the line you want to precede the new line, and press the Insert function key.

    Or you can type INSERT on the QMF command line, move the cursor to the line you want to precede the new line, and press Enter.

  9. To delete lines from a procedure, move the cursor to the line you want to delete and press the Delete function key.

    Or you can type DELETE on the QMF command line, move the cursor to the line you want to delete, and press Enter.

  10. To save the procedure in the database, enter:
    SAVE AS procname
    

    Figure 148. This procedure produces a commission report on Mondays.

    +--------------------------------------------------------------------------------+
    | PROC                                    MODIFIED     LINE     1                |
    |                                                                                |
    | /* 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.'"  |
    |   end                                                                          |
    | else                                                                           |
    |   do                                                                           |
    |     "MESSAGE (TEXT='Sorry, it is not Monday.  Report cannot be created.'"      |
    |   end                                                                          |
    | exit 0       /*Exit without errors */                                          |
    | error:                                                                         |
    |   "MESSAGE (TEXT = '"dsq_message_text"'"                                       |
    |   exit 8      /*Exit with error condition*/                                    |
    | *** END ***                                                                    |
    +--------------------------------------------------------------------------------+

In the procedure that is shown in Figure 148, the REXX DATE function provides the day of the week. The rest of the procedure includes QMF commands that are run depending on the day of the week.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]