The SUM clause establishes a sum counter and names the data items to be summed.
General Format
Syntax Rules
- The data item that is the subject of the report group description entry in which the SUM clause appears must not be defined as alphabetic. Identifier-1 must reference a numeric data item. If identifier-1 is defined in the report section, identifier-1 must reference a sum counter.
If the UPON phrase is omitted, any identifiers in the associated SUM clause which are themselves sum counters must be defined either in the same report group that contains this SUM clause or in a report group which is at a lower level in the control hierarchy of this report.
If the UPON phrase is specified, any identifiers in the associated SUM clause must not be sum counters.
- Data-name-1 must be the name of a DETAIL report group described in the same report as the CONTROL FOOTING report group in which the SUM clause appears. Data-name-1 can be qualified by a report-name.
- A SUM clause can appear only in the description of a CONTROL FOOTING report group.
- Data-name-2 must be one of the data-names specified on the CONTROL clause for this report. Data-name-2 must not be a lower level control than the associated control for the report group in which the RESET phrase appears.
FINAL, if specified in the RESET phrase, must also appear in the CONTROL clause for this report.
This rule is not enforced.
- The highest permissible qualifier of a sum counter is the report-name.
General Rules
- The SUM clause establishes a sum counter. The sum counter is a numeric data item with an optional sign. At object time, the RWCS adds into the sum counter the value in each data item referenced by identifier-1. This addition is consistent with the rules for arithmetic statements. (See the sections Arithmetic Statements and Overlapping Operands.)
- The size of the sum counter is equal to the number of receiving character positions specified by the PICTURE clause that accompanies the SUM clause in the description of the elementary item.
- Only one sum counter exists for an elementary report entry regardless of the number of SUM clauses specified in the elementary report entry.
- If the elementary report entry for a printable item contains a SUM clause, the sum counter serves as a source data item. The RWCS moves the data contained in the sum counter, according to the rules of the MOVE statement, to the printable item for presentation.
- If a data-name appears as the subject of an elementary report entry that contains a SUM clause, the data-name is the name of the sum counter; the data-name is not the name of the printable item that the entry can also define.
- It is permissible for Procedure Division statements to alter the contents of sum counters.
- Addition of the values of the data items referenced by identifiers into sum counters is performed by the report writer control system during the execution of GENERATE and TERMINATE statements. There are three categories of sum counter incrementing called subtotalling, crossfooting, and rolling forward. Subtotalling is accomplished only during execution of GENERATE statements and after any control break processing but before processing of the DETAIL report group. (See the section The GENERATE Statement.) Crossfooting and rolling forward are accomplished during the processing of CONTROL FOOTING report groups. (See the section The TYPE Clause.)
- The UPON phrase provides the capability to accomplish selective subtotalling for the DETAIL report groups named in the phrase.
- The RWCS adds each individual addend into the sum counter at a time that depends upon the characteristics of the addend.
- When the addend is a sum counter defined in the same CONTROL FOOTING report group, then the accumulation of that addend into the sum counter is termed crossfooting.
Crossfooting occurs when a control break takes place and at the time the CONTROL FOOTING report group is processed.
Crossfooting is performed according to the sequence in which sum counters are defined in the CONTROL FOOTING report group. That is, all crossfooting into the first sum counter defined in the CONTROL FOOTING report group is completed, and then all crossfooting into the second sum counter defined in the CONTROL FOOTING report group is completed.
When one of the addends is the sum counter defined by the data description entry in which that SUM clause appears, the initial value of that sum counter at the time of summation is used in the summing operation.
- When the addend is a sum counter defined in a lower level CONTROL FOOTING report group, then the accumulation of that addend into the sum counter is termed rolling forward. A sum counter in a lower level CONTROL FOOTING report group is rolled forward when a control break occurs and at the time that the lower level CONTROL FOOTING report group is processed.
- When the addend is not a sum counter the accumulation into a sum counter of such an addend is called subtotalling. If the SUM clause contains the UPON phrase, the addends are subtotalled when a GENERATE statement for the designated DETAIL report group is executed. If the SUM clause does not contain the UPON phrase, the addends which are not sum counters are subtotalled when any GENERATE data-name statement is executed for the report in which the SUM clause appears.
- If two or more of the identifiers specify the same addend, then the addend is added into the sum counter as many times as the addend is referenced in the SUM clause. It is permissible for two or more of the data-names to specify the same DETAIL report group. When a GENERATE data-name statement for such a DETAIL report group is given, the incrementing occurs repeatedly, as many times as data-name appears in the UPON phrase.
- The subtotalling that occurs when a GENERATE report-name statement is executed is discussed in the appropriate paragraph. (See the section The GENERATE Statement.)
- In the absence of an explicit RESET phrase, the report writer control system will set a sum counter to zero at the time that the report writer control system is processing the CONTROL FOOTING report group in which the sum counter is defined. If an explicit RESET phrase is specified, then the report writer control system will set the sum counter to zero at the time that the report writer control system is processing the designated level of the control hierarchy. (See the section The TYPE Clause.)
Sum counters are initially set to zero by the report writer control system during the execution of the INITIATE statement for the report containing the sum counter.