Menu ▾ ▴

#529 Report Writer SUM clause: accept UPON with RESET, several UPON details, repeated SUM and ROUNDED

unclassified
open
nobody
None
5 - default
2026-11-05
2026-11-05
No

The Programmer's Guide (6.9.40 SUM) documents SUM OF {identifier|literal}... [RESET ON ... | UPON identifier], which is what cobc accepts; ISO allows more. We would like cobc to accept four standard forms of the report writer SUM clause that it refuses today: RESET after an UPON phrase, an UPON phrase naming the same detail twice, a second SUM keyword in one clause, and ROUNDED.

To reproduce

sumf.cob (attached, free format). The RESET ON FINAL item is in the footing for WS-K, which is below FINAL:

IDENTIFICATION DIVISION.
PROGRAM-ID. SUMF.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT RPT-FILE ASSIGN TO "sumf.out".
DATA DIVISION.
FILE SECTION.
FD RPT-FILE REPORT IS RPT-A.
WORKING-STORAGE SECTION.
01 WS-A PIC 99 VALUE 12.
01 WS-B PIC 99 VALUE 5.
01 WS-K PIC X VALUE "K".
REPORT SECTION.
RD RPT-A
CONTROLS ARE FINAL WS-K
PAGE LIMIT IS 20 LINES.
01 RPT-DET TYPE IS DETAIL LINE PLUS 1.
05 COLUMN 1 PIC 99 SOURCE IS WS-A.
01 TYPE CONTROL FOOTING WS-K LINE PLUS 1.
05 COLUMN 1 PIC 999 SUM OF WS-A UPON RPT-DET RESET ON FINAL.
01 TYPE CONTROL FOOTING FINAL LINE PLUS 1.
05 COLUMN 5 PIC 999 SUM OF WS-A UPON RPT-DET RPT-DET.
05 COLUMN 9 PIC 999 SUM OF WS-A SUM OF WS-B.
05 COLUMN 13 PIC 999 SUM OF WS-A ROUNDED.
PROCEDURE DIVISION.
OPEN OUTPUT RPT-FILE
INITIATE RPT-A
GENERATE RPT-DET
GENERATE RPT-DET
TERMINATE RPT-A
CLOSE RPT-FILE
STOP RUN.
cobc -x -free -std=cobol2014 -fno-diagnostics-show-caret sumf.cob

What happens

3.2.0 and 3.3-dev r5751 both print

sumf.cob:21: error: syntax error, unexpected RESET, expecting DISPLAY or DISPLAY-1 or NATIONAL or UTF-8
sumf.cob:23: error: syntax error, unexpected Identifier, expecting DISPLAY or DISPLAY-1 or NATIONAL or UTF-8
sumf.cob:24: error: duplicate SUM clause
sumf.cob:25: error: syntax error, unexpected ROUNDED, expecting DISPLAY or DISPLAY-1 or NATIONAL or UTF-8

and the same with -std=default and cobol2002.

What should happen

We ask that cobc accept the clause as the standard writes it. ISO/IEC 1989:2023 13.18.54.2 writes the clause as { SUM OF addend ... [ UPON { data-name-2 } ... ] } ... [ RESET ON { data-name-3 | FINAL } ] [ rounded-phrase ], and 13.18.54.3 rule 1 says "The whole clause is referred to as a SUM clause even though the SUM keyword may appear more than once." By 13.18.54.4 rule 7, an UPON addend is added only when a detail it names is generated, once per naming; by rule 2, a counter with RESET is reset only at the footing for the level it names. With these forms the program would compile, and sumf.out would hold 12 twice, the WS-K footing 024, and the final footing 048 034 024. The same in 2002 (with [ ROUNDED ]) and in the 2014 FCD.

Why it happens

In cobc/parser.y, sum_clause_list is SUM _of report_x_list _reset_clause, and _reset_clause is either RESET _on data_or_final or UPON identifier: one SUM phrase, one UPON name or a RESET, no ROUNDED, and no expressions in report_x_list. A second SUM is a second clause to check_repeated.

Proposed fix

We have no patch: the fix is wider than the grammar. Each SUM phrase needs its own UPON list, repeats kept; each counter needs its RESET level and a ROUNDED flag, so new members in cob_report_sum and cob_report_sum_ctr.

  • bugs #768 mentions SUM FSM-1 SUM FSM-2 SUM FSM-3 in passing; its subject is a zero total at CONTROL FINAL.
  • bugs #775 uses RESET on a data-name; its comments report a codegen.c cast failure on that operand with internal checks on.

Details

GnuCOBOL 3.2.0 (Ubuntu gnucobol3 3.2-4build1) and 3.3-dev r5751 (CI snapshot 3.3-dev.138 of 2026-10-29), x86_64 Linux, both run 2026-11-04.

1 Attachments

Discussion


Log in to post a comment.