Zug
Zug

Reputation: 194

How to print nested Control Headings using Report Writer and GnuCOBOL?

I'm trying to create a report declared in the "report section" of a COBOL program. The program takes the data.txt file as input, and writes the report to the report.txt file. Here you can see the COBOL source code followed by the content of the input file:

       IDENTIFICATION DIVISION.
       PROGRAM-ID. PROGRAM.

      *
       ENVIRONMENT DIVISION.
      *

       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT F-DATA
               ASSIGN TO 'data.txt'
               LINE SEQUENTIAL.
           SELECT F-REPORT
               ASSIGN TO 'report.txt'
               LINE SEQUENTIAL.

      *
       DATA DIVISION.
      *

       FILE SECTION.
       FD F-DATA.
       01 R-DATA.
           05 GRP       PIC A(01).
           05 NAME      PIC X(04).
           05 SCORE     PIC 9(02).
           05 FILLER    PIC X(72).
       FD F-REPORT
           REPORT IS REP.

       WORKING-STORAGE SECTION.
       77 FS-DATA       PIC 9(02).
       77 FS-REPORT     PIC 9(02).
       77 EOF           PIC A(01).

       REPORT SECTION.
       RD REP
           PAGE LIMIT 10
           CONTROLS ARE GRP NAME.
       01 TYPE CH FOR GRP.
           02 LINE +1.
               03 COL  1 PIC A(05) VALUE 'GROUP'.
               03 COL +2 PIC A(01) SOURCE GRP.
       01 TYPE CH FOR NAME.
           02 LINE +1.
               03 COL  3 PIC X(16) SOURCE NAME.
       01 DET TYPE DE.
           02 LINE +1.
               03 COL  5 PIC 9(02) SOURCE SCORE.
       01 TYPE CF FOR NAME.
           02 LINE +1.
               03 COL  3 PIC A(05) VALUE 'TOTAL'.
               03 COL +2 PIC X(04) SOURCE NAME.
               03 COL +2 PIC X(01) VALUE '='.
               03 COL +2 PIC 9(02) SUM OF SCORE.
       01 TYPE CF FOR GRP.
           02 LINE +1.
               03 COL  1 PIC A(11) VALUE 'TOTAL GROUP'.
               03 COL +2 PIC A(01) SOURCE GRP.
               03 COL +2 PIC X(01) VALUE '='.
               03 COL +2 PIC 9(02) SUM OF SCORE.

      *
       PROCEDURE DIVISION.
      *

       P-MAIN.
           MOVE 'N' TO EOF
           OPEN INPUT F-DATA
           OPEN OUTPUT F-REPORT
           INITIATE REP
           PERFORM P-READ
           PERFORM UNTIL EOF = 'Y'
               GENERATE DET
               PERFORM P-READ
           END-PERFORM
           TERMINATE REP
           CLOSE F-REPORT
           CLOSE F-DATA
           STOP RUN
           .

       P-READ.
           READ F-DATA
               AT END MOVE 'Y' TO EOF
           END-READ
           .
AJOHN01
AJOHN10
AJACK02
AJACK20

The program is compiled and executed with the following command:

cobc -xj program.cob

Here is the actual content of the output file:

  JOHN
GROUP A
    01
    10
  TOTAL JOHN = 11
  JACK
    02
    20
  TOTAL JACK = 22
TOTAL GROUP A = 33

And the content I expected:

GROUP A
  JOHN
    01
    10
  TOTAL JOHN = 11
  JACK
    02
    20
  TOTAL JACK = 22
TOTAL GROUP A = 33

Am I doing something wrong?

My version of GnuCOBOL is 4.0-early-dev.0 (GnuCOBOL 3.2 crashes after printing "unexpected tree category").

sudo apt install gnucobol4

Upvotes: 1

Views: 98

Answers (0)

Related Questions