GENERATE
General Format
GENERATE { data-name-1  }
         { report-name1 }
Syntax Rules
1. Data-name-1 shall name a detail report group. It may be qualified by a report-name.
2. Report-name-1 may be used only if the referenced report description entry contains a CONTROL clause.
3. If data-name-1 is defined in a containing program, the report description entry in which data-name-1 is specified and the file description entry associated with that report description entry shall contain a GLOBAL clause.
4. If report-name-1 is defined in a containing program, the file description entry associated with report-name-1 shall contain a GLOBAL clause.
General Rules
1. Execution of a GENERATE data-name statement causes one instance of the specified detail to be printed, following any necessary control break and page fit processing, as detailed below.
2. Execution of a GENERATE report-name-1 statement results in the same processing as for a GENERATE data-name statement for the same report, except that no detail is printed. This process is called summary reporting. If all the GENERATE statements executed for a report between the execution of the INITIATE and TERMINATE statements are of this form, the report that is produced is called a summary report.
3. If a CONTROL clause is specified in the report description entry, each execution of the GENERATE statement causes the specified control data items to be saved and subsequently compared so as to sense for control breaks. This processing is described by the CONTROL clause.
4. Execution of the chronologically first GENERATE statement following an INITIATE causes the following actions to take place in order:
A. The report heading is printed if defined. If the report heading appears on a page by itself, an advance is made to the next physical page, and PAGE-COUNTER is either incremented by 1 or, if the report heading's NEXT GROUP clause has the WITH RESET phrase, set to 1.
B. A page heading is printed if defined.
C. If a CONTROL clause is defined for the report, each control heading is printed, wherever defined, in order from major to minor.
D. The specified detail is printed, unless summary reporting is specified.
5. Execution of any chronologically second and subsequent GENERATE statements following an INITIATE causes the following actions to take place in order:
A. If a CONTROL clause is defined for the report, and a control break has been detected, each control footing and control heading is printed, if defined, up to the level of the control break.
B. The specified detail is printed, unless summary reporting is specified.
6. If the associated report is divided into pages, the chronologically first body group since the INITIATE is preceded by a page heading, if defined, and the printing of any subsequent body groups is preceded by a page fit test which, if unsuccessful, results in a page advance, consisting of the following actions in this order:
A. If a page footing is defined it is printed.
B. An advance is made to the next physical page.
C. If the associated report description entry contains a CODE clause with an identifier operand, the identifier is evaluated.
D. If the page advance was preceded by the printing of a group whose description has a NEXT GROUP clause with the NEXT PAGE and WITH RESET phrases, PAGE-COUNTER is set to 1; otherwise PAGE-COUNTER is incremented by 1.
E. LINE-COUNTER is set to zero.
F. If a page heading is defined it is printed.
7. The report associated with data-name-1 or report-name-1 shall be in the active state. If it is not, the EC-REPORT-INACTIVE exception condition is set to exist.
8. If a non-fatal exception condition is raised during the execution of a GENERATE statement, execution resumes at the next report item, line, or report group, whichever follows in logical order.
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
                         CityCode
                         SalesPersonNum
            page limit is 66
            heading 1
            first detail 6
            last detail 42
            footing 52.
 
       01 type is report heading line number is 1.
            02 .
               03 column 12     pic x(32)
                                value "Report heading of COBOL Program".
       01 type is page heading line number is 2.
            02 .
               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".
               02 line plus 1.
                  03 column 2      pic x(4)  value "City".
                  03 column 12     pic x(11value "Salesperson".
                  03 column 28     pic x(4)  value "Sale".
               02 line plus 1.
                  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)
                              source CityName(CityCode) group indicate.
             03 column 15     pic 9
                              source SalesPersonNum  group indicate.
             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)
                              value "Total sales".
             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)
                         value "Sales, Inc.".
             03 column 45     pic x(6value "Page :".
             03 column 52     pic z9 source page-counter.
 
       01 type is report footing line number is 66.
            02 .
               03 column 12     pic x(32)
                                value "End of the COBOL Report Program".
 
        procedure division.
        Begin.
            open input SalesFile.
            open output PrintFile.
            read SalesFile
                 at end set EndOfFile to true
            end-read.
            initiate SalesReport.
            perform PrintSalaryReport
                    until EndOfFile.
            terminate SalesReport.
            close SalesFile.
            close PrintFile.
            goback.
 
        PrintSalaryReport.
            generate DetailLine.
            read SalesFile
                  at end set EndOfFile to true
            end-read.