Menu ▾ ▴

#775 REPORT WRITER - COLUMN defined with SUM contains ZERO in DECLARATIVES SECTION BEFORE REPORTING

GC 3.x
accepted
3
2025-12-30
2021-10-16
Emmad
No

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.

Discussion

  • Ron Norman

    Ron Norman - 2021-12-30

    Should now be fixed in trunk revision 4505

     
  • Simon Sobisch

    Simon Sobisch - 2025-12-30
    • labels: --> report writer, PAGE LIMIT, DECLARATIVES, internal compiler error
    • summary: COBOL REPORT WRIER - COLUMN defined with SUM contains ZERO in DECLARTIVES SECTION BEFORE REPORTING --> REPORT WRITER - COLUMN defined with SUM contains ZERO in DECLARATIVES SECTION BEFORE REPORTING
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,7 +1,7 @@
     Hello,
     suppose you have this defined in a COBOL program using Report Writer Module:
    
    -~~~
    +```cobolfree
     01 CF-MM TYPE CONTROL FOOTING WS-MM.
                  02 LINE PLUS 1.
                     03 COLUMN 1             VALUE &#34;* CF MONTH: &#34;.
    @@ -17,84 +17,84 @@
                 CF-MM.
                 DISPLAY &#34;SUM MM LEVEL:&#34; S-MM   
                .
    -~~~
    -Furthermore, suppose that the program reported 3 lines where SUM WS-TUTION-PAY resulted in 126.
    +```
    +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 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 &#34;should&#34; be displayed in the declaratives section for S-MM?
    
     --
    -I posted the above as a question above  in
    -https://stackoverflow.com/questions/69590695/could-you-reference-a-column-in-declaratives-section-when-the-column-is-used-wit/69591957#69591957 
    -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 DECLARTIVES 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.
    +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:
    
    +```cobolfree
        *&gt; cobc.exe rx.cbl -free -Wall -x -o rx.EXE
    
    -IDENTIFICATION DIVISION.
    -program-id. rw-test.
    -environment division.
    -input-output section.
    
    -   select report-file assign &#34;rpt.txt&#34;
    -       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.
    -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 &#34;-  ---&#34;.
    - 02 line plus 1.
    -   03 column 1 pic 9 source test-group.
    -   03 s-mm column 4 pic zz9        *&gt; 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.               *&gt; s.mm referenced
    -end declaratives.
    -main-line section.
    -   open output report-file.
    -   initiate report-1
    -   perform varying n from 1 by 1
    -   until n &gt; 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.
    + IDENTIFICATION DIVISION.
    +    program-id. rw-test.
    +    ENVIRONMENT DIVISION.
    +    INPUT-OUTPUT SECTION.
    +    FILE-CONTROL.  *&gt; only needed if not compiling with -std=mf-strict
    +       select report-file assign &#34;rpt.txt&#34;
    +           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     *&gt; 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 &#34;-  ---&#34;.
    +     02 line plus 1.
    +       03 column 1 pic 9 source test-group.
    +       03 s-mm column 4 pic zz9        *&gt; 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.               *&gt; s.mm referenced
    +   end declaratives.
    +   main-line section.
    +       open output report-file.
    +       initiate report-1
    +       perform varying n from 1 by 1
    +       until n &gt; 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.
    +```
    
    • status: open --> accepted
    • assigned_to: Simon Sobisch
    • Group: unclassified --> GC 3.x
    • Priority: 5 - default --> 3
     
  • Simon Sobisch

    Simon Sobisch - 2025-12-30

    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:

    libcob: error: INITIATE report-1 LINE 1 exceeds PAGE LIMIT
    libcob: error: GENERATE report-1 but no INITIATE was done
    libcob: warning: implicit CLOSE of report-file ('rpt.txt')
    

    The clearly standard says

    if not specified, the report consists of a single page of indefinite length

    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):

    cobc: ../../cobc/codegen.c:10548: invalid cast from 'test-group' type REFERENCE to type LIST
    

    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-syntax is enough and included there).

     

    Related

    Commit: [r4505]


Log in to post a comment.