An example procedure with logic

This example procedure with logic automatically prints a report on a particular day.

About this task

Procedures with logic can run both QMF and REXX commands. The rules and the structure of procedures with logic follow the rules of any REXX program.

This example shows how to print the following commissions report, but adds REXX logic to check whether the day is Monday. If it is Monday, the procedure automatically prints the report.
Figure 1. Enter your procedure on the PROC panel.
 PROC                                    MODIFIED    LINE 1
 
 -- MONDAY MORNING REPORT.
 -- PROCEDURES MAY CONTAIN COMMENT LINES; THEY BEGIN
 -- WITH TWO HYPHENS.
 -- A TITLE OR IDENTIFIER AT THE BEGINNING IS USEFUL.
 
 RUN QUERY REPT4QRY (FORM=REPT4FORM
 -- THIS COMMAND RUNS YOUR QUERY AND FORMATS THE REPORT.
 
 SAVE DATA AS LASTWEEKDATA (CONFIRM=NO
 -- THIS COMMAND SAVES YOUR DATA AND OVERRIDES THE VALUE OF
 -- CONFIRM IN YOUR PROFILE FOR THE DURATION OF THE COMMAND.
 
 PRINT REPORT (LENGTH=50
 -- THIS COMMAND PRINTS THE REPORT.
 -- YOU MAY OR MAY NOT WANT TO CHANGE PRINTING
 -- SPECIFICATIONS BY USING OPTIONS OF THE PRINT COMMAND.
 MESSAGE (TEXT 'OK, LASTWEEKDATA HAS BEEN SAVED AND PRINTED.'
 --THE MESSAGE COMMAND CAN BE USED TO DISPLAY A MESSAGE WHEN THE
 --PROCEDURE HAS FINISHED.
 
 
 *** END ***
 1=Help       2=Run        3=End      4=Print     5=Chart        6=Query
 7=Backward   8=Forward    9=Form     10=Insert   11=Delete       12=Report
 OK, cursor positioned.
 COMMAND ===>                                   SCROLL ===> PAGE

Procedure

  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 so that QMF recognizes the procedure as a procedure with logic.
    REXX comment lines begin with /* and end with */. The first line of a procedure must be a comment, but you can also use them anywhere to explain the commands in the procedure.
  4. Type the QMF commands that 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 will not run.

    Enclose all QMF commands in quotes to distinguish them from REXX commands; any QMF command that is 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 line, type INTERACT before the command name.

  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 a REXX exit statement at the end of the procedure.
    The procedure in the following figure 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. The procedure uses the QMF MESSAGE command to issue message text to help users diagnose the error.
    Figure 2. 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 ***
  7. 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.

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

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

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

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

    In the procedure that is shown in the previous figure, 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.