Hello,
suppose you have this defined in a COBOL program using Report Writer Module:
01 CF-MM TYPE CONTROL FOOTING WS-MM.
02 LINE PLUS 1.
03 COLUMN 1 VALUE "* CF MONTH: ".
03 COLUMN PLUS 1 PIC 99 SOURCE WS-MM.
03 S-MM COLUMN PLUS 5 PIC S9(4)V99 SUM WS-TUTION-PAY.
03 VAL-NN COLUMN PLUS 5 PIC S9(4)V99 SOURCE S-MM.
<...>
PROCEDURE DIVISION.
DECLARATIVES.
SEC2 SECTION.
USE BEFORE REPORTING
CF-MM.
DISPLAY "SUM MM LEVEL:" S-MM
.
Furthermore, suppose that the program reported 3 lines where SUM WS-TUTION-PAY resulted in 126.
What would be the value resulting from the statement in SEC2 SECTION that displays S-MM value? I guess it should be 126 but I am getting ZERO displayed. This maybe because the value 126 was not yet moved to S-MM, but I am not sure.
What is the value that "should" be displayed in the declaratives section for S-MM?
--
I posted the above as a question in
https://stackoverflow.com/questions/69590695/ and got the answer as a the code below and execution results showing S-MM to have the expected non-zero value when displayed from DECLARATIVES BEFORE REPORTING.... However, running the same code with GNU COBOL 3.1.2 on Windows 10 64-bit CPU, I got zeroes. This also occurs when I run my own code.
This is an important requirement since GNU COBOL does not support computer expressions in COLUMN clause. The programmer has no other resort for calculations except in BEFORE REPORTING. As an example, to find the Maximum of a column of data to appear in control footing.
Test Code:
*> cobc.exe rx.cbl -free -Wall -x -o rx.EXE
IDENTIFICATION DIVISION.
program-id. rw-test.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL. *> only needed if not compiling with -std=mf-strict
select report-file assign "rpt.txt"
organization line sequential.
data division.
file section.
fd report-file
report is report-1.
working-storage section.
01 n comp pic 99 value 0.
01 test-table.
02 test-data.
03 pic 9999 value 1001.
03 pic 9999 value 1002.
03 pic 9999 value 1003.
03 pic 9999 value 2004.
03 pic 9999 value 2005.
03 pic 9999 value 2006.
02 test-entry redefines test-data pic 9999 occurs 6.
01 report-entry.
03 test-group pic 9.
03 test-value pic 999.
report section.
rd report-1
control is test-group
page limit 50 lines *> MANDATORY for GnuCOBOL
.
01 rw-detail type de.
02 line plus 1.
03 grp column 1 pic 9 source test-group.
03 val column 4 pic zz9 source test-value.
01 rw-foot type cf test-group.
02 line plus 1.
03 column 1 pic x(6) value "- ---".
02 line plus 1.
03 column 1 pic 9 source test-group.
03 s-mm column 4 pic zz9 *> s.mm defined
sum test-value
reset test-group.
02 line plus 1 pic x value space.
procedure division.
declaratives.
decl-rpt section.
use before reporting rw-foot.
display s-mm. *> s.mm referenced
end declaratives.
main-line section.
open output report-file.
initiate report-1
perform varying n from 1 by 1
until n > 6
move test-entry (n) to report-entry
generate rw-detail
end-perform
terminate report-1
close report-file
stop run.
end program rw-test.
Should now be fixed in trunk revision 4505
Diff:
The main part was fixed by Ron with [r4505] (in trunk), but there is one big issue: the page limit is mandatory, otherwise we get runtime error as follows:
The clearly standard says
and that's also the way MF handles this.
GC 3.2.1 compiles this fine, but outputs only "6" instead of "6 + 15"; but if internal checks are enabled we have a codegen error (at least with current GC3.x):
The test from r4505 is also not in GC3, so I plan to merge that very soon (if still needed, but I guess not, then the list cast part will be handled as well), then adding a follow-up commit for the optional page length.
The "optional" headers are only necessary if not compiled with
-std=mf-strict(or most other non-standard dialects - adding-frelax-syntaxis enough and included there).Related
Commit: [r4505]