1. Introduction The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦...

42
1

Transcript of 1. Introduction The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦...

Page 1: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

1

Page 2: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

Introduction The Benefits of the Report Writer Module

◦ For Detail and Summary Printing◦ For Control Break Processing◦ For Printing Headings and Footings

16-2

Page 3: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

The REPORT SECTION in the DATA DIVISION◦ The RD Entry within the REPORT SECTION◦ Clauses Used at the Group Level within a Report

Group Description◦ Clauses Used at the Elementary Level within a

Report Group Description

16-3

Page 4: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

PROCEDURE DIVISION Statements◦ INITIATE Statement◦ GENERATE Statement◦ TERMINATE Statement

16-4

Page 5: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

COBOL has a Report Writer Module that greatly facilitates print operations.

By including additional DATA DIVISION entries, the Report Writer Module automatically handles all:

1. Spacing of forms.2. Skipping to a new page.3. Testing for end of page.

4. Printing of headings at the top of a page and footings at the bottom of a page.

16-5

Page 6: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

5. Accumulating of amount fields.6. Testing for control breaks.7. Detail and/or summary printing.8. Printing of totals for control breaks.9. Printing of a final total when there are no more input records.

Summary

16-6

Page 7: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

A Report Writer program can designate print lines of the following types:

REPORT HEADING (RH) - Prints identifying information about the report only once, at the top of the first page of the report.

PAGE HEADING (PH) - Prints identifying information at the top of each page. ◦ This may include page numbers, column headings,

and so on.

16-7

Page 8: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

CONTROL HEADING (CH) - Prints a heading that typically contains new control values when a control break has occurred.

DETAIL (DE) - Prints for each input record read.

CONTROL FOOTING (CF) - Prints control totals for the previous group of detail records just printed, after a control break has occurred.

16-8

Page 9: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

PAGE FOOTING (PF) - Prints at the end of each page.

REPORT FOOTING (RF) - Prints only once, at the end of the report. ◦ This may include, for example, an ‘End of Report’

message.

16-9

Page 10: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

The DATA DIVISION of a program using the Report Writer Module can consist of three sections that must be coded in the order shown:1. FILE SECTION2. WORKING-STORAGE SECTION3. REPORT SECTION

16-10

Page 11: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

The REPORT SECTION is specified only when the Report Writer Module is used.

Lines must be designated as heading, detail, and footing lines.◦ These will print as appropriate under the control

of the Report Writer Module.

16-11

Page 12: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

The FD for the print file in a program using the Report Writer Module contains a LABEL RECORDS clause and may include a RECORD CONTAINS clause.

A REPORT clause is added as in the following:

FD print-file-nameLABEL RECORDS ARE OMITTED[RECORD CONTAINS integer-1

CHARACTERS]{REPORT IS}

{REPORTS ARE} report-name-1 . . .

16-12

Page 13: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

The REPORT SECTION, which follows the WORKING-STORAGE SECTION, defines all aspects of the printed output. It specifies:1. The report group type that describes each

type of line (e.g., Report Heading, Page Heading, Detail).

2. The line on which each record is to print. This can be specified as an actual line number (e.g.,

3) or a relative line number that relates to a previous line (e.g., PLUS 2).

16-13

Page 14: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

3. The control fields.4. The positions within each line where data is to

print. Each field can be given a VALUE or can have data passed to it from another field.

5. The fields to be used as summation fields. With these specifications in the REPORT

SECTION, the PROCEDURE DIVISION need not include coding for control break or summary operations.

16-14

Page 15: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

The RD entry’s name corresponds to the report-name assigned in the FD for the output print file.

REPORT SECTION.RD REPORT - LISTING

Both the REPORT SECTION header and the RD entry are required.

16-15

Page 16: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

The RD entry describes the report and it can have numerous subordinate clauses. (Naming: FD -> RD)

REPORT SECTION RD report-name-1

[{CONTROL IS} {{data-name-1 . . .}}

{CONTROLS ARE}{ FINAL data-name-1 . ..}]

[PAGE [LIMIT IS] integer-1

[LINE LIMITS ARE] [LINE LINES] HEADING integer-2

FIRST DETAIL integer-3 LAST DETAIL integer-4 FOOTING integer-5]

16-16

Page 17: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

The CONTROL clause specifies the control fields. ◦ These fields will be tested against their previous value to determine if a control break has

occurred. The sequence in which the data-names are listed in the CONTROL clause indicates their level in the control hierarchy.

◦ Major control fields must be specified before minor ones.

16-17

Page 18: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

How Lines Are Printed When a Control Break Occurs The action to be taken when a control break occurs is specified by the

programmer. After a control break occurs, we can print a

CONTROL FOOTING and/or a CONTROL HEADING. ◦ Both are coded on the 01 level in the REPORT

SECTION. ◦ This is automatic, none of the control break

programming required

16-18

Page 19: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

That is, CONTROL FOOTINGs typically contain accumulated control totals, so they should print first.

Then CONTROL HEADINGs, which relate to the new control fields, will print before any detail or summary

lines for these new control fields. CONTROL FOOTING (CF) print followed by

CONTROL HEADING (CH).

16-19

Page 20: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

The PAGE LIMIT clause specifies the layout of a page

of the report, indicating actual line numbers on which specific report group types are to print.

The PAGE LIMIT clause indicates:1. The number of actual lines that should be used

for printing (integer-1). Approximately 60 lines are usually allotted for a

page; this would allow for adequate margins at both the

top and bottom of the page.

16-20

Page 21: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

2. The line on which the PAGE or first REPORT HEADING record may print (integer-2).

3. The line on which the FIRST DETAIL record may print (integer-3).

4. The line on which the LAST DETAIL record may print (integer-4).

5. The last line on which a CONTROL FOOTING record may print (integer-5).

Only a PAGE or REPORT FOOTING can print beyond integer-5.

16-21

Page 22: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

An example using commands covered thus far would include the following entries:REPORT SECTIONRD REPORT-LISTING

CONTROLS ARE FINAL, CUST-NO PAGE LIMIT IS 60 LINES HEADING 3 FIRST DETAIL 9

16-22

Page 23: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

The first entry for a report group within the RD is called the report group description entry. ◦ It is coded on the 01 level.

The report groups within the REPORT SECTION are classified as headings, detail lines, and footings. ◦ The printing specifications and the format of each

are defined in a series of report group descriptions.

16-23

Page 24: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

AN OVERVIEW OF THE FORMAT FOR THE REPORT GROUP DESCRIPTION ENTRY

01 [data-name-1] TYPE Clause [LINE Clause] [NEXT GROUP Clause]

16-24

Page 25: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

The TYPE clause specifies the category of the report group. ◦ The time at which each report group is printed within a

report is dependent on its type. For example, a REPORT HEADING is printed before a

PAGE HEADING, a CONTROL FOOTING is printed when

a control break occurs, and so on. There are also established rules for the formation of each

report group. ◦ Data-name-2 and data-name-3 in the format refer to

control fields defined in the CONTROL clause of the RD entry.

16-25

Page 26: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

A REPORT HEADING, which can be abbreviated as RH, is the title of a report. ◦ It is the first item printed on each report.

Note that there can be only one 01-level entry categorized as a REPORT HEADING. ◦ It appears once - at the top of the first page of

the report.

16-26

Page 27: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

A PAGE HEADING (or PH) indicates a report group that is produced at the beginning of each page.

There can be only one 01-level entry categorized as a PAGE HEADING.

16-27

Page 28: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

Each DETAIL (or DE) record is described with an 01-level entry.

The first detail line of each group indicates the month and day. ◦ We call these GROUP INDICATE fields. ◦ They print when a control break has occurred.

The first time a detail group prints is considered a control break as well.

16-28

Page 29: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

The CONTROL FOOTING (or CF) report group is produced at the end of a control group for a given control item.

The CONTROL FOOTING is printed when a control break occurs. ◦ It prints prior to any CONTROL HEADING, which

would refer to the next control field’s value. ◦ There can be only one CONTROL FOOTING per

control item. CONTROL FOOTING FINAL is used to print final

totals at the end of a report.

16-29

Page 30: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

The PAGE FOOTING (or PF) report group is printed at the end of each page.

There can be only one 01-level entry designated as a PAGE FOOTING.

16-30

Page 31: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

The REPORT FOOTING (or RF) report group is produced at the end of the report.

There can be only one REPORT FOOTING.

16-31

Page 32: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

The optional LINE clause specifies either:1. An actual or absolute line number on which the corresponding report line is to be printed (e.g., LINE 3 or LINE 10), or2. A line number relative to the previous entry or to the previous page (e.g., LINE PLUS 2).

The LINE NUMBER clause can appear on the

01 level or on a level subordinate to it.

16-32

Page 33: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

The NEXT GROUP clause is most often used in a report group to indicate the line spacing (absolute or relative) to be performed when the last line of the control footing has been printed.

NEXT GROUP is also used to provide some extra blank lines between the end of one control group the and the start of the next.◦ It can also be used to force a REPORT

HEADING report group to print on a separate page before all other report groups.

16-33

Page 34: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

◦ INITIATE Statement◦ GENERATE Statement◦ TERMINATE Statement

16-34

Page 35: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

The INITIATE statement begins the processing of a report.

It is usually coded directly after the OPEN statement, and it serves to initiate the Report Writer Module.

Its format is: INITIATE report-name-1 . . .

The INITIATE statement sets all SUM and COUNTER fields to zero, including LINE-COUNTER and PAGE-COUNTER.

16-35

Page 36: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

The GENERATE statement is used to produce the report.

It usually names a detail report group to be printed after an input record has been read and follows this format:

GENERATE data-name-1

report-name-1 We may generate a DETAIL report group

name (data-name-1 in this format) or an RD entry (report-name-1).

16-36

Page 37: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

The TERMINATE statement completes the processing of a report after all records have been processed.

It is usually coded just before the files are closed, and follows this format:

TERMINATE report-name-1 . . . The TERMINATE causes the Report Writer

Module to produce all CONTROL FOOTING report groups beginning with the minor ones. ◦ That is, it forces all control totals to print for the

last control group and also prints any final totals.

16-37

Page 38: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

A. DATA DIVISION Entries 1. Code a REPORT SECTION following the

WORKING-STORAGE SECTION. 2. The FD for the output print file references

the RD in the REPORT SECTION: FD . . .

REPORT IS report-name-1. . . .

REPORT SECTION.

RD report-name-1.

16-38

Page 39: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

3. RD clauses. a. Control fields are listed beginning with

major controls as: CONTROLS ARE [FINAL,]

major control field . . . minor control field.

b. The PAGE LIMIT clause describes the number of print lines on each page; It can also include clauses that indicate what line

a heading should print on and/or what line a first detail, last detail, and last CONTROL FOOTING should print on.

16-39

Page 40: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

4. 01 report group description entries can describe REPORT HEADING, PAGE HEADING, CONTROL HEADING, DETAIL, CONTROL FOOTING, PAGE FOOTING, and REPORT FOOTING.

a. A data-name is required on the 01 level only if the data-name is used in the PROCEDURE DIVISION (e.g., with TYPE DETAIL) or in a USE BEFORE REPORTING declarative, which has not been discussed here.

b. A LINE NUMBER clause on the 05 level indicates what actual line or relative line the report group should print on.

16-40

Page 41: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

c. Specifying individual items within a report group:(1) Each entry indicates the columns in which items

are to print. (2) Each entry can contain a

(1) SOURCE - where the sending data is located (2) VALUE, or (3) SUM if the item is the sum of some other field.

(3) A data-name is required after the entry’s level number only if it is accessed elsewhere (e.g., in a CONTROL FOOTING’s SUM clause).

d. If a REPORT or PAGE HEADING or any detail printing requires more than one line, code each on an 05 level subordinate to the corresponding 01-level item.

16-41

Page 42: 1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.

B. PROCEDURE DIVISION Statements1. INITIATE report-name-1 after the files are opened.2. GENERATE detail-report-group-name for each

input record that has been read. The computer will print all headings, detail lines, control lines, and footings as well.

3. Before closing the files, TERMINATE report-name-1.

Sample Code

16-42