Control Breaks - PowerPoint PPT Presentation

1 / 30
About This Presentation
Title:

Control Breaks

Description:

000100 HUMMER 010w 05 CHICAGO MIDWEST. 000101 CLARK 1500 10 TRENTON NORTHEAST ... 694446 HUMMER 0904 10 CHICAGO MIDWEST. 203000 HAAS 8900 05 ST. LOUIS MIDWEST ... – PowerPoint PPT presentation

Number of Views:99
Avg rating:3.0/5.0
Slides: 31
Provided by: Den678
Category:
Tags: breaks | control | hummer

less

Transcript and Presenter's Notes

Title: Control Breaks


1
Control Breaks
2
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.

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

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

5
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.

6
Figure 15.1 Transaction File. (The sales amount
shows ASCII rather than EBCDIC Characters
Acct Salesperson Sales Comm Location RegionNum
Amount Pct 000069 BENWAY 023q 10 CHICAGO MIDWE
ST000100 HUMMER 010w 05 CHICAGO MIDWEST000101
CLARK 1500 10 TRENTON NORTHEAST000104 CLARK 05
00 03 TRENTON NORTHEAST100000 JOHNSON 030s 06 S
T. PETERSBURG SOUTHEAST130101 CLARK 3200 20 TREN
TON NORTHEAST203000 HAAS 8900 05 ST.
LOUIS MIDWEST248545 JOHNSON 0345 14 ST.
PETERSBURG SOUTHEAST277333 HAAS 009x 08 ST.
LOUIS MIDWEST400000 JOHNSON 070y 08 ST.
PETERSBURG SOUTHEAST444333 ADAMS 100v 01 NEW
YORK NORTHEAST444444 FEGEN 0100 02 ST.
PETERSBURG SOUTHEAST475365 HAAS 0333 05 ST.
LOUIS MIDWEST476236 FEGEN 037v 03 ST.
PETERSBURG NORTHEAST476530 BENWAY 023u 05 CHICAG
O MIDWEST555555 FEGEN 0304 05 ST.
PETERSBURG NORTHEAST555666 ADAMS 2003 20 NEW
YORK NORTHEAST576235 CLARK 0100 03 TRENTON NOR
THEAST583645 KARLSTROM 0145 04 BALTIMORE NORTHE
AST649356 HUMMER 0345 05 CHICAGO MIDWEST694446
HUMMER 0904 10 CHICAGO MIDWEST700039 MARCUS 0
932 10 BALTIMORE NORTHEAST750020 MARCUS 0305 05
BALTIMORE NORTHEAST800396 KARLSTROM 3030 09 BA
LTIMORE NORTHEAST878787 JOHNSON 1235 12 ST.
PETERSBURG SOURHEAST987654 ADAMS 2005 10 NEW
YORK NORTHEAST988888 BENWAY 0450 01 CHICAGO MI
DWEST999340 BENWAY 0334 30 CHICAGO MIDWEST
How woulddetermine total by salesperson
7
Signed Number
  • Negative Numbers
  • -0 p
  • -1 q
  • -2 r
  • -3 s
  • -4 t
  • -5 u
  • -6 v
  • -7 w
  • -8 x
  • -9 y
  • Positive Numbers
  • 0 0
  • 1 1
  • 2 2
  • 3 3
  • 4 4
  • 5 5
  • 6 6
  • 7 7
  • 8 8
  • 9 9

8
Figure 15.2 One-level Control Break
9
One Level Control Breaks
  • Data file must be sorted
  • Only one data field - usually Major Key
  • Change in value of Major Key (control field)
    indicates a new level
  • How will you know when a change occurs?
  • Need a WS data item (prev-???) which stores the
    value of the current control field level)
  • Produces only one set of totals
  • End of File
  • Treated as a break

10
Figure 15.5 One-level Algorithm (b) Pseudocode
Open sorted-file, print-filePerform until
End-Of_File Read Sorted-file At
End Move NO to Eof-SW
Not At End Perform
210-Process-Records End-ReadEnd-perform PER
FORM 220-Finalize Stop run
11
Figure 15.5 One-level Algorithm (b) Pseudocode
210-Process-Record. EVALUATE TRUE
WHEN FIRST-RECORD-SW YES
MOVE NO TO FIRST-RECORD-SW
MOVE SALESPERSON-NAME TO
WS-PREV-SALES-PERSON WHEN
SALESPERSON-NAME gt WS-PREV-SALES-PERSON
PERFORM 900-SALEPERSON-BREAK
WHEN SALESPERSON-NAME lt
WS-PREV-SALES-PERSON
PERFORM 380-SALEPERSON-ERROR
CLOSE FILES STOP
RUN. END-EVALUATE
PERFORM 300-ASSEMBLE DETAIL-LINE300-DET
AIL-LINE IF LINE-COUNT gt 30
PERFORM 950-HEADING-ROUTINE
END-IF MOVE
STUFF TO DETAIL-LINE PERFORM
400-ACCUMULATE-SALES-TOTALS WRITE
PRINT-LINE
12
Figure 15.5 One-level Algorithm (b) Pseudocode
220-FINALIZE PREFORM
900-SALESPERSON-BREAK PERFORM
380-WRITE-REPORT-TOTALS CLOSE
FILES 900-SALESPERSON-BREAK. MOVE
STUFF TO SALES-TOTAL-LINE ADD SALESTOTAL
TO REPORT-TOTAL WRITE PRINT-LINE FROM
SALES-TOTAL-LINE INITIALIZE
WS-SALESPERSON-TOTALS IF NOT-EOF
MOVE SALESPERSON-NAME TO WS-PREV-SALESPERSON
PERFORM 950-HEADING-ROUTINE
END-IF
13
Figure 15.3 Two-level Control Break
WS 05 PREV-SALESPERSON 05
SALESPERSON-TOTALS PROCEDURE DIVISION IF
SALESPERSON OF INPUT gt PREV-SALESPERSON
THEN PRINT TOTALS RESET
PREV-SALESPERSON
(a) Sorted Data (by Location and Salesperson)
14
Figure 15.3 Two-level Control Break
SALES ACTIVITY REPORT
PAGE 3 LOCATION NEW YORK SALESPERSON
ADAMS ACCOUNT SALES COMMISSION
583645 145 6
800396 3,030 273
--------
------- SALESPERSON TOTAL
3,175 279 SALESPERSON
KARLSTROM ACCOUNT SALES
583645 145 6
800396 3,030 273
--------
------- SALESPERSON TOTAL
3,175 279
SALES ACTIVITY REPORT PAGE
2 LOCATION CHICAGO SALESPERSON
KARLSTROM ACCOUNT SALES COMMISSION
583645 145
6 800396 3,030 273
--------
------- SALESPERSON TOTAL
3,175 279 SALESPERSON
MARCUS ACCOUNT SALES COMMISSION
700039 932
93 7500020 305 15

-------- -------
SALESPERSON TOTAL 1,237 108
LOCATION TOTAL 4,412 387
SALES ACTIVITY REPORT PAGE 1 LOCATION
BALTIMORE SALESPERSON
KARLSTROM ACCOUNT SALES COMMISSION
583645 145
6 800396 3,030 273
--------
------- SALESPERSON TOTAL
3,175 279
SALESPERSON MARCUS ACCOUNT SALES
COMMISSION 700039
932 93 7500020 305
15
-------- -------
SALESPERSON TOTAL 1,237 108
LOCATION TOTAL 4,412 387
MAJOR
MINOR
(b) Partial Output
15
Two Level Control Breaks
  • Two Sort Fields - Major and Minor
  • A change in the minor causes 1 level of totals
  • A minor level total
  • A change in the major causes 2 levels of totals
  • A minor total
  • A major total
  • End of file treated as a major level break

16
Figure 15.5 Two-level Algorithm (b) Pseudocode
Open sorted-file, print-filePerform until
End-Of_File Read Sorted-file At
End Move NO to Eof-SW
Not At End Perform
210-Process-Records End-ReadEnd-perform PER
FORM 220-Finalize Stop run
17
Figure 15.5 Two-level Algorithm (b) Pseudocode
210-Process-Record. EVALUATE TRUE
WHEN FIRST-RECORD-SW YES
MOVE NO TO FIRST-RECORD-SW
MOVE SALESPERSON-NAME TO
PREV-SALESPERSON MOVE
LOCATION TO PREV-LOCATION
MOVE REGION TO PREV-REGION
INITIALIZE ACCUMULATORS
When Location Not Prev- Location
Perform 920-Location-Break
When Salesperson Not Prev-Salesperson
Perform 930-SalesPerson-Break
END-EVALUATE
PERFORM 300-ASSEMBLE DETAIL-LINE
18
Figure 15.5 Three-level Algorithm
920-LOCATION-BREAK. PERFORM
930-SALESPERSON-BREAK MOVE STUFF TO
LOACTION-TOTAL-LINE ADD LOCATION-TOTALS
TO REPORT-TOTALS WRITE PRINT-LINE FROM
LOACTION-TOTAL-LINE INITIALIZE
LOCATION-TOTALS IF NOT-EOF
MOVE LOCATION TO PREV-LOCATION
END-IF 930-SALESPERSON-BREAK. MOVE STUFF
TO SALES-TOTAL-LINE ADD SALESTOTALS TO
LOACTION-TOTALS WRITE PRINT-LINE FROM
SALES-TOTAL-LINE INITIALIZE
SALESPERSON-TOTALS IF NOT-EOF
MOVE SALESPERSON-NAME TO WS-PREV-SALESPERSON
END-IF
19
Figure 15.5 Three-level Algorithm (b)
Pseudocode
220-FINALIZE PREFORM
920-LOCATION-BREAK PERFORM
380-WRITE-REPORT-TOTALS CLOSE FILES
20
Totals
  • Running Totals
  • Add to each total every record
  • Rolling Totals
  • Add only to lowest level total for each record
  • When a break add lower level total to next
    highest level

21
Figure 15.4 Three-level Control Break
000069 BENWAY 023q 10 CHICAGO MIDWEST476530 BENW
AY 023u 05 CHICAGO MIDWEST988888 BENWAY 0450
01 CHICAGO MIDWEST999340 BENWAY 0334 30
CHICAGO MIDWEST000100 HUMMER 010w 05
CHICAGO MIDWEST649356 HUMMER 0345 05
CHICAGO MIDWEST694446 HUMMER 0904 10
CHICAGO MIDWEST203000 HAAS 8900 05 ST.
LOUIS MIDWEST277333 HAAS 009x 08 ST.
LOUIS MIDWEST475365 HAAS 0333 05 ST. LOUIS
MIDWEST583645 KARLSTROM 0145 04
BALTIMORE NORTHEAST00396 KARLSTROM 3030 09
BALTIMORE NORTHEAST 700039 MARCUS 0932 10
BALTIMORE NORTHEAST750020 MARCUS 0305 05
BALTIMORE NORTHEAST444333 ADAMS 100v 01 NEW
YORK NORTHEAST555666 ADAMS 2003 20 NEW
YORK NORTHEAST 987654 ADAMS 2005 10 NEW
YORK NORTHEAST000101 CLARK 1500 10
TRENTON NORTHEAST000104 CLARK 0500 03
TRENTON NORTHEAST130101 CLARK 3200 20
TRENTON NORTHEAST576235 CLARK 0100 03
TRENTON NORTHEAST444444 FEGEN 0100 02 ST.
PETERSBURG SOUTHEAST476236 FEGEN 037v 03 ST.
PETERSBURG SOUTHEAST555555 FEGEN 0304 05 ST.
PETERSBURG SOUTHEAST100000 JOHNSON 030s 06 ST.
PETERSBURG SOUTHEAST248545 JOHNSON 0345 14 ST.
PETERSBURG SOUTHEAST400000 JOHNSON 070y 08 ST.
PETERSBURG SOUTHEAST878787 JOHNSON 1235 12 ST.
PETERSBURG SOUTHEAST
One-level control breaks (tertiary key)
Two-level control breaks (secondary key)
Three-level control break (primary key)
(a) Sorted Data (by Region, Location, and
Salesperson)
22
SALES ACTIVITY REPORT PAGE 3REGION
SOUTHEAST LOCATION ST. PETERSBURG
SALESPERSON BENWAY ACCOUNT SALES
COMMISSION 000069
231- 23- 476530
235- 12- 988888 450
5 999340 334 100
--------
------- SALESPERSON
TOTAL 318 70
SALESPERSON HUMMER ACCOUNT
SALES COMMISSION 000100 107-
5- 649356
345 17 694446
904 90
-------- -------
SALESPERSON TOTAL
1,142 102 LOCATION
TOTAL 1,460 172 LOCATION ST.
LOUIS SALESPERSON
BENWAY ACCOUNT SALES COMMISSION
203000 8,900
445 277333 98-
8- 475365 333 17
--------
-------
SALESPERSON TOTAL 9,135 454
LOCATION TOTAL 9,135
454 REGION TOTAL 10,595
626
SALES ACTIVITY REPORT PAGE 2REGION
NORTHEAST LOCATION BALTIMORE
SALESPERSON BENWAY ACCOUNT SALES
COMMISSION 000069
231- 23- 476530
235- 12- 988888 450
5 999340 334 100
--------
------- SALESPERSON
TOTAL 318 70
SALESPERSON HUMMER ACCOUNT
SALES COMMISSION 000100 107-
5- 649356
345 17 694446
904 90
-------- -------
SALESPERSON TOTAL
1,142 102 LOCATION
TOTAL 1,460 172 LOCATION ST.
LOUIS SALESPERSON
BENWAY ACCOUNT SALES COMMISSION
203000 8,900
445 277333 98-
8- 475365 333 17
--------
-------
SALESPERSON TOTAL 9,135 454
LOCATION TOTAL 9,135
454 REGION TOTAL 10,595 626\
SALES ACTIVITY REPORT PAGE 1REGION
MIDWEST LOCATION CHICAGO
SALESPERSON BENWAY ACCOUNT SALES
COMMISSION 000069
231- 23- 476530
235- 12- 988888 450
5 999340 334 100
--------
------- SALESPERSON
TOTAL 318 70
SALESPERSON HUMMER ACCOUNT
SALES COMMISSION 000100 107-
5- 649356
345 17 694446
904 90
-------- -------
SALESPERSON TOTAL
1,142 102 LOCATION
TOTAL 1,460 172 LOCATION ST.
LOUIS SALESPERSON
BENWAY ACCOUNT SALES COMMISSION
203000 8,900
445 277333 98-
8- 475365 333 17
--------
-------
SALESPERSON TOTAL 9,135 454
LOCATION TOTAL 9,135
454 REGION TOTAL 10,595 626
(b) Partial Output
23
Three Level Control Breaks
Contains items for comparing input data to 01
Control-Levels 05 Prev-Region Pic
x(11) Value Low-Values 05 Prev-Location
Pic x(15) Value Low-Values 05 Prev-Salesperson
Pic x(15) Value Low-Values01 Accumulators
Usage Comp-3. 05 REPORT-Totals.
10 SALES-TOTAL PIC
9(9)v99. 10 COMMISSION-TOTAL PIC
9(7)V99. 05 Region-Totals.
10 SALES-TOTAL PIC 9(9)v99.
10 COMMISSION-TOTAL PIC 9(7)V99.
05 Location-Totals. 10
SALES-TOTAL PIC 9(7)v99.
10 COMMISSION-TOTAL PIC 9(5)V99.
05 SalesPerson-Totals. 10 SALES-TOTAL
PIC 9(6)v99. 10
COMMISSION-TOTAL PIC 9(4)V99.
24
Figure 15.5 Three-level Algorithm (b)
Pseudocode
Open sorted-file, print-filePerform until
End-Of_File Read Sorted-file At
End Move NO to Eof-SW
Not At End Perform
210-Process-Records End-ReadEnd-perform PER
FORM 220-Finalize Stop run
25
Figure 15.5 Three-level Algorithm (b)
Pseudocode
210-Process-Record. EVALUATE TRUE
WHEN FIRST-RECORD-SW YES
MOVE NO TO FIRST-RECORD-SW
MOVE SALESPERSON-NAME TO
PREV-SALESPERSON MOVE
LOCATION TO PREV-LOCATION
MOVE REGION TO PREV-REGION
INITIALIZE ACCUMULATORS
When Region Not Prev-Region
Perform 910-Region-Break
When Location Not Prev- Location
Perform 920-Location-Break When
Salesperson Not Prev-Salesperson
Perform 930-SalesPerson-Break
END-EVALUATE
PERFORM 300-ASSEMBLE DETAIL-LINE
26
Figure 15.5 Three-level Algorithm
910-REGION-BREAK PERFORM
920-LOCATION-BREAK MOVE STUFF TO
REGION-TOTAL-LINE ADD REGION-TOTALS TO
REPORT-TOTALS WRITE PRINT-LINE FROM
REGION-TOTAL-LINE INITIALIZE
REGION-TOTALS IF NOT-EOF
MOVE SALESPERSON-NAME TO WS-PREV-SALESPERSON
PERFORM 950-HEADING-ROUTINE
END-IF 920-LOCATION-BREAK. PERFORM
930-SALESPERSON-BREAK MOVE STUFF TO
LOACTION-TOTAL-LINE ADD LOCATION-TOTALS
TO REGION-TOTALS WRITE PRINT-LINE FROM
LOACTION-TOTAL-LINE INITIALIZE
LOCATION-TOTALS IF NOT-EOF
MOVE LOCATION TO PREV-LOCATION
END-IF 930-SALESPERSON-BREAK. MOVE STUFF
TO SALES-TOTAL-LINE ADD SALESTOTALS TO
LOACTION-TOTALS WRITE PRINT-LINE FROM
SALES-TOTAL-LINE INITIALIZE
SALESPERSON-TOTALS IF NOT-EOF
MOVE SALESPERSON-NAME TO WS-PREV-SALESPERSON
END-IF
27
Figure 15.5 Three-level Algorithm (b)
Pseudocode
220-FINALIZE PREFORM 910-REGION-BREAK
PERFORM 380-WRITE-REPORT-TOTALS
CLOSE FILES
28
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.

29
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.

30
P R O G R A M M I N G T I P
How to Write a Control Break Program
The algorithm for one-, two-, and three-level
control breaks follows a general pattern that can
be adopted for any control break application
and/or any number of levels. We suggest,
therefore, that you review the hierarchy chart,
pseudocode, and/or COBOL programs that were
developed in this chapter and see how those
examples fit a general pattern. Start
by determining the number of levels in the
application, their relative importance (sort
order), and corresponding field names. Identify
the field names that will be used to detect a
control break at each level -- for example,
SR-REGION, SR-LOCATION, and SR-NAME in the
three-level example used in the text.
Modify the hierarchy chart, pseudocode, and COBOL
listings from the chapter to accommodate your
specific application. Begin with the highest
(most important) level and do the following for
every level 1. Initialize the control totals
for this level 2. Initialize the field name to
detect a control break at this level with the
previous value 3. Write the heading for this
level (if any) 4. Process this level until the
field name at this level is not equal to the
previous value OR the field name at a
higher level is not equal to the previous value
OR no data remains 5. Write this levels
total (if any) 6. Increment the next higher
levels total (rolling totals) At the lowest
(transaction) level 1. Perform the necessary
calculations (if any) 2. Write a detail line
(if any) 3. Increment the lowest levels total
(running total) 4. Read the next record
Write a Comment
User Comments (0)
About PowerShow.com