COBOL has a Report Writer Module that greatly facilities print operations. By include Writer Module will automatically handle all:  Spacing of forms.  Skipping to a new page.  Testing for end of page.  Printing of headings at the top of a page and footings at the bottom of a page.  Accumulating of amount fields.  Testing for control breaks.  Detail and/or summary printing.  Printing of totals for control breaks.  Printing of a final total when there are no more input records.

The Report Writer Module provides a facility for producing reports by focusing on the physical characteristics of the report rather than specifying the detailed procedures necessary to produce the report. Many new DATA DIVISION entries are required when using this module but there are very few PROCEDURE DIVISION entries.

. Summary or group printing: The printing of totals or other summary information for groups of records. Detail printing: The printing of one or more lines for each input record. 2. FOR DETAIL PRINTING AND SUMMARY PRINTING 1.

When a change or “break” in the department number occurs.FOR CONTROL BREAK PROCESSING      Control break processing is a type of summary procedure. With this type of processing. . control fields are used to indicate when totals are to print. Summary printing is performed as a result of control break that occurs when there is a change in the department number. the accumulated total of all amounts of sales is printed as a control total line. We call department number a control field.

00 01 12347 $34.967.877.00 .967.3 2 2 03 03 15645 12321 $980.MONTHLY STATUS REPORT AREA 1 1 1 1 1 DEPT SALESPERSON AMT OF SALES 01 12345 $988.55 01 12346 $3.77 TOTAL AREA 1 $14525.560.77 TOTAL FOR DEPT IS $9.964.00 TOTAL AREA 2 $2.00 $1.00 TOTAL FOR DEPT IS $2.537.987.99 PAGE 01 TOTAL FOR DEPT IS $4.54 02 02 12222 12234 $9.00 $87.

. then the area total is printed. when a change in major control field occurs. During the reading of input. first the corresponding department total is printed.  Here area is a major control field.

• DETAIL (DE) : Prints for each input record read. at the top of the first page of the report. • CONTROL HEADING (CH) : Prints a heading that typically contains new control values when a control break has occurred. and so on. column heading. This may include page number. • PAGE HEADING (PH) :Prints identifying information at the top of each page.FOR PRINTING HEADING AND FOOTING  A Report Writer program can be designate print lines of the following types: • REPORT HEADING (RH) : Prints identifying information about the report only once. .

• CONTROL FOOTING (CF) : Prints control totals for the previous group of detail record just printed. for example. after a control break has occurred. While producing the coding needed in the PROCEDURE DIVISION . • PAGE FOOTING (PF) : Prints at the end of each page. The printing of each type of print line is controlled by the Report Writer Module. This may include. at the end of the report.  The Report Writer Module makes it possible for the programmer to specify a report‟s format in the REPORT SECTION of the DATA DIVISION. • REPORT FOOTING (RF) : Prints only once. and „End of Report‟ message.

We can use this module when complex summery of group printing is required. and they will print as appropriate under the control of the Report Writer Module. detail and footing lines. or it can be used for simple detail printing as well. Lines must be designated as heading. The DATA DIVISION of a program using the Report Writer Module can consist of three sections. . ◦ FILE SECTION ◦ WORKING-STORAGE SECTION ◦ REPORT SECTION    The REPORT SECTION is specified only when the Report Writer Module is used.

 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. FORMAT:  FD print-file-name LABEL RECORDS ARE OMITED [RECORD CONTAINS integer-1 CHARACTERS] REPORT IS REPORT ARE report-name-1… .

Most programs produce only one report in a program. but if use it should equal the number of characters per print line. The report-name must conform to the rules for forming datanames. Each report-name refers to a specific report. not just to a specific record format. summations. and reset procedures. The RECORD CONTAINS clause is optional. our program will use the WORKING-STORAGE SECTION only for the endof-file indicator. The Report Writer Module handles all control breaks.     . page breaks. A report may contain several types of print records or report line formats.

. which follows the WORKINGSTORAGE SECTION. It specifies: ◦ The report group type that describes each type of line. Each field can be given a VALUE or can have data passed to it from another field. ◦ The line on which each record is to print. ◦ The positions within each line where data is to print. ◦ The control fields. The REPORT SECTION. ◦ The fields to be used as summation fields. This can be specified as an actual line number or a relative line number that relates to a previous line. defines all aspects of the printed output.

  The RD entry‟s name corresponds to the report-name assigned in the FD for the output print file. . REPORT SECTION. like its counterpart the FD entry in the FILE SECTION. it can have numerous subordinate clauses. The RD entry describes the report and. Example. RD REPORT-LISTING   Both the REPORT SECTION header and the RD entry are required.

RD report-name-1 CONTROL IS CONTROLS ARE data-name-1 … FINAL data-name-1 … PAGE LIMIT IS LINE LIMIT ARE integer-1 LINES [HEADING integer-2] [FIRST DETAIL integer-3] [LAST DETAIL integer-4] [FOOTING integer-5] .FORMAT: REPORT SECTION.

for the next control group are printed. . Then the major-level CONTROL HEADINGs. the Report writer Module prints minor level CONTROL FOOTINGs first. If a major level control breaks occurs.    The CONTROL clause specifies the control fields. followed sequentially by the next level CONTROL FOOTINGs until the major level footings are printed. if any. This fields will be tested against their previous value to determine if a control break has occurred. followed by any intermediate an minor level CONTROL HEADINGs. The major control fields must be specified before minor ones.

The line on which the LAST DETAIL record may print. The line on which the FIRST DETAIL record may print. This would allow for adequate margins at both the top and bottom of the page. . The line on which the PAGE or first REPORT HEADING record may printed. indicating actual line numbers on which specific report group types are to print.      The PAGE LIMIT clause specifies the layout of a page of thee report. The PAGE LIMIT clause indicates: The number of actual lines that should be used for printing approximately 60 lines are usually allotted for a page. The last line on which a CONTROL FOOTING record may print.

The report groups within the REPORT SECTION are classified as ◦ Headings ◦ Detail lines ◦ Footings. It is coded on the 01 level.  The printing specifications and the format of each are defined in a series of report group descriptions. .   The first entry for a report group within the RD is called the report group description entry.

However. Clauses may be coded in sequence. that the TYPE clause is typically coded first in and 01-level entry. It is a required entry only when the report group is specifically called for in the PROCEDURE DIVISION. .   AN OVERVIEW OF THE FORMAT FOR THE REPORT GROUP DESCRIPTION ENTRY 01 [data-name-1] TYPE Clause [LINE Clause] [NEXT GROUP Clause] Data-name-1 is the name of the report group.


 LINE Clause FORMAT 01 [data-name-1]… integer-1 [ON NEXT PAGE] LINE NUMBER IS PLUS integer-2 . ◦ The time at which each report group is printed within a report is dependant on its type. TYPE clause-Required ◦ it is specifies the category of the 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.

    NEXT GROUP Clause It is most often used in a report group to indicate the line spacing. To be performed when the last line of the control footing has been printed. . FORMAT 01 [data-name-1]… integer-1 NEXT GROUP IS PLUS integer-2 NEXT PAGE  One of the main use of NEXT-GROUP clause is to provide some extra blanks between the end of one of control group and the start of the next.

 FORMAT level-no [data-name-1] PICTURE IS character-string PIC LINE NUMBER IS integer-1 [ON NEXT PAGE] PLUS integer-2 [COLUMN NUMBER IS integer-3] SOURCE IS identifier-1 VALUE IS literal-1 [SUM identifier-2 …] RESET ON data-name-2 FINAL [GROUP INDICATE] .

we need not indicate a field-name or FILLER at all. o The SOURCE Clause o The SUM Clause o The RESET Phrase . The following clauses may be used to transmit the contend in some named storage area to an individual field in a heading. Data-names or identifiers are only required with detail. heading and footing fields that are to be referenced elsewhere. footing or detail report group.   For headings and footings that have VALUE.

.  Sum is used only on a CONTROL FOOTING LINE. usually it is an input field. usually defined in the input area or in WORKING-STORAGE.99 SOURCE IS COST This indicate that beginning at column 14 of the specified record. the contents of the field called COST should print.  Example. COST may be either a FILE or WORKING-STORAGE SECTION item. The SUM Clause  It is used for automatic summation of data.  The SOURCE Clause indicates a field that is used as a source for this report item. 05 COLUMN 14 PICTURE $ZZ.The SOURCE Clause  The SOURCE Clause specifies that a data item is to be printed from a different field.ZZZ.

      The RESET Phrase It may be used only in conjunction with a SUM Clause. Example. . If the RESET Phrase is not included.99 SUM COST RESET ON DEPT-NO. The RESET Clause is used to defer the resetting of a SUM counter to zero until some higher level control break occurs. The RESET Phrase permits a sum to serve as a running total for higher level control breaks. a SUM counter will be reset immediately after it is printed. 05 COLUMN 65 PICTURE $$$$9.

It is usually coded directly after the OPEN statement. . including LINE-COUNTER and PAGE-COUNTER. Format: INITIATE report-name1 The INITIATE statement sets all SUM and COUNTER fields to zero. INITIATE STATEMENT The INITIATE statement begins the processing of a report. It INITIATE the report write module.

Format: GENERATE  Data-name-1 Report-name-1 . 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.

   We may generate a DETAIL report group name or an RD entry. . If the data-name identifies an RD entry. then the GENERATE statement performs all the functions of the report writer module. the GENERATE statement performs all functions of the report writer module except detail printing. only summary printing is achieved. If the data-name is the DETAIL report group name. In this way. including control break processing and summary and detail printing.

Format TERMINATE report-name-1…….      The TERMINATE statement completes the processing of a report after all records have been processed. it forces all control total to print for the last control group and also prints any final totals. . The TERMINATE causes the report writer module to produce all CONTROL FOOTING report groups beginning with minor a once. It is usually coded just before the files are closed. That is.

Sign up to vote on this title
UsefulNot useful