Identifying a special condition using an expression

In this example, you create a report that displays specific text whenever the data meets certain conditions by using the FORM.CONDITIONS panel with the FORM.DETAIL panel.

About this task

You can format your report in different ways with this method, depending on conditions you want QMF to test for. You specify an expression for any tests or conditions on the FORM.CONDITIONS panel. Then you associate a FORM.DETAIL panel with each test. When the test evaluates to true for the data in a particular row, QMF formats the report the way you specify on the associated FORM.DETAIL panel. When the test does not evaluate to true, you can specify a different format on another FORM.DETAIL panel.

In this example, you create a condition that prints the text *** Needs Raise *** in the report for all employees with salary plus commissions less than $17,000.00.

Procedure

  1. Run the query and display the report.

    For this example, use this query:

    SELECT ID, NAME, JOB, DEPT, SALARY, COMM
      FROM Q.STAFF
  2. On the QMF command line, enter:
    SHOW FORM.CONDITIONS

    The FORM.CONDITIONS panel displays.

  3. Type an ID number for the expression. You can use any number from 1 through 999.

    For this example, you need to create two conditions: one for employees who earn greater than or equal to $17,000.00, and one for employees who earn less than $17,000.00.

    Type 1 for the first expression and 2 for the second expression.

  4. In the CONDITIONAL EXPRESSION field, type the first expression, using form variables to specify the columns according to their position numbers in the SELECT statement of the query.

    For this example, type the following:

    &5 + NULL(&6) >= 17000.00

    This is the first condition, which finds each row for which the employee's total earnings (SALARY+COMM) are greater than or equal to $17,000.00.

    For the second condition, type the following, which finds each row for which the employee's total earnings are less than $17,000.00:

    &5 + NULL(&6) < 17000.00
  5. Type YES in the PASS NULLS field to process nulls for this example.

    If you want to process nulls, you can create a REXX program like NULL to substitute a 0 (or whatever value is appropriate) for the null value. Then you can use that value in the calculation. A sample NULL program is shown in Displaying a calculated value on a report. The following figure shows how to use the NULL program in the CONDITIONAL EXPRESSION field of the FORM.CONDITIONS panel.

    Figure 1. Specifying conditional expressions for employees' raises
    FORM.CONDITIONS
     
                                                   Pass
      ID   CONDITIONAL EXPRESSION                  Nulls?
      ---  --------------------------------------------------
      1    &5 + NULL(&6) >= 17000.00               YES
      2    &5 + NULL(&6) < 17000.00                YES
           *** END ***
     

    Now that you have defined the conditions you want to display on the report, use the FORM.DETAIL panel to create a report variation for each condition. This type of report formatting is called conditional formatting.

    You can select a report variation without associating it with a specific condition, or associate it with a condition such as those you entered on the FORM.CONDITIONS panel.

  6. On the QMF command line, enter:
    SHOW FORM.DETAIL

    The FORM.DETAIL panel displays.

  7. In the Select Panel Variation field, type C1 to associate this report format variation with the first condition on the FORM.CONDITIONS panel, where the employee makes greater than or equal to $17,000.00. For this variation, do not enter any detail text.
  8. Create a report variation for the second condition. For this example, move the cursor to Var 1 of 1.
  9. Type 2 over the 1 and press Enter. (You can also enter NEXT on the QMF command line.)

    A second FORM.DETAIL panel displays.

  10. In the Select Panel Variation field, type C2 to associate this report format variation with the second condition on the FORM.CONDITIONS panel, where the employee makes less than $17,000.00.
  11. For this example, type *** Needs Raise *** for the first line of detail block text, as shown in the following figure. Change the alignment to column 60. QMF displays the text on the report when this condition is true.
    Figure 2. Specify detail block text to appear when the condition is true.
     FORM.DETAIL                                                       Var 1  of 1
     
     Include Column Headings with Detail Heading? ===> YES
     LINE  ALIGN   DETAIL HEADING TEXT
     ----  ------  ----+----1----+----2----+----3----+----4----+----5----+
     1     LEFT
     2     LEFT
                   *** END ***
     
     New Page for Detail Block? ===> NO      Repeat Detail Heading?    ===> NO
     Keep Block on Page?        ===> NO      Blank Lines after Block   ===> 0
     Put Tabular Data at Line (Enter 1-999 or NONE) ===> 1
     LINE  ALIGN   DETAIL BLOCK TEXT
     ----  ------  ----+----1----+----2----+----3----+----4----+----5----+
     1     60      *** Needs Raise ***
     2     LEFT
                   *** END ***
     
     Select Panel Variation?    ===> C2
     
  12. Change the width of the report so that the detail block text appears. On the QMF command line, enter:
    SHOW FORM.OPTIONS
  13. In the Report text line width field, type 80 to change the report width to 80 columns.
  14. Press the Report function key to see the changed report, which is shown in the following figure.
    Figure 3. This report uses conditional formatting to show employees who need a raise.
           ID  NAME       JOB      DEPT      SALARY        COMM
       ------  ---------  -----  ------  ----------  ----------
     
           10  SANDERS    MGR        20    18357.50           -
           20  PERNAL     SALES      20    18171.25      612.45
           30  MARENGHI   MGR        38    17506.75           -
           40  O'BRIEN    SALES      38    18006.00      846.55
           50  HANES      MGR        15    20659.80           -
           60  QUIGLEY    SALES      38    16808.30      650.25
           70  ROTHMAN    SALES      15    16502.83     1152.00
           80  JAMES      CLERK      20    13504.60      128.20 *** Needs Raise ***
           90  KOONITZ    SALES      42    18001.75     1386.70
          100  PLOTZ      MGR        42    18352.80           -
          110  NGAN       CLERK      15    12508.20      206.60 *** Needs Raise ***
          120  NAUGHTON   CLERK      38    12954.75      180.00 *** Needs Raise ***
          130  YAMAGUCHI  CLERK      42    10505.90       75.60 *** Needs Raise ***
          140  FRAYE      MGR        51    21150.00           -
                 .
                 .
                 .