SUM

Sum data items, and generate an internal SUM accumulator for a SOURCE or REFERENCE data field to be used in a control footing group.
Restriction: This topic applies only when the AppMaster Builder AddPack has been installed, and applies only to Windows platforms.

Syntax:

SUM|+ [IS] dataname [iterativeexpression|dataname] ...
    [UPON detlineidentifier [detlineidentifier] ...]
    [RESET [ON] [FINAL] controlname]
    [DATA-NAME [IS] fieldname]
    [PICTURE|PIC [IS] picclause]

Parameters:

dataname Data item to reference; can be report mock-up field or a Working-Storage field. Define as a numeric data item.
DATA-NAME fieldname Name a sum accumulator established by a SUM or REFERENCE clause. Do not define fieldname in Working-Storage. At generation, AMB inserts fieldname after the level number in the generated report group. DATA-NAME moves the value of the internal SUM accumulator to fieldname.

Code DATA-NAME when a SUM UPON clause references DETAIL report group, when the program references a sum accumulator, or when a sum accumulator requires a data name for qualification.

iterative expression Generate multiple SUM statements for numerically suffixed data items or elements of an array.
PIC picclause Specify the format of dataname. If dataname is a report mock-up field instead of a Working-Storage field, the next matching COBOL picture in the report mock-up is the picclause for dataname. Picclause determines the size of the internal SUM accumulator.
RESET controlname Set the SUM accumulator to zero after a control break on controlname. If RESET is not coded, the internal SUM accumulator resets to zero after each control break.
UPON detline- identifier Sum on the printing of a specific detail line, when there is more than one detail line. Detlineidentifier is the name of DETAIL report group.

Comments:

  • To set up a SUM accumulator, identify the data field with a SOURCE or REFERENCE on the detail line, and sum it with a SUM clause on the control footing line. AMB adds the value of dataname1 to its internal sum accumulator each time the dataname1 data item prints for a detail group.
  • SUM is valid for a CONTROL FOOTING report group only. It follows MOCKUP or OVERPRINT clause.
  • The internal SUM accumulator value prints with the CONTROL FOOTING group and then clears.
  • If the description for a printable data item contains a SUM clause, the internal SUM accumulator serves as a data item, that is, Report Writer moves the internal accumulator value to the data item for printing.
  • AMB sums data field values into internal SUM accumulators during GENERATE and TERMINATE processing.

Examples:

Each time DEBIT-LINE generates, add SOURCE amount to the DEBIT-LINE and CREDIT-LINE amount accumulators.

 01    DEBIT-LINE TYPE IS DETAIL.
       MOCKUP LINE 1
       SOURCE AMOUNT               PIC 9(5)
 01    CREDIT-LINE TYPE IS DETAIL.
       MOCKUP LINE 2
       SOURCE AMOUNT               PIC 9(5)
 01    TYPE IS CONTROL FOOTING WS-PRODUCT-CODE.
       MOCKUP LINE 3
       SUM AMOUNT UPON DEBIT-LINE  PIC 9(6)
       SUM AMOUNT UPON CREDIT-LINE PIC 9(6)

Print CONTROL FOOTING and RESET the SUM accumulator to zero after the final control break.

 01    TYPE IS CONTROL FOOTING WS-LOCATION-CODE.
       MOCKUP LINE 15 THRU 21
       SUM WS-QTY-IN-STOCK RESET ON FINAL

RESET the WS-LOCAL-SALES field to continue accumulating a sum until the WS-REGION-SALES control break occurs.

 RED   SALES REPORT
       CONTROLS ARE FINAL WS-REGION-SALES 
          WS-LOCAL-SALES
 01     TYPE IS CONTROL FOOTING WS-LOCAL-SALES.
       MOCKUP LINE 5
       SUM WS-LOCAL-SALES RESET ON 
           WS-REGION-SALES

Move the value of the NO-OF-SALES accumulator to the TOT-SALES field.

 01    TYPE IS CONTROL FOOTING WS-LOCATION-CODE.
       MOCKUP LINE 12
       SUM NO-OF-SALES DATA-NAME TOT-SALES

Print all values for WS-QTY-IN-STOCK on the detail line in the report and the total of those values in the control footing of the report. Print the total only for WS-NO-OF-SALES in the control footing. When the detail line is prints, add the REFERENCE field value to the SUM accumulator.

 01    DETAIL-LINE TYPE IS DETAIL.
       MOCKUP LINE 16
       SOURCE WS-QTY-IN-STOCK     PIC ZZZ,ZZ9
       REFERENCE WS-NO-OF-SALES   PIC 9999
 01    TYPE IS CONTROL FOOTING WS-LOCATION-CODE.
       MOCKUP LINES 17 THRU 23
       SUM WS-QTY-IN-STOCK        PIC Z,ZZZ,ZZ9
       SUM WS-NO-OF-SALES         PIC ZZZ9