Вы находитесь на странице: 1из 69

Structured COBOL Programming

Nancy Stern Hofstra University Robert A. Stern

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.

Nassau Community College


PowerPoint Presentation: Richard H. Baum, Ph.D.
DeVry Institute of Technology
Structured COBOL Programming, Stern & Stern, 9th Edition

9th Edition

CHAPTER 10 Control Break Processing

OBJECTIVES
To familiarize you with:

1. The main types of computer-generated reports. 2. The techniques used for efficient printing of group reports and control totals. 3. Control break processing and control break printing.
Structured COBOL Programming, Stern & Stern, 9th Edition

CONTENTS
An Introduction to Control Break Processing
Types of Reports: A Systems Overview An Example of a Control Break Procedure

Program Requirements for Control Break Processing


A Single-Level Control Break

Structured COBOL Programming, Stern & Stern, 9th Edition

CONTENTS
Refinements to Improve the Quality of a Control Break Report Summary of a Single-Level Control Break Procedure

Self-Test

Multiple-Level Control Breaks

Structured COBOL Programming, Stern & Stern, 9th Edition

An Introduction to Control Break Processing

Structured COBOL Programming, Stern & Stern, 9th Edition

An Introduction to Control Break Processing


Types of Reports: A Systems Overview

Printed Reports fall into three major categories:


Detail or Transaction Reports Exception Reports Summary Reports

Another type of report, Displayed Output, results from interactive processing.


Structured COBOL Programming, Stern & Stern, 9th Edition

Detail or Transaction Reports


Detail or transaction reports are those that include one or more lines of output for each input record read. The following are examples:
Customer bills generated from a master accounts receivable file would be an example of a transaction or detail report. Payroll checks generated from a master payroll file would be a detail report. A listing of each part number stocked by a company would be a detail report.
Structured COBOL Programming, Stern & Stern, 9th Edition

Detail or Transaction Reports


Transaction or detail output is produced when information for each input record is required. Because detail reports generate output for each input record read, they can take a relatively long time to produce.
Printing 300,000 checks from a file of 300,000 records, for example, could take several hours.
Structured COBOL Programming, Stern & Stern, 9th Edition

Exception Reports
A listing of those clients with overdue balances is an example of an exception report. An exception report is any printout of individual records that meet (or fail to meet) certain criteria. Other examples of exception reports are:
A list of employees who are 65 years old or older. A list of part numbers in stock with a quantity on hand below some minimum value.
Structured COBOL Programming, Stern & Stern, 9th Edition

Summary Reports
As the name suggests, a summary or group report summarizes rather than itemizes. Often summaries or totals can provide more comprehensive and meaningful information for the user than a detail or exception report.

Structured COBOL Programming, Stern & Stern, 9th Edition

Displayed Output: A Systems Overview Interactive Processing.


When output is required as responses to inquiries and where printed copies are not needed, displayed output is often used.
The output is generated on a screen quickly and there is no need to generate paper, this can be costly and burdensome to store.
Structured COBOL Programming, Stern & Stern, 9th Edition

Displayed Output: A Systems Overview


Generally, detail and summary reports appear in printed form; short exception report s are often displayed on a monitor.
Displayed output must be clear, concise and informative just like printed output. We use a DISPLAY verb to generate output on a screen.
There is no need to establish an output file for output that will be displayed.
Structured COBOL Programming, Stern & Stern, 9th Edition

PROGRAM REQUIREMENTS FOR CONTROL BREAK PROCESSING


This chapter considers a type of summary procedure called control break processing.

With this type of processing, control fields are used to indicate when totals are to print.

Structured COBOL Programming, Stern & Stern, 9th Edition

A Single-Level Control Break


Control Break Processing is when a field (known as the key or control field) changes from one record to the next. When this change takes place then the following takes place:
An appropriate control total line is printed. The appropriate control field is initialized. The appropriate control total is initialized.
Structured COBOL Programming, Stern & Stern, 9th Edition

Control Break Processing: a Modular, Top-Down MAIN MODULE


You may wish to examine Figure 10.2 in your textbooks for the pseudocode planning tool used to prepare the program.
The program that will perform this control break procedure is shown in Figure 10.3 (The hierarchy chart is shown in Figure 10.4).
Excerpts follow.
Structured COBOL Programming, Stern & Stern, 9th Edition

Control Break Processing: a Modular, Top-Down Approach


The Main module is subdivided into subordinate modules that perform:
1. initializing functions 2. heading functions 3. calculations 4. end-of-job procedures

Helps focus on design and structure


Easier to debug
Structured COBOL Programming, Stern & Stern, 9th Edition

A Modular, Top-Down Approach


Pseudocode Excerpt MAIN-MODULE PERFORM Initialize-Rtn PERFORM Heading-Rtn PERFORM UNTIL there is no more input READ a Record NOT AT END PERFORM Detail-Rtn
AT END Move 'NO ' to Are-ThereMore-Records END-READ END-PERFORM
Structured COBOL Programming, Stern & Stern, 9th Edition

Program Excerpt
100-MAIN-MODULE. PERFORM 500-INITIALIZATION-RTN PERFORM 400-HEADING-RTN PERFORM UNTIL ARE-THERE-MORE-RECORDS = 'NO ' READ SALES-IN AT END MOVE 'NO ' TO ARE-THERE-MORE-RECORDS NOT AT END PERFORM 200-DETAIL-RTN END-READ END-PERFORM...
Structured COBOL Programming, Stern & Stern, 9th Edition

A Modular, Top-Down Approach


Program Excerpt

...
500-INITIALIZATION-RTN.

OPEN INPUT

SALES-IN

OUTPUT PRINT-OUT.

Structured COBOL Programming, Stern & Stern, 9th Edition

200-DETAIL-RTN
The processing of input records at 200DETAIL-RTN depends on whether there is a change in control fields, which we call a control break.

EVALUATE accomplishes two things:


1. Determines if the record being processed is the first one. 2. Initializes WS-HOLD-DEPT with that records DEPT-IN control field.
Structured COBOL Programming, Stern & Stern, 9th Edition

200-DETAIL-RTN
Program Excerpt 200-DETAIL-RTN.
EVALUATE TRUE
WHEN FIRST-RECORD = 'YES'
MOVE DEPT-IN TO WS-HOLD-DEPT MOVE 'NO ' TO FIRST-RECORD

WHEN DEPT-IN NOT = WS-HOLD-DEPT


PERFORM 300-CONTROL-BREAK

END-EVALUATE

IF WS-LINE-CT > 25
PERFORM 400-HEADING-RTN

END-IF
Structured COBOL Programming, Stern & Stern, 9th Edition

200-DETAIL-RTN (Continued)
200-DETAIL-RTN.
MOVE DEPT-IN TO DL-DEPT-OUT MOVE SLSNO-IN TO DL-SLSNO-OUT MOVE AMT-OF-SALES-IN TO DL-AMT-OF-SALES-OUT WRITE PRINT-REC FROM DETAIL-LINE AFTER ADVANCING 2 LINES

ADD 1 TO WS-LINE-CT
ADD AMT-OF-SALES-IN TO WS-DEPT-TOTAL.
Structured COBOL Programming, Stern & Stern, 9th Edition

300-CONTROL-BREAK
In the 300-CONTROL-BREAK module we print a summary line after a record is read that has a different department number than the one stored at WS-HOLD-DEPT.

300-CONTROL-BREAK is performed when an input record's DEPT-IN, the control field, differs from the one stored at WSHOLD-DEPT.
Structured COBOL Programming, Stern & Stern, 9th Edition

300-CONTROL-BREAK
When there is a change in DEPT-IN, we must:
1. Print a line with the department total accumulated for the previous DEPT-IN control group, which is stored in WS-DEPT-TOTAL. 2. Reinitialize WS-DEPT-TOTAL, the control total, so that the next department's total begins at zero before any amounts for the new control group have been accumulated.

Structured COBOL Programming, Stern & Stern, 9th Edition

300-CONTROL-BREAK
3. Move the current DEPT-IN to WS-HOLDDEPT so that we can compare succeeding input records to this new DEPT-IN control field. 4. Return to 200-DETAIL-RTN and process the current record by printing a detail line and adding the amount to the control total.

Structured COBOL Programming, Stern & Stern, 9th Edition

300-CONTROL-BREAK
Program Excerpt

300-CONTROL-BREAK.
WRITE PRINT-REC FROM GROUP-REC

MOVE WS-DEPT-TOTAL TO DEPT-TOTAL-OUT AFTER ADVANCING 2 LINES


ADD 1 TO WS-LINE-CT

MOVE ZEROS TO WS-DEPT-TOTAL


MOVE DEPT-IN TO WS-HOLD-DEPT.
Structured COBOL Programming, Stern & Stern, 9th Edition

Forcing a Control Break When There Are No More Records


Control break printing of totals occurs when:
A record with a new control field is read. The total for the last group of records, then, will have been accumulated when ARETHERE-MORE-RECORDS is equal to 'NO '. A control total will not have been printed since there is no subsequent record to trigger a change.
Structured COBOL Programming, Stern & Stern, 9th Edition

Forcing a Control Break When There Are No More Records


DEPT 01 01 01 02 --- 01 totals are printed when 02 is read

02 03 --- 02 totals are printed when 03 is read 03 (no more records)

At this point, the printing of 03 totals must be ``forced'' after ARE-THERE-MORERECORDS is set equal to 'NO '
Structured COBOL Programming, Stern & Stern, 9th Edition

Forcing a Control Break When There Are No More Records


We need to include a procedure to print the 03 totals. In the main module, after 200-DETAIL-RTN has been repeatedly executed and ARETHERE-MORE-RECORDS is equal to 'NO '. We must return to the statement following the in-line PERFORM ... END- PERFORM and force a printing of this final total.
Structured COBOL Programming, Stern & Stern, 9th Edition

REFINEMENTS TO IMPROVE THE QUALITY OF A CONTROL BREAK REPORT

Structured COBOL Programming, Stern & Stern, 9th Edition

Printing a Final Total


Sometimes, control break processing also requires the printing of a summary line containing a final total. This summary line (with final total) would be printed after the last control total is written.

Structured COBOL Programming, Stern & Stern, 9th Edition

Printing a Final Total Method 1


The final total, which we will call WSFINAL-TOTAL, may be accumulated by adding AMT-OF-SALES-IN for each record.
This may be accomplished by changing the ADD instruction in the 200- DETAIL-RTN to: ADD AMT-OF-SALES-IN TO WS-DEPT-TOTAL WS-FINAL-TOTAL

Structured COBOL Programming, Stern & Stern, 9th Edition

Printing a Final Total Method 2


The WS-FINAL-TOTAL may be accumulated, instead, by adding each WS-DEPT-TOTAL to it in 300-CONTROL-BREAK. This means that WS-FINAL-TOTAL would be accumulated, not for each detail record, but only when a control break has occurred.

Structured COBOL Programming, Stern & Stern, 9th Edition

Printing a Final Total Method 2


This would be accomplished by coding the following before we reinitialize WS-DEPTTOTAL: 300-CONTROL-BREAK.

...
ADD WS-DEPT-TOTAL TO WS-FINALTOTAL

MOVE ZEROS TO WS-DEPT-TOTAL


...
Structured COBOL Programming, Stern & Stern, 9th Edition

Starting a New Page After Each Control Break


It is likely that separate pages of a control break report will be distributed to different users.
In this case, it is useful to have each department's data begin on a new page.

Thus, a control break module would also include a statement to PERFORM the heading routine so that the paper is advanced to a new page when a control break occurs.
Structured COBOL Programming, Stern & Stern, 9th Edition

Starting a New Page After Each Control Break


We would add a PERFORM statement to the 300-CONTROL-BREAK module for printing headings on a new page each time that module is executed.

In this instance, it would be redundant to print the Department Number on each detail line. Rather, it would be better to print it once at the beginning of each page as a page heading.
Structured COBOL Programming, Stern & Stern, 9th Edition

Sequence-Checking or Sorting
For accurate control break processing, records must be in sequence by the control field. It might be useful to check to make certain, after each control break, that no sequence error occurred. If one did, an error message should be printed.

Structured COBOL Programming, Stern & Stern, 9th Edition

Executing the Control Break Module from the Main Module After an End-of-File Condition Has Been Met
If we wish to force a control break at the end of the job, it is best to perform the sequence of steps in the control break routine.

Structured COBOL Programming, Stern & Stern, 9th Edition

SUMMARY OF STEPS INVOLVED IN A SINGLE-LEVEL CONTROL BREAK PROBLEM


1. For the first record read, move the control field to a hold area in WORKINGSTORAGE.
2. For each additional record, as long as the control field is equal to the hold area, execute the detail routine for the input record.
This means: Add the appropriate amount to a control total, print the detail record (if desired), and read the next record.
Structured COBOL Programming, Stern & Stern, 9th Edition

SUMMARY OF STEPS INVOLVED IN A SINGLE-LEVEL CONTROL BREAK PROBLEM


3. If, for a specific record read, the control field is not equal to the hold area:
Print the control total. Initialize the control total field to zero. Reinitialize the hold field with the new control field value if ARE- THERE-MORE-RECORDS is not equal to 'NO '.

Structured COBOL Programming, Stern & Stern, 9th Edition

SUMMARY OF STEPS INVOLVED IN A SINGLE-LEVEL CONTROL BREAK PROBLEM


Process the detail record as in step 2.
Print headings on a new page if each control total is to appear on a separate page.

4. After all records have been processed, perform a control break to print the last control group.

Structured COBOL Programming, Stern & Stern, 9th Edition

QUESTIONS?

Structured COBOL Programming, Stern & Stern, 9th Edition

SELF-TEST
1. In control break processing, we typically MOVE the control field to ____ after reading the first record (when FIRSTRECORD = 'YES').

Solution: a hold or WORKING-STORAGE area


Structured COBOL Programming, Stern & Stern, 9th Edition

SELF-TEST
2. What processing is performed if an input control field is equal to the control field stored in the hold area?

Solution: We add to a control total and print, if detail printing is required.


Structured COBOL Programming, Stern & Stern, 9th Edition

SELF-TEST
3. What processing is performed if an input control field is not equal to the control field stored in the hold area?

Solution: We perform a control break procedure.


Structured COBOL Programming, Stern & Stern, 9th Edition

SELF-TEST
4. If each control group is to begin on a separate page, we would perform a heading routine at the ____ module.

Solution: control break


Structured COBOL Programming, Stern & Stern, 9th Edition

SELF-TEST
5. If a final total is required, it is most efficient to accumulate the final total in the ____ module.

Solution: control break


Structured COBOL Programming, Stern & Stern, 9th Edition

SELF-TEST
6. At the control break module, we must print ____ , initialize ____ at zero, and move ____ .

Solution: the control total; the control total; the input control field to the hold area
Structured COBOL Programming, Stern & Stern, 9th Edition

SELF-TEST
7. When each individual input record results in the printing of an output line, we call this ____ .

Solution: detail or transaction printing


Structured COBOL Programming, Stern & Stern, 9th Edition

Multiple-Level Control Breaks


When two or more fields are required as control fields:
Use a double-level control break

Need two holding areas for comparison purposes.

Structured COBOL Programming, Stern & Stern, 9th Edition

Multiple-Level Control Breaks Sample Input Data


DEPT-IN SLSNO-IN AMT-OF-TRANS-IN
01 01 01 01 02 02 001* 001* 002* 003* 001* 001* 34555 54434 65544 76353 09377 92838

02
02

002*

09374

002* 09383 * in sequence by department number

Structured COBOL Programming, Stern & Stern, 9th Edition

Multiple-Level Control Breaks Sample Output


MONTHLY SALES REPORT PAGE 1 01/29/2001

DEPT-01
SALESPERSON NUMBER 001 002 003 TOTAL AMT OF SALES $889.89 $655.44 $763.53 TOTAL FOR DEPT - $2,308.86
Structured COBOL Programming, Stern & Stern, 9th Edition

Multiple-Level Control Breaks Sample Output


MONTHLY SALES REPORT PAGE 2 01/29/2001

DEPT-02
SALESPERSON NUMBER 001 002 TOTAL AMT OF SALES $1,022.15 $187.57 TOTAL FOR DEPT - $1,209.72

Structured COBOL Programming, Stern & Stern, 9th Edition

Multiple-Level Control Breaks Program Excerpt


100-MAIN-MODULE. PERFORM 600-INITIALIZATION-RTN. PERFORM UNTIL NO-MORE-RECORDS READ TRANS-FILE-IN AT END MOVE 'NO ' TO ARE-THERE-MORERECORDS NOT AT END PERFORM 200-DETAIL-RTN END-READ END-PERFORM.
Structured COBOL Programming, Stern & Stern, 9th Edition

Multiple-Level Control Breaks Program Excerpt


600-INITIALIZATION-RTN.

OPEN INPUT

TRANS-FILE-IN

OUTPUT REPORT-FILE-OUT

ACCEPT WS-DATE FROM DATE


.

.
.
Structured COBOL Programming, Stern & Stern, 9th Edition

Multiple-Level Control Breaks Program Excerpt


No Detail printing required, no write needed: 200-DETAIL-RTN.

EVALUATE TRUE
WHEN FIRST-RECORD = 'YES' MOVE SLSNO-IN TO WS-HOLD-SLSNO MOVE DEPT-IN TO WS-HOLD-DEPT PERFORM 500-HEADING-RTN MOVE 'NO ' TO FIRST-RECORD
Structured COBOL Programming, Stern & Stern, 9th Edition

Multiple-Level Control Breaks Program Excerpt


WHEN DEPT-IN NOT = WS-HOLD-DEPT
PERFORM 400-DEPT-BREAK

WHEN SLSNO-IN NOT = WS-HOLDSLSNO


PERFORM 300-SLS-BREAK

END EVALUATE ADD AMT-OF-TRANS-IN TO WS-SLSTOTAL.

Structured COBOL Programming, Stern & Stern, 9th Edition

Multiple-Level Control Breaks Program Excerpt


400-DEPT-BREAK.

PERFORM 300-SLS-BREAK
MOVE WS-DEPT-TOTAL TO DL-DEPTTOTAL WRITE REPORT-REC-OUT FROM DLDEPT-LINE AFTER ADVANCING 2 LINES

Structured COBOL Programming, Stern & Stern, 9th Edition

Multiple-Level Control Breaks Program Excerpt


400-DEPT-BREAK. (continued)
IF MORE-RECORDS

MOVE ZEROS TO WS-DEPT-TOTAL

MOVE DEPT-IN TO WS-HOLD-DEPT


PERFORM 500-HEADING-RTN
END-IF.

Structured COBOL Programming, Stern & Stern, 9th Edition

MULTIPLE-LEVEL CONTROL BREAKS


The last WHEN condition tested in EVALUATE is the minor-level control break.
This test is performed only if FIRST-RECORD is not equal to 'YES' (for all records except the first) and if there is no major control break.

When a change in SLSNO-IN occurs even without a change in DEPT-IN, this would force a minor control break called 300SLS-BREAK.
Structured COBOL Programming, Stern & Stern, 9th Edition

MULTIPLE-LEVEL CONTROL BREAKS


Thus, when SLSNO-IN is not equal to WSHOLD-SLSNO (or when a department break has occurred) we do the following:
1. Print the total for the previous SLSNO-IN.

2. Add that total to a WS-DEPT-TOTAL.


3. Initialize the WS-SLS-TOTAL field at zero. 4. Move the new SLSNO-IN to WS-HOLDSLSNO.

Structured COBOL Programming, Stern & Stern, 9th Edition

Multiple-Level Control Breaks Program Excerpt


300-SLS-BREAK. MOVE WS-SLS-TOTAL TO DL-SLS-TOTAL MOVE WS-HOLD-SLSNO TO DL-SLSNO WRITE REPORT-REC-OUT FROM DL-SLS-LINE
AFTER ADVANCING 2 LINES

ADD WS-SLS-TOTAL TO WS-DEPT-TOTAL IF MORE-RECORDS


MOVE ZERO TO WS-SLS-TOTAL
MOVE SLSNO-IN TO WS-HOLD-SLSNO

END-IF.
Structured COBOL Programming, Stern & Stern, 9th Edition

Multiple-Level Control Breaks Program Excerpt


Once all records have been read and processed and an AT END condition occurs, control returns to the main module, where an end-of-job routine is executed.
300-SLS-BREAK. ... IF MORE-RECORDS
MOVE ZERO TO WS-SLS-TOTAL MOVE SLSNO-IN TO WS-HOLD-SLSNO

END-IF.
Structured COBOL Programming, Stern & Stern, 9th Edition

Multiple-Level Control Breaks Program Excerpt


400-DEPT-BREAK.
.
.

IF MORE-RECORDS

MOVE ZEROS TO WS-DEPT-TOTAL MOVE DEPT-IN TO WS-HOLD-DEPT

PERFORM 500-HEADING-RTN
END-IF.
Structured COBOL Programming, Stern & Stern, 9th Edition

DEBUGGING TIP
When programs start to get complex with numerous procedures, programmers sometimes lose sight of the relationships among modules. This is where hierarchy charts can be helpful.
Note, too, that the PIC clause for the control field in the input record must be exactly the same as the PIC clause for the hold area that stores a control field.
If they are not the same, the comparison performed to test for a control break could result in errors.
Structured COBOL Programming, Stern & Stern, 9th Edition

CHAPTER SLIDES END HERE


CHAPTER SUMMARY COMES NEXT

Structured COBOL Programming, Stern & Stern, 9th Edition

CHAPTER SUMMARY
A PROCEDURE DIVISION shell like the one found in the chapter summary of your text can be useful for processing any number of control breaks within a program.

Control Break Routines:


Higher-level breaks force lower-level breaks. Appropriate control total line is printed. Appropriate control field is initialized. Appropriate control total is initialized.
Structured COBOL Programming, Stern & Stern, 9th Edition

CHAPTER SUMMARY
In a control break program, all input records must be in sequence by minor control fields within intermediate control fields within major control fields.

If the records are not already in this order, then the file must be sorted into the required sequence before it can be processed.
Structured COBOL Programming, Stern & Stern, 9th Edition

Вам также может понравиться