Presentation is loading. Please wait.

Presentation is loading. Please wait.

Structured COBOL Programming

Similar presentations


Presentation on theme: "Structured COBOL Programming"— Presentation transcript:

1 Structured COBOL Programming
“Copyright @ 2000 John Wiley & Sons, In. All rights reserved. Reproduction or translation of this work beyond that permitted in Section 117 of the 1976 United States Copyright Act without the express permission of the copyright owner is unlawful. Request for further information should be addressed to the permissions Department , John Wily & Sons, Inc. The purchaser may make back-up copies for his/her own use only and not for distribution or resale. The Publisher assumes no responsibility for errors, omissions, or damages, caused by the use of these programs or from the use of the information contained herein.” Nancy Stern Hofstra University Robert A. Stern Nassau Community College 9th Edition PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology

2 CHAPTER 17 The Report Writer Module
Structured COBOL Programming, Stern & Stern, 9th edition

3 Structured COBOL Programming, Stern & Stern, 9th edition
OBJECTIVES To familiarize you with: 1. The Report Writer Module. 2. The options available for printing reports. Structured COBOL Programming, Stern & Stern, 9th edition

4 Structured COBOL Programming, Stern & Stern, 9th edition
CONTENTS Introduction The Benefits of the Report Writer Module For Detail and Summary Printing For Control Break Processing For Printing Headings and Footings Structured COBOL Programming, Stern & Stern, 9th edition

5 Structured COBOL Programming, Stern & Stern, 9th edition
CONTENTS 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 Structured COBOL Programming, Stern & Stern, 9th edition

6 Structured COBOL Programming, Stern & Stern, 9th edition
CONTENTS PROCEDURE DIVISION Statements INITIATE Statement GENERATE Statement TERMINATE Statement Structured COBOL Programming, Stern & Stern, 9th edition

7 Structured COBOL Programming, Stern & Stern, 9th edition
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. Structured COBOL Programming, Stern & Stern, 9th edition

8 Structured COBOL Programming, Stern & Stern, 9th edition
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. Structured COBOL Programming, Stern & Stern, 9th edition

9 The Benefits of the Report Writer Module
Structured COBOL Programming, Stern & Stern, 9th edition

10 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. Structured COBOL Programming, Stern & Stern, 9th edition

11 For Control Break Processing
A report has both detail and summary printing. That is, when input records with the same department number are read, the records are printed and the total amount of sales for each salesperson is accumulated. Structured COBOL Programming, Stern & Stern, 9th edition

12 For Control Break Processing
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 thee department number. Structured COBOL Programming, Stern & Stern, 9th edition

13 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. Structured COBOL Programming, Stern & Stern, 9th edition

14 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. Structured COBOL Programming, Stern & Stern, 9th edition

15 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. Structured COBOL Programming, Stern & Stern, 9th edition

16 The REPORT SECTION in the DATA DIVISION
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 SECTION 2. WORKING-STORAGE SECTION 3. REPORT SECTION Structured COBOL Programming, Stern & Stern, 9th edition

17 The REPORT SECTION in the DATA DIVISION
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. Structured COBOL Programming, Stern & Stern, 9th edition

18 The REPORT SECTION in the DATA DIVISION REPORT CLAUSE
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-name LABEL RECORDS ARE OMITTED [RECORD CONTAINS integer CHARACTERS] {REPORT IS} {REPORTS ARE} report-name Structured COBOL Programming, Stern & Stern, 9th edition

19 The REPORT SECTION in the DATA DIVISION
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). Structured COBOL Programming, Stern & Stern, 9th edition

20 The REPORT SECTION in the DATA DIVISION
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. Structured COBOL Programming, Stern & Stern, 9th edition

21 The RD Entry within the REPORT SECTION
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. Structured COBOL Programming, Stern & Stern, 9th edition

22 The Format for the RD Entry within the REPORT SECTION
The RD entry describes the report and it can have numerous subordinate clauses. REPORT SECTION RD report-name-1 [{CONTROL IS} {{data-name }} {CONTROLS ARE}{ FINAL data-name }] [PAGE [LIMIT IS] integer [LINE LIMITS ARE] [LINE LINES] HEADING integer FIRST DETAIL integer LAST DETAIL integer FOOTING integer-5] Structured COBOL Programming, Stern & Stern, 9th edition

23 Structured COBOL Programming, Stern & Stern, 9th edition
The CONTROL Clause 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. Structured COBOL Programming, Stern & Stern, 9th edition

24 Structured COBOL Programming, Stern & Stern, 9th edition
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. Structured COBOL Programming, Stern & Stern, 9th edition

25 Structured COBOL Programming, Stern & Stern, 9th edition
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. Structured COBOL Programming, Stern & Stern, 9th edition

26 Structured COBOL Programming, Stern & Stern, 9th edition
PAGE LIMIT Clause 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. Structured COBOL Programming, Stern & Stern, 9th edition

27 Structured COBOL Programming, Stern & Stern, 9th edition
PAGE LIMIT Clause 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. Structured COBOL Programming, Stern & Stern, 9th edition

28 The RD Entry within the REPORT SECTION: PAGE LIMIT Clause
An example using commands covered thus far would include the following entries: REPORT SECTION RD REPORT-LISTING CONTROLS ARE FINAL, CUST-NO PAGE LIMIT IS 60 LINES HEADING 3 FIRST DETAIL 9 Structured COBOL Programming, Stern & Stern, 9th edition

29 Structured COBOL Programming, Stern & Stern, 9th edition
QUESTIONS? Structured COBOL Programming, Stern & Stern, 9th edition

30 Structured COBOL Programming, Stern & Stern, 9th edition
SELF-TEST SALES Record Layout Field Size Type DIVISION 2 Alpha DEPT 2 Alpha ITEM 2 Alpha AMT-OF-SALES 6 Numeric * decimal positions Structured COBOL Programming, Stern & Stern, 9th edition

31 Structured COBOL Programming, Stern & Stern, 9th edition
SELF-TEST SALES REPORT PAGE NO. 9999 DIV DEPT ITEM AMT OF SALES XX XX XXX $ ... TOTAL ITEM AMT $ * TOTAL ITEM AMT $ * TOTAL DEPT AMT $ ** FINAL TOTAL $ **** Structured COBOL Programming, Stern & Stern, 9th edition

32 Structured COBOL Programming, Stern & Stern, 9th edition
SELF-TEST 1. DIV, DEPT, and ITEM are called ____ fields. SOLUTION: control Structured COBOL Programming, Stern & Stern, 9th edition

33 Structured COBOL Programming, Stern & Stern, 9th edition
SELF-TEST 2. The first line printed is called a ____ . SOLUTION: Page Heading (it is not a Report Heading, which would appear only on the first page of a report) Structured COBOL Programming, Stern & Stern, 9th edition

34 Structured COBOL Programming, Stern & Stern, 9th edition
SELF-TEST 3. The printing of a line for each input record is called ____ printing. SOLUTION: Detail Structured COBOL Programming, Stern & Stern, 9th edition

35 Structured COBOL Programming, Stern & Stern, 9th edition
SELF-TEST 4. The printing of total lines for DIV, DEPT, and ITEM is called ____ printing. SOLUTION: summary or group Structured COBOL Programming, Stern & Stern, 9th edition

36 Structured COBOL Programming, Stern & Stern, 9th edition
SELF-TEST 5. Each total line is referred to as a ____ . SOLUTION: CONTROL FOOTING Structured COBOL Programming, Stern & Stern, 9th edition

37 Structured COBOL Programming, Stern & Stern, 9th edition
SELF-TEST 6. The major-level control item, as specified on the output, is ____ . SOLUTION: DIV (after FINAL) Structured COBOL Programming, Stern & Stern, 9th edition

38 Structured COBOL Programming, Stern & Stern, 9th edition
SELF-TEST 7. The intermediate-level control item is ____ , and the minor-level control item is ____ . SOLUTION: DEPT; ITEM Structured COBOL Programming, Stern & Stern, 9th edition

39 Structured COBOL Programming, Stern & Stern, 9th edition
SELF-TEST 8. A change in DEPT results in the printing of ____ lines. That is, a DEPT control break also forces a(n) ____ control break. SOLUTION: two; ITEM Structured COBOL Programming, Stern & Stern, 9th edition

40 Structured COBOL Programming, Stern & Stern, 9th edition
SELF-TEST 9. A change in DIV results in the printing of ____ lines. That is, a DIV control break causes a ____ line to print, followed by a ____ line and then a ____ line. SOLUTION: three; ITEM total or footing; DEPT total or footing; DIV total or footing Structured COBOL Programming, Stern & Stern, 9th edition

41 Structured COBOL Programming, Stern & Stern, 9th edition
SELF-TEST 10. A ____ prints after all records and control totals, at the end of the job. SOLUTION: final total Structured COBOL Programming, Stern & Stern, 9th edition

42 Structured COBOL Programming, Stern & Stern, 9th edition
SELF-TEST 11. Assuming the Report Writer Module will be used in this program, code the FD for the preceding output file. SOLUTION: A suggested solution is: FD OUTPUT-FILE LABEL RECORDS ARE OMITTED REPORT IS REPORT-OUT. Structured COBOL Programming, Stern & Stern, 9th edition

43 Structured COBOL Programming, Stern & Stern, 9th edition
SELF-TEST 12. (T or F) 01 - level record description entries must not follow the above FD entries. SOLUTION: T Structured COBOL Programming, Stern & Stern, 9th edition

44 Structured COBOL Programming, Stern & Stern, 9th edition
SELF-TEST 13. The REPORT SECTION must follow the ____ and ____ SECTIONs in the ____ DIVISION. SOLUTION: FILE; WORKING-STORAGE; DATA Structured COBOL Programming, Stern & Stern, 9th edition

45 Structured COBOL Programming, Stern & Stern, 9th edition
SELF-TEST 14. The name following the RD level- indicator is the same as the name following the ____ clause in the ____ SECTION for the output file. SOLUTION: REPORT IS or REPORTS ARE; FILE Structured COBOL Programming, Stern & Stern, 9th edition

46 Structured COBOL Programming, Stern & Stern, 9th edition
SELF-TEST 15. Code the RD entry and its clauses for the preceding illustration. SOLUTION: REPORT SECTION RD REPORT CONTROLS ARE FINAL, DIV, DEPT, ITEM PAGE LIMIT IS 60 LINES HEADING FIRST DETAIL LAST DETAIL FOOTING 59. Note: Assume that DIV, DEPT, ITEM are the input record description data-names. Structured COBOL Programming, Stern & Stern, 9th edition

47 Clauses Used at the Group Level within a Report Group Description
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. Structured COBOL Programming, Stern & Stern, 9th edition

48 Clauses Used at the Group Level within a Report Group Description
AN OVERVIEW OF THE FORMAT FOR THE REPORT GROUP DESCRIPTION ENTRY 01 [data-name-1] TYPE Clause [LINE Clause] [NEXT GROUP Clause] Structured COBOL Programming, Stern & Stern, 9th edition

49 Structured COBOL Programming, Stern & Stern, 9th edition
TYPE Clause - Required 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. Structured COBOL Programming, Stern & Stern, 9th edition

50 Structured COBOL Programming, Stern & Stern, 9th edition
REPORT HEADING 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. Structured COBOL Programming, Stern & Stern, 9th edition

51 Structured COBOL Programming, Stern & Stern, 9th edition
PAGE HEADING 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. Structured COBOL Programming, Stern & Stern, 9th edition

52 Structured COBOL Programming, Stern & Stern, 9th edition
DETAIL line 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. Structured COBOL Programming, Stern & Stern, 9th edition

53 Structured COBOL Programming, Stern & Stern, 9th edition
CONTROL FOOTING 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. Structured COBOL Programming, Stern & Stern, 9th edition

54 Structured COBOL Programming, Stern & Stern, 9th edition
PAGE FOOTING 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. Structured COBOL Programming, Stern & Stern, 9th edition

55 Structured COBOL Programming, Stern & Stern, 9th edition
REPORT FOOTING The REPORT FOOTING (or RF) report group is produced at the end of the report. There can be only one REPORT FOOTING. Structured COBOL Programming, Stern & Stern, 9th edition

56 Structured COBOL Programming, Stern & Stern, 9th edition
LINE Clause 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), or 2. 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. Structured COBOL Programming, Stern & Stern, 9th edition

57 Structured COBOL Programming, Stern & Stern, 9th edition
NEXT GROUP Clause The NEXT GROUP clause is mot 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. Structured COBOL Programming, Stern & Stern, 9th edition

58 PROCEDURE DIVISION Statements
Structured COBOL Programming, Stern & Stern, 9th edition

59 Structured COBOL Programming, Stern & Stern, 9th edition
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 The INITIATE statement sets all SUM and COUNTER fields to zero, including LINE- COUNTER and PAGE-COUNTER. Structured COBOL Programming, Stern & Stern, 9th edition

60 Structured COBOL Programming, Stern & Stern, 9th edition
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 report-name-1 We may generate a DETAIL report group name (data-name-1 in this format) or an RD entry (report-name-1). Structured COBOL Programming, Stern & Stern, 9th edition

61 Structured COBOL Programming, Stern & Stern, 9th edition
TERMINATE Statement 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 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. Structured COBOL Programming, Stern & Stern, 9th edition

62 CHAPTER SLIDES END HERE
CHAPTER SUMMARY COMES NEXT Structured COBOL Programming, Stern & Stern, 9th edition

63 Structured COBOL Programming, Stern & Stern, 9th edition
CHAPTER SUMMARY 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 REPORT SECTION RD report-name-1. Structured COBOL Programming, Stern & Stern, 9th edition

64 Structured COBOL Programming, Stern & Stern, 9th edition
CHAPTER SUMMARY 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. Structured COBOL Programming, Stern & Stern, 9th edition

65 Structured COBOL Programming, Stern & Stern, 9th edition
CHAPTER SUMMARY 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. Structured COBOL Programming, Stern & Stern, 9th edition

66 Structured COBOL Programming, Stern & Stern, 9th edition
CHAPTER SUMMARY 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. Structured COBOL Programming, Stern & Stern, 9th edition

67 Structured COBOL Programming, Stern & Stern, 9th edition
CHAPTER SUMMARY B. PROCEDURE DIVISION Statements 1. 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. Structured COBOL Programming, Stern & Stern, 9th edition


Download ppt "Structured COBOL Programming"

Similar presentations


Ads by Google