[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP COBOL
User Manual


Previous Contents Index

With the GROUP INDICATE clause, the program produces the following output:


                            1         2         3
                   123456789012345678901234567890
                   Name               Registration
                                      Number

                   Rolans  R.         123456
                                      123457
                                      123458
                   Vencher R.         654321
                                      654322
                                      654323
                                      654324
                   Anders J.          987654
                                      987655
                                      987656

10.8.13 Processing a Report Writer Report

In a Report Writer program, you usually use the following five statements:

  • INITIATE
  • GENERATE
  • TERMINATE
  • USE BEFORE REPORTING
  • SUPPRESS

You must use the INITIATE, GENERATE, and TERMINATE statements. The USE BEFORE REPORTING and the SUPPRESS statements are optional.

Before any Report Writer statement is executed, the report file must be open.

10.8.13.1 Initiating the Report

The INITIATE statement begins the report processing and is executed before any GENERATE or TERMINATE statements. The report name used in this statement is specified in the RD entry in the Report Section and in the REPORT clause of the FD entry for the file to which the report is written.

INITIATE sets PAGE-COUNTER to 1, LINE-COUNTER to zero, and all SUM counters to zero.

This program code uses the code in Section 10.8.2.


PROCEDURE DIVISION.
     .
     .
     .
MAIN SECTION.
000-START.
     OPEN INPUT CUSTOMER-FILE.
     OPEN OUTPUT PRINTER-FILE.
     .
     .
     .
     INITIATE MASTER-LIST.

A second INITIATE statement for the same report must not be executed until a TERMINATE statement for the report has been executed (see Section 10.8.13.4).

10.8.13.2 Generating a Report Writer Report

The GENERATE statement prints the report.

You can produce either detail or summary reports depending on the GENERATE identifier. If you code the name of a DETAIL report group with GENERATE, you create a detail report; if you code a report name with GENERATE, you create a summary report.

10.8.13.3 Automatic Operations of the GENERATE Statement

When the first GENERATE statement is executed, the following report groups are printed, if they are specified in the program:

  • REPORT HEADING report group
  • PAGE HEADING report group
  • CONTROL HEADING report groups
  • For detail reporting, the specified TYPE DETAIL report group

A USE BEFORE REPORTING declarative can also execute just before the associated report group is produced, to produce a cover page for the report, for example.

Note

Figure 10-11 and Figure 10-12 illustrate the major flow of operations, but do not cover all possible operations associated with a GENERATE statement.

Figure 10-11 shows the sequence of operations for the first GENERATE statement.

Figure 10-11 First GENERATE Statement


For subsequent GENERATE statements in the program, the following operations take place:

  • Any USE BEFORE REPORTING declaratives execute just before the associated report group is produced.
  • Any specified control breaks occur.
  • CONTROL FOOTING and CONTROL HEADING report groups print after the specified control breaks occur.
  • In a detail report, the TYPE DETAIL report groups print.
  • SUM operands are incremented.
  • Sum counters are reset as specified.

Figure 10-12 shows the sequence of operations for all GENERATE statements except the first. See Figure 10-11 for a comparison with the sequence of operations for the first GENERATE statement.

Figure 10-12 Subsequent GENERATE Statements


10.8.13.4 Ending Report Writer Processing

The TERMINATE statement completes the processing of a report.

Like INITIATE, the TERMINATE statement report name is specified in the RD entry in the Report Section and in the REPORT clause of the FD entry for the file to which the report is written.

When the TERMINATE statement is executed, breaks occur for all control fields, and all control footings are written; any page footings and report footings are also written.


PROCEDURE DIVISION.
.
.
.
300-END-OF-FILE.
    TERMINATE MASTER-LIST.
    CLOSE CUSTOMER-FILE, PRINTER-FILE.
    STOP RUN.

If no GENERATE statement has been executed for the report, the TERMINATE statement does not produce any report groups.

A second TERMINATE statement for the report must not be executed before a second INITIATE statement for the report has been executed.

The TERMINATE statement does not close the report file; a CLOSE statement must be executed after the TERMINATE statement.

Figure 10-13 shows the sequence of operations for TERMINATE.

Figure 10-13 TERMINATE Statement


10.8.13.5 Applying the USE BEFORE REPORTING Statement

In a COBOL program, you specify a Declarative section to define procedures that supplement the standard procedures of the program. Note that in a Report Writer program, you can specify the USE BEFORE REPORTING statement. This USE BEFORE REPORTING statement gives you more control over the data to be printed in a Report Writer program.

The USE BEFORE REPORTING statement:

  • Allows you to define declarative procedures
  • Causes those procedures to be executed just before a specified report group is printed (this specified report group name is written with the USE statement)
  • Lets you modify the data to be printed (for example, where simple sum operations must be augmented by more complex operations involving multiplication, division, and subtraction)
  • Lets you suppress printing the report group

The following example indicates that the phrase BEGINNING-OF-REPORT is to be displayed just before the REPORT HEADING group named REPORT-HEADER; the phrase END-OF-REPORT is to be displayed just before the REPORT FOOTING group called REPORT-FOOTER.


PROCEDURE DIVISION.
DECLARATIVES.
BOR SECTION.
     USE BEFORE REPORTING REPORT-HEADER.
BOR-A.
     DISPLAY "BEGINNING-OF-REPORT".
EOR SECTION.
     USE BEFORE REPORTING REPORT-FOOTER.
EOR-A.
     DISPLAY "END-OF-REPORT".
END DECLARATIVES.

Note that you cannot use INITIATE, GENERATE, or TERMINATE in a Declarative procedure.

10.8.13.6 Suppressing a Report Group

You can also use the SUPPRESS statement in a USE BEFORE REPORTING procedure to suppress the printing of a report group. For example, you can suppress printing of an unnecessary total line, such as a line for a monthly sales total that has only one sale or a line of zeros.

The SUPPRESS statement nullifies any NEXT GROUP and LINE clauses, but leaves the LINE-COUNTER value unchanged.

Note that the SUPPRESS statement applies only to that particular instance of the report group; that group will be printed the next time unless the SUPPRESS statement is executed again.

The SUPPRESS statement has no effect on sum counters.

10.8.14 Selecting a Report Writer Report Type

You can print two types of reports using the Report Writer feature. In a detail report, you print primary data information as well as totals. In a summary report, you print only control heading and footing information (such as report data headings and totals) and exclude detail input record information.

Section 10.9 provides examples of detail and summary reports.

10.8.14.1 Detail Reporting

In detail reporting, at least one printable TYPE DETAIL report group must be specified. A GENERATE statement produces the specified TYPE DETAIL report group and performs all the automatic operations of the Report Writer facility as specified in the report group entries (see Section 10.8.13.3).

In the following example, DETAIL-LINE is the name of the DETAIL report group. When this GENERATE statement executes, a detail report is printed.


200-READ-MASTER.
    READ CUSTOMER-FILE AT END MOVE HIGH-VALUES TO NAME.
    IF NAME NOT = HIGH-VALUES GENERATE DETAIL-LINE.


Previous Next Contents Index