1 / 42

Report Writer

Report Writer. Reporting programs. Problems Number of lines per page? Headings? Footings? Totals? Sub-totals? Page numbers? Blank lines? Tedious to program Require several attempts. INTRODUCTION. COBOL has a Report Writer Module that greatly facilitates print operations.

jace
Télécharger la présentation

Report Writer

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Report Writer

  2. Reporting programs • Problems • Number of lines per page? • Headings? • Footings? • Totals? • Sub-totals? • Page numbers? • Blank lines? • Tedious to program • Require several attempts

  3. INTRODUCTION • 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.

  4. INTRODUCTION 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.

  5. For Detail and Summary Printing • You will recall that many reports in business require: 1. Detail printing - The printing of one or more lines for each input record. 2. Summary or group printing - The printing of totals or other summary information for groups of records. • The Report Writer Module can be easily used for both detail and/or summary reports.

  6. For Control Break Processing • A report has both detail and summary printing • When a change or “break”in the department number occurs, the accumulated total of all amounts of sales is printed as a control total line. • We call department number a control field. • Summary printing is performed as a result of the control break that occurs when there is a change in the department number.

  7. Report Generator/Writer • Most Reports have same structure • Report Heading • Page Heading • Columns of Data • Page Footing • Report Footing • Allows automatic generation of report

  8. Example Report MONTHLY WAGES REPORT PAGE: 1 Date: 23/11/02 Dept.EmployeeGrossPayTaxNetPay Sales Murphy M 1000.00 50.00 950.00 Sales Flynn S 500.00 50.00 450.00 ----------- ---------- ---------- Sales Dept TOTAL 1500.00 $ 100.00 $ 1400.00 ====== ====== ====== Acc. Smith M 1000.00 50.00 950.00 Acc. Jones S 400.00 50.00 350.00 ----------- ---------- ---------- Acc. Dept. TOTAL $ 1400.00 $100.00 $ 1300.00 ====== ====== ====== ----------- ---------- ---------- Acc. Dept. TOTAL $ 2900.00 $ 200.00 $ 2700.00 ====== ====== ======

  9. Using Report Writer • Reports are written to an external file • Must declare the file to the program • Must identify • Logical Name • Physical Name • Organisation • Same as for a sequential File Select REPORT-FILE ASSIGN TO “C:\REPORT.DAT”. • Can also assign directly to printer in some versions of COBOL

  10. Using Report Writer • Must describe the structure of the records in the report file • Slightly Different FD REPORT-FILE REPORT IS STOCK-REPORT. NB. No record description is required at this point.

  11. Using Report Writer • Must define detail structure of the report • New section REPORT SECTION in DATA DIVISION • After WORKING-STORAGE section • After SCREEN section • There must be an entry(Report Description) for each report mentioned in the File Section REPORT SECTION. RD STOCK-REPORT. <- identified in REPORT IS

  12. Using Report Writer • Creating the report in Procedure Division • Housekeeping • OPEN Files • INITIATE the report • Processing • GENERATE the lines of the report • Finalize • TERMINATE the report • CLOSE Files

  13. Example Environment Division. Configuration Section. Input-Output Section. File-Control. • Declare the file from which data will be taken to produce the report • Must be sorted – if any total is to be done Select STOCK-FILE assign “STOCK.DAT” organization is LINE Sequential Declare the report file Select PRINT-FILE assign to “PRINT.DAT” organization is LINE Sequential.

  14. Example contd…. Data Division. File Section. FD STOCK-FILE. 01 STOCK-RECORD. 02 ITEM-NO PIC 9(5). 02 Name PIC X(20). 02 Department PIC X(10). 02 Amount-in-stock PIC 9(3). 02 Unit-price PIC 9(5)V99. 02 Supplier-name PIC X(50). FD PRINT-FILE REPORT IS STOCK-REPORT. * Later in the data division define the report in the report section.

  15. Report Section -Report Definition • A report generated by the Report Writer must have a Report Description (RD) entry in the Report Section. • Specifies the format of the printed page

  16. Report Section – Report Definition • Must Define • PAGE LIMIT • No. of lines to print on each page • Watch for page creep (57 seems to work well) • HEADING • Line at which heading will appear • FIRST DETAIL • Line at which first detail will appear • LAST DETAIL • Line at which last detail will appear • FOOTING • Line at which footing will appear

  17. Defining the Report Lines • Each RD entry consists of one or more 01 level-number entries. • Each 01 level-number entry identifies a report group • A unit consisting of one or more print lines and is of a particular type.

  18. Defining Report Lines • Must identify the type of line • Have sub-ordinate items • Must identify the line on which it is to be printed in the report • For each section of the line must identify where the data to be included is positioned I.e. column • Must identify the source of the data to be included on that line

  19. Line Number Clause • The LINE NUMBER clause is used to specify the vertical positioning of print lines. • Lines can be printed on • a specified line • a specified line on the next page • the current line number plus some increment

  20. For Printing Headings and Footings • 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.

  21. For Printing Headings and Footings 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.

  22. For Printing Headings and Footings 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.

  23. Example contd… *After Working-Storage Section REPORT SECTION. RD STOCK-REPORT PAGE LIMIT 66 HEADING 2 FOOTING 62 FIRST DETAIL 5 LAST DETAIL 60. 01 STOCK-PAGE-HEADING TYPE PH. 02 LINE 2. 03 COLUMN 10 PIC X(4) VALUE “ITEM”. 03 COLUMN 20 PIC X(4) VALUE “NAME”. 03 COLUMN 50 PIC X(5) VALUE “PAGE:”. 03 COLUMN 55 PIC ZZ9 SOURCE PAGE-COUNTER. 01 STOCK-DETAIL TYPE DETAIL. 02 LINE PLUS 2. 03 COLUMN 10 PIC X(5) SOURCE ITEM-NO. 03 COLUMN 20 PIC X(20) SOURCE NAME.

  24. Example contd…. 01 STOCK-PAGE-FOOTING TYPE PAGE FOOTING. 02 LINE 63. 03 COLUMN 45 PIC X(5) VALUE "-----". 02 LINE PLUS 1. 03 COLUMN 38 PIC X(6) VALUE "TOTAL:". 03 COLUMN 45 PIC $(4)9.99 SOURCE WS-TOTAL. 02 LINE PLUS 1. 03 COLUMN 45 PIC X(5) VALUE "=====".

  25. Example contd… 100-Main PERFORM 200-HOUSEKEEPING Perform until EOF Read Stock-file at end set EOF to true not at end Perform 210-Print-and-read End-Read End-Perform Perform 220-Finalize Stop

  26. Example 200-Housekeeping Open files INITIATE STOCK-REPORT 210-PRINT-AND-READ. GENERATE STOCK-DETAIL. 220-Finalize. TERMINATE STOCK-REPORT. Close Files

  27. Statements • INITIATE <report-name as defined in RD> • Initialises totalling data items, PAGE-COUNTER, LINE-COUNTER • GENERATE <Detail Line name > • Only items of type DETAIL • Outputs the named item plus page and control headings/footings as needed • TERMINATE <report-name as defined in RD> • Prints the last page, control footings needed plus report footing.

  28. Subdividing Reports • Suppose we want to divide the reports into sections decided upon by the value of pieces of data ? • E.g. For our example • Group items by department • Show the total value of stock in each department

  29. Controlling Reports • Define control in the report definition RD STOCK-REPORT CONTROLS ARE FINAL, DEPARTMENT PAGE LIMIT 66 HEADING 2 FOOTING 62 FIRST DETAIL 5 LAST DETAIL 60. • Data to control report must appear in a detail line • FINAL is a report writer specific word • Ensures last control footing of the report will be output • When data item changes known as CONTROL BREAK

  30. The CONTROL Clause • The CONTROL clause specifies the controlfields. • 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.

  31. The CONTROL Clause 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.

  32. The CONTROL Clause • CONTROL FOOTING (CF) print followed by CONTROL HEADING (CH). • 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.

  33. Controlling Reports • When detail line first generated report writer saves values of control data items • Each time a detail line is generated report item checks to see if values have changed beginning with the first listed in the RD

  34. Controlling Reports • If a control data item changes it also cause all other control breaks that are sub-ordinate to it • E.g. Controls are FINAL, DEPARTMENT, SUB-DEPARTMENT • When department changes • Footings for sub-department will be generated before the footings for department • Headings for next group will be generated for department then sub-department • Data Item that controls the report must appear in either a Detail or Control Line

  35. Control Heading • Will be printed at start of each group of data • Type is CONTROL HEADING • Identify where it should be positioned within the report 01 DEPT-HEADING TYPE IS CONTROL HEADING CONTROL IS DEPARTMENT NEXT GROUP NEXT PAGE. 02 LINE PLUS 1. 03 COLUMN 10 PIC X(28) value “STOCK LISTING FOR DEPARTMENT “. 03 COLUMN 40 PIC X(10) SOURCE DEPARTMENT.or 01 DEPT-HEADING TYPE IS CONTROL HEADING CONTROL IS DEPARTMENT NEXT GROUP LINE PLUS 5. 02 LINE PLUS 1. 03 COLUMN 10 PIC X(28) value “STOCK LISTING FOR DEPARTMENT “. 03 COLUMN 40 PIC X(10) SOURCE DEPARTMENT.

  36. Control Footing • Will be printed at end of each group of data • Type is CONTROL FOOTING • Identify where it should be positioned within the report 01 DEPT-HEADING TYPE IS CONTROL HEADING CONTROL IS DEPARTMENT LINE PLUS 2 NEXT GROUP IS NEXT PAGE. 02 LINE PLUS 1. 03 COLUMN 1 PIC X(27) VALUE “The total value of stock is “. 03 COLUMN 50 PIC 9(3) SUM UNIT-PRICE. OR 01 DEPT-HEADING TYPE IS CONTROL HEADING CONTROL IS DEPARTMENT PLUS 5. 02 LINE PLUS 1. 03 COLUMN 1 PIC X(27) VALUE “The total value of stock is “. 03 COLUMN 50 PIC 9(3) SUM UNIT-PRICE.

  37. NEXT GROUP Clause • 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.

  38. PROCEDURE DIVISION Statements

  39. INITIATE Statement • 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.

  40. GENERATE Statement • 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 (detail report) report-name-1 (summary only) • We may generate a DETAIL report group name (data-name-1 in this format) or an RD entry (report-name-1).

  41. TERMINATE Statement • The TERMINATE statement completes the processing of a report after all records have been processed. • It is 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.

  42. QUESTIONS?

More Related