Previous Topic

Next Topic

Book Contents

Book Index

Solution – Details

The rule consists of the following four ON blocks:

In this rule, you will

Examine this rule online. Proceed to the Rule Definition facility, to the Rule List screen.

  1. Select rule ARWARN06 for browsing.

    If you are not familiar with how to select a rule for browsing, review the instructions at the beginning of the discussion of rule ARWARN02 in Problem 2.

    Figure 93 Rule ARWARN06

            LIBRARY : CTB.PROD.RULES                                RULE : ARWARN06

    COMMAND ===>                                                    SCROLL===> CRSR

    +---------------------------------- BROWSE -----------------------------------+

    | OWNER   M66                      GROUP INTRAC                               |

    | UPDATED 03/04/99  -  15:30:05    BY M66                                     |

    | DESC    CHECK MONTH SALES COMMISSIONS REPORT                                |

    | OPTIONS                                                                     |

    | =========================================================================== |

    | EXECUTE INIT     UPON                                                   C   |

    | ON DATA                                                                     |

    | ALWAYS                                                                      |

    |   DO SET      = TOTPEOPLE=0                                             C   |

    |   DO SET      = LASTSALES=' '                                           C   |

    |   DO SET      = ERRORCOUNT=0                                            C   |

    |   DO SET      = BLANK=' '                                               C   |

    | =========================================================================== |

    | EXECUTE INPUT    UPON                                                   C   |

    | ON SYSOUT     PROCST          PGMST STEP01   DDNAME SYSUT2   JOBNM          |

    |    MODE PG    LINECT 0000    DATASTAMP                                      |

    | WHEN LINE 001     - 005     COL 002     - 014              STOP Y  AND/OR A |

    |      STRING = SALESPERSON                                                   |

    | STOP LINE 001     - 002     COL 001     - 020                               |

    |      STRING = INTRAC                                                        |

    PLEASE FILL IN RULE DEFINITION.                                        15.50.49

    In the INIT ON block, two variables, TOTPEOPLE and LASTSALES, process a table containing each salesperson's relevant amounts from the report. These variables are discussed later in these instructions.

    In the next ON block, INPUT extracts data from the report.

  2. Place the cursor on the line beginning with the character string "EXECUTE INPUT," and press PF08/PF20, or enter the DOWN command.

    Figure 94 EXECUTE INPUT ON Block

            LIBRARY : CTB.PROD.RULES                                RULE : ARWARN06

    COMMAND ===>                                                    SCROLL===> CRSR

    +---------------------------------- BROWSE -----------------------------------+

    | EXECUTE INPUT    UPON                                                   C   |

    | ON SYSOUT     PROCST          PGMST STEP01   DDNAME SYSUT2   JOBNM          |

    |    MODE PG    LINECT 0000    DATASTAMP                                      |

    | WHEN LINE 001     - 005     COL 002     - 014              STOP Y  AND/OR A |

    |      STRING = SALESPERSON                                                   |

    | STOP LINE 001     - 002     COL 001     - 020                               |

    |      STRING = INTRAC                                                        |

    | WHEN LINE L01+001 - 060     COL 050     - 060              STOP    AND/OR   |

    |      STRING = /                                                             |

    |   DO EXTRACT  = SALESNO                                                     |

    |                 LEVEL 1 LINE +000 COL 0035 - 0037 PROCESS          TYP      |

    |   DO EXTRACT  = AMOUNT                                                      |

    |                 LEVEL 0 LINE +000 COL 0068 - 0078 PROCESS          TYP      |

    |   DO EXTRACT  = SUM1%%SALESNO                                               |

    |                 LEVEL 0 LINE +000 COL 0068 - 0078 PROCESS          TYP SU   |

    |   DO BLOCK    = CHKNAME  ARG                                            C   |

    | WHEN LINE 005     - 005     COL 002     - 014              STOP Y  AND/OR A |

    |      STRING = SALESPERSON                                                   |

    | STOP LINE 001     - 002     COL 001     - 020                               |

    |      STRING = INTRAC                                                        |

    PLEASE FILL IN RULE DEFINITION.                                        15.51.58

    Compound WHEN Statements

    This ON block uses compound WHEN statements to locate certain sections of the report. The first compound WHEN statement performs the following actions:

    1. It locates the string "SALESPERSON."
    2. Whenever this string is found, the second WHEN statement searches for the string "/" on every subsequent line.
    3. Every time the string "/" is found, the DO actions are performed. Because for third DO action the TYPE parameter is set to SU, the rule automatically totals the amount field found in columns 68 through 78, into a variable called SUM1%%SALESNO.
    4. The DO actions are stopped. The ON block searches again for the string, "SALESPERSON." When it finds the string, "INTRAC," in lines 1 through 2, this indicates a new page of the report.

      Why was a compound WHEN structure used for this operation?

      To access the different sections of the report from which to extract data, the rule needs to uniquely identify those sections. For example, the rule may be searching for the string "/" but there may be sections of the report where you do not want to extract any data. This can be done using WHEN statements, which enable the rule to easily extract data from different areas of the report, without requiring that each section have a fixed number of lines.

    Examine how this is done by looking at a sample page from the report:

    Figure 95 Sample Page of the Sales Operations Department Report

    INTRAC INC.                 SALES OPERATIONS DEPARTMENT     DATE 09/12/00 TIME 23:50     PAGE  1

     

                S A L E S     C O M M I S S I O N S    D E T A I L          FROM 01/01/00  TO  01/12/00

    | SALESPERSON   HARVEY J. JONES (197)  | INVOICE # | INVOICE DATE |   AMOUNT  | STATUS

    +-----------------------------------------------------------------------------------------------------------

    |                                      | CJ39D94   | 02/02/00     |   2040.00 |COLLECTION   |

    |                                      | CJ98443   | 03/03/00     |    245.00 |             |

    |                                      | MJ24545   | 04/04/00     |  10344.40 |             |

    |                                      | RJ10030   | 01/02/00     |   5329.39 |             |

    |                                      | RJ12233   | 02/02/00     |   5000.00 |             |

    |                                      | RJ30021   | 03/02/00     |  16670.10 |             |

    |                                      | RJ32991   | 02/03/00     |  30300.44 |             |

    |                                      | RJ33939   | 03/03/00     |    900.25 |             |

    |                                      | RJ38001   | 04/04/00     |   1000.23 |             |

    |                                      | RJ93043   | 04/04/00     |    415.89 |             |

    |+-----------------------------------------------------------------------------------------------------------

      TOTAL SALES - THIS MONTH                                           72245.70 | PAID IN FULL|

      ADJUSTMENTS                                                        -5800.70

      YTD SALES (INCLUDING THIS MONTH)                                 -127879.00

      YTD COMMISSIONS PAID                                                   0.00

      YTD COMMISSIONS OWED                                               -5115.00

      COMMISSION PAYROLL AMOUNT                                           5115.00

    1. Find the line with the salesperson named "Harvey J. Jones," and number "197." Because this line was found as a result of the first WHEN parameter specified, this is called a LEVEL 1 line.

      Look at the DO EXTRACT statements shown in Figure 94, and see how the first DO EXTRACT statement (LEVEL 1) is specified to extract the salesperson number (SALESNO). The next WHEN statement within a compound WHEN grouping would point to a LEVEL 2 line, and any other WHEN statements would point to LEVEL 3, LEVEL 4, and so on.

    2. For the salesperson Harvey J. Jones, the rule processes all detail lines that are identified with a "/" between columns 50 through 60. Because these were found as a result of the second WHEN statement in the compound WHEN parameter, it is called a LEVEL 2 line.

      Note: Because this WHEN statement is also the last WHEN statement in the compound WHEN grouping, it is also referred to as a LEVEL 0 line. LEVEL 0 always refers to the last WHEN statement specified within a compound WHEN grouping.

      As defined in the compound WHEN grouping, the number of lines of data between the LEVEL 1 line (SALESNO) and the LEVEL 0 or LEVEL 2 ("/") line may vary. That is, there can be any number of lines of data for Harvey J. Jones until the rule encounters the next SALESNO in the data it is searching.

      Also, any other lines of the report that coincidentally contain a "/" character, such as the top two lines of the report, are not processed as detail lines for Harvey J. Jones because they are not preceded by a LEVEL 1 line containing the character string "SALESPERSON."

    3. The rule searches for LEVEL 0 lines until a line containing the string "INTRAC" is found (see the top of the sample report).
  3. Now look at the next compound grouping of WHEN parameters. Place the cursor on the line beginning with the character string "WHEN LINE 005" and press PF08/PF20, or enter the DOWN command.

    Figure 96 Second Compound Grouping of WHEN Parameters

            LIBRARY : CTB.PROD.RULES                                RULE : ARWARN06

    COMMAND ===>                                                    SCROLL===> CRSR

    +---------------------------------- BROWSE -----------------------------------+

    | WHEN LINE 005     - 005     COL 002     - 014              STOP Y  AND/OR A |

    |      STRING = SALESPERSON                                                   |

    | STOP LINE 001     - 002     COL 001     - 020                               |

    |      STRING = INTRAC                                                        |

    | WHEN LINE 001     - 060     COL 001     - 020              STOP    AND/OR   |

    |      STRING = TOTAL SALES                                                   |

    |   DO EXTRACT  = SALESNO                                                     |

    |                 LEVEL 1 LINE +000 COL 0035 - 0037 PROCESS          TYP      |

    |   DO EXTRACT  = NAME%%SALESNO                                               |

    |                 LEVEL 1 LINE +000 COL 0017 - 0033 PROCESS          TYP      |

    |   DO EXTRACT  = MTHSLS%%SALESNO                                             |

    |                 LEVEL 0 LINE +000 COL 0068 - 0078 PROCESS          TYP      |

    |   DO EXTRACT  = YTDSLS%%SALESNO                                             |

    |                 LEVEL 0 LINE +002 COL 0068 - 0078 PROCESS          TYP      |

    |   DO EXTRACT  = YTDCOM%%SALESNO                                             |

    |                 LEVEL 0 LINE +003 COL 0068 - 0078 PROCESS          TYP      |

    |   DO EXTRACT  = YTDOWE%%SALESNO                                             |

    |                 LEVEL 0 LINE +004 COL 0068 - 0078 PROCESS          TYP      |

    |   DO EXTRACT  = PAYAMT%%SALESNO                                             |

    |                 LEVEL 0 LINE +005 COL 0068 - 0078 PROCESS          TYP      |

    PLEASE FILL IN RULE DEFINITION.                                        15.54.04

    This compound WHEN grouping performs the following actions:

    Every time the "TOTAL SALES" string is found, the WHEN statement performs the DO actions. Each time a value is extracted from the report, the salesperson number becomes part of the variable name. The result is a series of variables with names as follows:

    --------------------------- Salesperson -------------------------

       1                        2                         3

    NAME197                  NAME101                   NAME177

    MTHSLS197                MTHSLS101                 MTHSLS177

    YTDSLS197                YTDSLS101                 YTDSLS177

    YTDCOM197                YTDCOM101                 YTDCOM177

    YTDOWE197                YTD0WE101                 YTDOWE177

    PAYAMT197                PAYAMT101                 PAYAMT177

    Each of these variables contains data extracted from the report.

    Examining the ON Block CHKNAME

  4. Scroll forward to the bottom of the rule by pressing PF08/PF20, or by entering the DOWN command.

    Figure 97 ON Block CHKNAME

            LIBRARY : CTB.PROD.RULES                                RULE : ARWARN06

    COMMAND ===>                                                    SCROLL===> CRSR

    +---------------------------------- BROWSE -----------------------------------+

    |   DO PRINT    = ***** SERIOUS COMMISSION ERRORS *****               F   C   |

    |   DO PRINT    = ***** TOTAL NUMBER OF ERRORS %%ERRORCOUNT *****     F   C   |

    |   DO TERMINAT = NOTOK    COD 0999                                           |

    | ELSE                                                                        |

    |   DO PRINT    = %%BLANK                                             F   C   |

    |   DO PRINT    = %%BLANK                                             F   C   |

    |   DO TERMINAT = OK       COD 0000                                           |

    | =========================================================================== |

    | EXECUTE CHKNAME  UPON                                                   C   |

    | ON DATA                                                                     |

    | IF       SALESNO NE LASTSALES                                           C   |

    |   DO SET      = TOTPEOPLE=INT(TOTPEOPLE+1)                              C   |

    |   DO SET      = NUMBER%%TOTPEOPLE=SALESNO                               C   |

    |   DO SET      = LASTSALES=SALESNO                                       C   |

    | =========================================================================== |

    | EXECUTE          UPON                                                   C   |

    | ON                                                                          |

    ======= >>>>>>>>>>>>>>> END OF RULE DEFINITION PARAMETERS <<<<<<<<<<<<<<< =====

                                                                                  

                                                                                  

    PLEASE FILL IN RULE DEFINITION.                                        15.55.43

    This ON block is only performed when the salesperson number has changed during processing of the rule. The variable, SALESNO, is the actual salesperson number that is extracted from the LEVEL 1 line on the report. LASTSALES is a variable that stores the salesperson number whenever processing begins for a new salesperson.

    CHKNAME performs the following actions:

    1. Adds 1 to the count of the number of salespeople, tracked in variable TOTPEOPLE.
    2. Creates a table of salesperson numbers, which will be used later. The table, in its final form, will appear as follows:

      Variable Name               Contents

        NUMBER1                     197

        NUMBER2                     101

        NUMBER3                     177

    3. Because this is now a new salesperson being processed, set the variable LASTSALES equal to the new salesperson number.

    Examining the ON Block FINISH

    After processing the report, the rule proceeds to the next sequential ON block, FINISH, which contains most of the balancing parameters.

  5. Scroll backward using PF07/PF19, or by entering the UP command, until you see the ON block FINISH on the screen.
  6. Place the cursor on the line beginning with the character string "EXECUTE FINISH," and press PF08/PF20, or enter the DOWN command.

    Figure 98 ON Block FInish

            LIBRARY : CTB.PROD.RULES                                RULE : ARWARN06

    COMMAND ===>                                                    SCROLL===> CRSR

    +---------------------------------- BROWSE -----------------------------------+

    | EXECUTE FINISH   UPON                                                   C   |

    | ON DATA                                                                     |

    | ALWAYS                                                                      |

    |   DO SET      = I=1                                                     C   |

    |   DO PRINT    = TOTAL # OF SALESPEOPLE=%%TOTPEOPLE                  F   C   |

    |   DO PRINT    = %%BLANK                                             F   C   |

    | LABEL: TEST                                                                 |

    | IF       I GT TOTPEOPLE                                                 C   |

    |   DO GOTO     LABEL ENDJOB                                                  |

    | ELSE                                                                        |

    |   DO PRINT    = **** COMMISSION CONTROL - %%NAME%%NUMBER%%I ****    F   C   |

    |   DO PRINT    = REPORTED SALES               %%MTHSLS%%NUMBER%%I    F   C   |

    |   DO PRINT    = CALCULATED SALES                %%SUM1%%NUMBER%%I   F   C   |

    |   DO PRINT    = --------------------------------------------        F   C   |

    |   DO SET      = DIFF1=ABS(SUM1%%NUMBER%%I-MTHSLS%%NUMBER%%I)            C   |

    |   DO PRINT    = DIFFERENCE                          %%DIFF1         F   C   |

    |   DO PRINT    = --------------------------------------------        F   C   |

    |   DO SET      = COMMCALC=YTDSLS%%NUMBER%%I*0.04                         C   |

    |   DO PRINT    = REPORTED COMMISSIONS OWED    %%YTDOWE%%NUMBER%%I    F   C   |

    |   DO PRINT    = CALCULATED COMMISSIONS OWED     %%COMMCALC          F   C   |

    PLEASE FILL IN RULE DEFINITION.                                        15.56.18

The FINISH block is defined as follows:

Parent Topic

Problem 6: Balance Monthly Commissions