skip to main content

Procedure Division Statements : GENERATE

GENERATE
General Format
GENERATE { data-name-1  }
Syntax Rules
1.
2.
3.
4.
General Rules
1.
2.
3.
4.
A.
B.
C.
D.
5.
A.
B.
6.
A.
B.
C.
D.
E.
F.
7.
8.
Examples
Using Generate to generate a report from Report Section
        input-output section.
        file-control.
            select SalesFile assign to "gbsales.dat"
                   organization is line sequential.
            select PrintFile assign to "salesreportb.lpt".
        file section.
        fd  SalesFile.
        01  SalesRecord.
            02 CityCode         pic 9.
            02 SalesPersonNum   pic 9.
            02 ValueOfSale      pic 9(4)V99.
        fd  PrintFile
            report is SalesReport.
        working-storage section.
        01  eof pic x value low-value.
            88 EndOfFile  value high-values.
        01  NameTable.
            02 TableValues.
               03 filler        pic x(18value "Dublin   Belfast  ".
               03 filler        pic x(18value "Cork     Galway   ".
               03 filler        pic x(18value "Sligo    Waterford".
               03 filler        pic x(9)  value "Limerick".
            02 filler redefines TableValues.
               03  CityName     pic x(9occurs 7 times.
        report section.
        rd  SalesReport
            controls are final
            page limit is 66
            first detail 6
            last detail 42
       01 type is report heading line number is 1.
               03 column 12     pic x(32)
                                value "Report heading of COBOL Program".
       01 type is page heading line number is 2.
               03 column 12     pic x(32)
                                value "An example COBOL Report Program".
            02 line plus 1.
               03 column 6      pic x(17)
                  value "Bible Salesperson".
               03 column 23     pic x(26)
                  value " - Sales and Salary Report".
                  03 column 2      pic x(4)  value "City".
                  03 column 12     pic x(11value "Salesperson".
                  03 column 28     pic x(4)  value "Sale".
                  03 column 2      pic x(4value "Name".
                  03 column 13     pic x(6value "Number".
                  03 column 28     pic x(5value "Value".
       01 DetailLine type is detail.
          02 line is plus 1.
             03 column 1      pic x(9)
             03 column 15     pic 9
             03 column 25     pic $$,$$$.99 source ValueOfSale.
       01 SalesPersonGrp
             type is control footing SalesPersonNum  next group plus 2.
          02 line is plus 1.
             03 column 15     pic x(21value "Sales for salesperson".
             03 column 37     pic 9 source SalesPersonNum.
             03 column 43     pic x value "=".
             03 sms column 45 pic $$$$$,$$$.99 sum ValueOfSale
       01 CityGrp type is control footing CityCode next group plus 2.
          02 line is plus 2.
             03 column 15     PIC X(9value "Sales for".
             03 column 25     PIC X(9) source CityName(CityCode).
             03 column 43     PIC X value "=".
             03 cs column 45  PIC $$$$$,$$$.99 sum sms
       01 TotalSalesGrp type is control footing final.
          02 line is plus 4.
             03 column 15     pic x(11)
             03 column 43     pic x value "=".
             03 column 45     pic $$$$$,$$$.99 sum cs.
        01 type is page footing.
          02 line is 53.
             03 column 1 pic x(29)
             03 column 45     pic x(6value "Page :".
             03 column 52     pic z9 source page-counter.
       01 type is report footing line number is 66.
               03 column 12     pic x(32)
                                value "End of the COBOL Report Program".
        procedure division.
            open input SalesFile.
            open output PrintFile.
                 at end set EndOfFile to true
            initiate SalesReport.
            perform PrintSalaryReport
            terminate SalesReport.
            close SalesFile.
            close PrintFile.
            generate DetailLine.
                  at end set EndOfFile to true

Copyright (c) 2017 Veryant
Contact us
Please share your comments on this manual or on any
Veryant product documentation with the email button at the top left