[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP COBOL
User Manual


Previous Contents Index


                1         2         3         4         5
column 1234567890123456789012345678901234567890123456789012345
       TOTAL SALES FOR YEAR-TO-DATE WAS            953208.90

10.8.11 Defining and Incrementing Totals

In addition to using either the VALUE or SOURCE clause to assign a value to a report item, you can use the SUM clause to accumulate values of report items. This clause establishes a sum counter that is automatically summed during the processing of the report. You code a SUM clause only in a TYPE CONTROL FOOTING report group.

The identifiers of the SUM clause are either elementary numeric data items not in the Report Section or other sum counters in the Report Section that are at the same or lower level in the control hierarchy of the report, as specified in the CONTROL clause.

The SUM clause provides three forms of sum accumulation: subtotaling, crossfooting, and rolling-forward. These forms are detailed in this section. See Section 10.3 for further discussion.

10.8.11.1 Subtotaling

In subtotaling, the SUM clause references elementary numeric data items that appear in the File or Working-Storage Sections and then generates sums of those items.

In the following example, EACH-WEEK represents a CONTROL clause name. COST represents a numeric data item in the File Section that indicates weekly expenses for a company. DAY and MONTH indicate the particular day and month.


01   TYPE CONTROL FOOTING EACH-WEEK.
     02  LINE PLUS 2.
        03  COLUMN 1   PIC IS X(30)
            VALUE IS   "TOTAL EXPENSES FOR WEEK/ENDING".
        03  COLUMN 33  PIC IS X(4)  SOURCE IS MONTH.
        03  COLUMN 39  PIC IS X(2)  SOURCE IS DAY.
        03  WEEK-AMT   COLUMN 45
                       PIC ZZ9.99 SUM COST.

This example produces the following subtotal output:


                1         2         3         4         5
column 12345678901234567890123456789012345678901234567890
       TOTAL EXPENSES FOR WEEK/ENDING  JULY  02    799.23

When the value of EACH-WEEK changes, a control break occurs that causes this TYPE CONTROL FOOTING report group to print. The value of the sum counter is edited according to the PIC clause accompanying the SUM clause. Then the sum lines are printed in the location specified by the items' LINE and COLUMN clauses.

10.8.11.2 Crossfooting

In crossfooting, the SUM clause adds all the sum counters in the same CONTROL FOOTING report group and automatically creates another sum counter.

In the following example, the CONTROL FOOTING group shows both subtotaling (SALES-1) and crossfooting (SALES-2):


01  TYPE DETAIL LINE PLUS 1.
    05  COLUMN 15 PIC 999.99 SOURCE BRANCH1-SALES.
    05  COLUMN 25 PIC 999.99 SOURCE BRANCH2-SALES.

01  TYPE CONTROL FOOTING BRANCH-TOTAL LINE PLUS 2.
    05  SALES-1  COLUMN 15 PIC 999.99 SUM BRANCH1-SALES.
    05  SALES-2  COLUMN 25 PIC 999.99 SUM BRANCH2-SALES.
    05  SALES-TOT  COLUMN 50 PIC 999.99 SUM SALES-1, SALES-2.

The SALES-1 sum contains the total of the BRANCH1-SALES column and the SALES-2 sum contains the total of the BRANCH2-SALES column (both sums are subtotals). SALES-TOT contains the sum of SALES-1 and SALES-2; it is a crossfooting.

The crossfooting ouput is as follows:


                1         2         3         4         5         6
column 123456789012345678901234567890123456789012345678901234567890
                     125.00    300.00                   425.00

10.8.11.3 Rolling Forward

When rolling totals forward, the SUM clause adds a sum counter from a lower-level CONTROL FOOTING report group to a sum counter in a higher-level footing group. The control logic and necessary control hierarchy for rolling counters forward begins in the CONTROL clause.

In the following example, WEEK-AMT is a sum counter found in the lower-level CONTROL FOOTING group, EACH-WEEK. This sum counter is named in the SUM clause in the higher-level CONTROL FOOTING report group, EACH-MONTH. The value of each WEEK-AMT sum is added to the higher-level counter just before the lower-level CONTROL FOOTING group is printed.


RD   EXPENSE-FILE.
     .
     .
     .
     CONTROLS ARE EACH-MONTH, EACH-WEEK.
01   TYPE CONTROL FOOTING EACH-WEEK.
     02  LINE PLUS 2.
        03  COLUMN 1             PIC IS X(30)
            VALUE IS             "TOTAL EXPENSES FOR WEEK/ENDING".
        03  COLUMN 33            PIC IS X(9)    SOURCE IS MONTH.
        03  COLUMN 42            PIC IS X(2)    SOURCE IS DAY.
        03  WEEK-AMT             COLUMN 45
                                 PIC ZZ9.99     SUM COST.

01   TYPE CONTROL FOOTING EACH-MONTH.
     02  LINE PLUS 2.
        03  COLUMN 10  PIC X(18)  VALUE IS "TOTAL EXPENSES FOR".
        03  COLUMN 29  PIC X(9)   SOURCE MONTH.
        03  COLUMN 50  PIC ZZ9.99 SUM WEEK-AMT.

The following output is a result of rolling the totals forward:


                1         2         3         4         5
column 1234567890123456789012345678901234567890123456789012345
       TOTAL EXPENSES FOR DECEMBER             379.19

10.8.11.4 RESET Option

When a CONTROL FOOTING group is printed, the SUM counter in that group is automatically reset to zero. If you want to specify when a SUM counter is reset to zero, use the RESET phrase. RESET names a data item in a higher-level CONTROL FOOTING that will cause the SUM counter to be reset to zero. RESET is used only with a SUM clause.

The following example sums SALES, resetting the counter to zero only when it encounters a new year (YEAR). This prevents the sum from being reset to zero when a new month causes a control break, giving a running total of the months within the year.


RD   SALES-REPORT.
     .
     .
     .
     CONTROLS ARE YEAR, EACH-MONTH, EACH-WEEK.

     .
     .
     .
01   TYPE CONTROL FOOTING EACH-MONTH
     02  COLUMN 10   PIC ZZ9.99  SUM SALES RESET ON YEAR.

10.8.11.5 UPON Option

Another SUM option is the UPON phrase. This phrase allows selective subtotaling for the DETAIL Report Group named in the phrase. When you use the UPON phrase, you cannot reference the sum counter in the SUM clause. You can use any File or Working-Storage Section elementary numeric data item.

When you code the UPON option with the SUM clause, the value of the data items of the SUM clause will be added whenever the TYPE DETAIL report group you name in the UPON option is generated.


WORKING-STORAGE SECTION.
     .
     .
     .
01   WORK-AREA.
     .
     .
     .
     03  ADD-COUNTER            PIC 9     VALUE 1.

REPORT SECTION.
     .
     .
     .
01   FIRST-DETAIL-LINE TYPE IS DETAIL LINE IS PLUS 2.
     .
     .
     .
01   TYPE IS CONTROL FOOTING FINAL.

     05  LINE IS PLUS 3.
     .
     .
     .
     05  LINE PLUS 2.
         10  COLUMN 5           PIC Z(3)9  SUM ADD-COUNTER
                                           UPON FIRST-DETAIL-LINE.

In the preceding example, the value of ADD-COUNTER is added to the CONTROL FOOTING FINAL counter every time the FIRST-DETAIL-LINE report group is generated.

10.8.12 Restricting Print Items

In a Report Writer program, the GROUP INDICATE clause eliminates repeated information from report detail lines by allowing an elementary item in a DETAIL report group to be printed only the first time after a control or page break. The following example illustrates the use of this clause:


01  DETAIL-LINE TYPE DETAIL LINE PLUS 1.

    05  COLUMN 1 GROUP INDICATE PIC X(6) VALUE "SALES:".
*       (prints only the first time after a control or page break)

    05  COLUMN 10 PIC X(10) SOURCE BRANCH.
*         (prints each time)

These statements produce the following lines:


SALES:   BRANCH-A

         BRANCH-B

         BRANCH-C

The next two examples are nearly identical programs; the only difference is the use of the GROUP INDICATE clause in the second example.

The following program does not contain a GROUP INDICATE clause:


                   01   DETAIL-LINE TYPE IS DETAIL
                                   LINE IS PLUS 1.
                        02  COLUMN 1  PIC X(15)
                                   SOURCE A-NAME.
                        02  COLUMN 20 PIC 9(6)
                                   SOURCE A-REG-NO.

It produces the following output:


                            1         2         3
                   123456789012345678901234567890
                   Name               Registration
                                      Number

                   Rolans  R.         123456
                   Rolans  R.         123457
                   Rolans  R.         123458
                   Vencher R.         654321
                   Vencher R.         654322
                   Vencher R.         654323
                   Vencher R.         654324
                   Anders J.          987654
                   Anders J.          987655
                   Anders J.          987656

The following example contains a GROUP INDICATE clause:


                   01   DETAIL-LINE TYPE IS DETAIL
                                   LINE IS PLUS 1.
                        02  COLUMN 1  PIC X(15)
                                   SOURCE A-NAME
                                   GROUP INDICATE.
                        02  COLUMN 20  PIC 9(6)
                                   SOURCE A-REG-NO.


Previous Next Contents Index