Академический Документы
Профессиональный Документы
Культура Документы
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.
9th Edition
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
CONTENTS
Refinements to Improve the Quality of a Control Break Report Summary of a Single-Level Control Break Procedure
Self-Test
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.
With this type of processing, control fields are used to indicate when totals are to print.
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
...
500-INITIALIZATION-RTN.
OPEN INPUT
SALES-IN
OUTPUT PRINT-OUT.
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.
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
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.
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.
300-CONTROL-BREAK
Program Excerpt
300-CONTROL-BREAK.
WRITE PRINT-REC FROM GROUP-REC
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
...
ADD WS-DEPT-TOTAL TO WS-FINALTOTAL
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
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.
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.
4. After all records have been processed, perform a control break to print the last control group.
QUESTIONS?
SELF-TEST
1. In control break processing, we typically MOVE the control field to ____ after reading the first record (when FIRSTRECORD = 'YES').
SELF-TEST
2. What processing is performed if an input control field is equal to the control field stored in the hold area?
SELF-TEST
3. What processing is performed if an input control field is not equal to the control field stored in the hold area?
SELF-TEST
4. If each control group is to begin on a separate page, we would perform a heading routine at the ____ module.
SELF-TEST
5. If a final total is required, it is most efficient to accumulate the final total in the ____ module.
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 ____ .
02
02
002*
09374
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
DEPT-02
SALESPERSON NUMBER 001 002 TOTAL AMT OF SALES $1,022.15 $187.57 TOTAL FOR DEPT - $1,209.72
OPEN INPUT
TRANS-FILE-IN
OUTPUT REPORT-FILE-OUT
.
.
Structured COBOL Programming, Stern & Stern, 9th Edition
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
PERFORM 300-SLS-BREAK
MOVE WS-DEPT-TOTAL TO DL-DEPTTOTAL WRITE REPORT-REC-OUT FROM DLDEPT-LINE AFTER ADVANCING 2 LINES
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
END-IF.
Structured COBOL Programming, Stern & Stern, 9th Edition
END-IF.
Structured COBOL Programming, Stern & Stern, 9th Edition
IF MORE-RECORDS
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 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.
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