Lesson 9

16
Lesson 9

description

Lesson 9. Control Break Processing. Detail Reports Exception Reports Summary Reports. Sorting. Reading in sequence Using Logical Files. Figure 15.1 Transaction File. (The sales amount shows ASCII rather than EBCDIC Characters. - PowerPoint PPT Presentation

Transcript of Lesson 9

Page 1: Lesson 9

Lesson 9

Page 2: Lesson 9

Control Break Processing

• Detail Reports

• Exception Reports

• Summary Reports

Page 3: Lesson 9

Sorting

• Reading in sequence

• Using Logical Files

Page 4: Lesson 9

Acct Salesperson Sales Comm Location RegionNum Amount Pct

000069 BENWAY 023! 10 CHICAGO MIDWEST000100 HUMMER 010’ 05 CHICAGO MIDWEST000101 CLARK 1500 10 TRENTON NORTHEAST000104 CLARK 0500 03 TRENTON NORTHEAST100000 JOHNSON 030# 06 ST. PETERSBURG SOUTHEAST130101 CLARK 3200 20 TRENTON NORTHEAST203000 HAAS 8900 05 ST. LOUIS MIDWEST248545 JOHNSON 0345 14 ST. PETERSBURG SOUTHEAST277333 HAAS 009( 08 ST. LOUIS MIDWEST400000 JOHNSON 070) 08 ST. PETERSBURG SOUTHEAST444333 ADAMS 100% 01 NEW YORK NORTHEAST444444 FEGEN 0100 02 ST. PETERSBURG SOUTHEAST475365 HAAS 0333 05 ST. LOUIS MIDWEST476236 FEGEN 037& 03 ST. PETERSBURG NORTHEAST476530 BENWAY 023% 05 CHICAGO MIDWEST555555 FEGEN 0304 05 ST. PETERSBURG NORTHEAST555666 ADAMS 2003 20 NEW YORK NORTHEAST576235 CLARK 0100 03 TRENTON NORTHEAST583645 KARLSTROM 0145 04 BALTIMORE NORTHEAST649356 HUMMER 0345 05 CHICAGO MIDWEST694446 HUMMER 0904 10 CHICAGO MIDWEST700039 MARCUS 0932 10 BALTIMORE NORTHEAST750020 MARCUS 0305 05 BALTIMORE NORTHEAST800396 KARLSTROM 3030 09 BALTIMORE NORTHEAST878787 JOHNSON 1235 12 ST. PETERSBURG SOURHEAST987654 ADAMS 2005 10 NEW YORK NORTHEAST988888 BENWAY 0450 01 CHICAGO MIDWEST999340 BENWAY 0334 30 CHICAGO MIDWEST

Figure 15.1 Transaction File. (The sales amount shows ASCII rather than EBCDIC Characters

Page 5: Lesson 9

444333 ADAMS 100% 01555666 ADAMS 2003 20987654 ADAMS 2005 10000069 BENWAY 023! 10476530 BENWAY 023% 05988888 BENWAY 450 01999340 BENWAY 0334 30000101 CLARK 1500 10000104 CLARK 0500 03130101 CLARK 3200 20576235 CLARK 0100 03444444 FEGEN 0100 02476236 FEGEN 037& 03555555 FEGEN 0304 05203000 HAAS 8900 05277333 HAAS 009( 08475365 HAAS 0333 05000100 HUMMER 010’ 05649356 HUMMER 0345 05694446 HUMMER 0904 10100000 JOHNSON 030# 06248545 JOHNSON 0345 14400000 JOHNSON 070) 08878787 JOHNSON 1235 12583645 KARLSTROM 0145 04800396 KARLSTROM 3030 09700039 MARCUS 0932 10750020 MARCUS 0305 05

SALES ACTIVITY REPORT PAGE 3

SALESPERSON: CLARKACCOUNT # SALES COMMISSION

444333 1,005- 10- 555666 2,003 401 987654 2.005 201 -------- -------

** SALESPERSON TOTAL $ 3,003 $ 582

SALES ACTIVITY REPORT PAGE 2

SALESPERSON: BENWAYACCOUNT # SALES COMMISSION

444333 1,005- 10- 555666 2,003 401 987654 2.005 201 -------- -------

** SALESPERSON TOTAL $ 3,003 $ 582

SALES ACTIVITY REPORT PAGE 1

SALESPERSON: ADAMSACCOUNT # SALES COMMISSION

444333 1,005- 10- 555666 2,003 401 987654 2.005 201 -------- -------

** SALESPERSON TOTAL $ 3,003 $ 582

One-level control break

One-level control break

(a) Sorted Data (by Salesperson) (b) Partial Output

Figure 15.2 One-level Control Break

Page 6: Lesson 9

583645 KARLSTROM 0145 04 BALTIMORE800396 KARLSTROM 3030 09 BALTIMORE700039 MARCUS 0932 10 BALTIMORE750020 MARCUS 0305 05 BALTIMORE

000069 BENWAY 023! 10 CHICAGO476530 BENWAY 023% 05 CHICAGO 988888 BENWAY 0450 01 CHICAGO999340 BENWAY 0334 30 CHICAGO000100 HUMMER 010’ 05 CHICAGO649356 HUMMER 0345 05 CHICAGO694446 HUMMER 0904 10 CHICAGO444333 ADAMS 100% 01 NEW YORK555666 ADAMS 2003 20 NEW YORK987654 ADAMS 2005 10 NEW YORK 203000 HAAS 8900 05 ST. LOUIS277333 HAAS 009( 08 ST. LOUIS475365 HAAS 0333 05 ST. LOUIS 444444 FEGEN 0100 02 ST. PETERSBURG476236 FEGEN 037& 03 ST. PETERSBURG555555 FEGEN 0304 05 ST. PETERSBURG100000 JOHNSON 030# 06 ST. PETERSBURG248545 JOHNSON 0345 14 ST. PETERSBURG400000 JOHNSON 070) 08 ST. PETERSBURG878787 JOHNSON 1235 12 ST. PETERSBURG000101 CLARK 1500 10 TRENTON000104 CLARK 0500 03 TRENTON130101 CLARK 3200 20 TRENTON576235 CLARK 0100 03 TRENTON

One-level control breaks (minor key)

Two-level control break (major key)

(a) Sorted Data (by Location and Salesperson)

Figure 15.3 Two-level Control Break

Page 7: Lesson 9

SALES ACTIVITY REPORT PAGE 3

LOCATION: NEW YORKSALESPERSON: ADAMS

ACCOUNT # SALES COMMISSION 583645 145 6 800396 3,030 273

-------- ------- ** SALESPERSON TOTAL $ 3,175 $ 279

SALESPERSON: KARLSTROMACCOUNT # 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: MARCUSACCOUNT # 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

Figure 15.3 Two-level Control Break

(b) Partial Output

Page 8: Lesson 9

000069 BENWAY 023! 10 CHICAGO MIDWEST476530 BENWAY 023% 05 CHICAGO MIDWEST988888 BENWAY 0450 01 CHICAGO MIDWEST999340 BENWAY 0334 30 CHICAGO MIDWEST000100 HUMMER 010’ 05 CHICAGO MIDWEST649356 HUMMER 0345 05 CHICAGO MIDWEST694446 HUMMER 0904 10 CHICAGO MIDWEST

203000 HAAS 8900 05 ST. LOUIS MIDWEST277333 HAAS 009( 08 ST. LOUIS MIDWEST475365 HAAS 0333 05 ST. LOUIS MIDWEST

583645 KARLSTROM 0145 04 BALTIMORE NORTHEAST00396 KARLSTROM 3030 09 BALTIMORE NORTHEAST700039 MARCUS 0932 10 BALTIMORE NORTHEAST750020 MARCUS 0305 05 BALTIMORE NORTHEAST444333 ADAMS 100% 01 NEW YORK NORTHEAST555666 ADAMS 2003 20 NEW YORK NORTHEAST987654 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 037& 03 ST. PETERSBURG SOUTHEAST555555 FEGEN 0304 05 ST. PETERSBURG SOUTHEAST100000 JOHNSON 030# 06 ST. PETERSBURG SOUTHEAST248545 JOHNSON 0345 14 ST. PETERSBURG SOUTHEAST400000 JOHNSON 070) 08 ST. PETERSBURG SOUTHEAST878787 JOHNSON 1235 12 ST. PETERSBURG SOUTHEAST

(a) Sorted Data (by Region, Location, and Salesperson)

Figure 15.4 Three-level Control Break

One-level control breaks (tertiary key)

Two-level control breaks (secondary key)

Three-level control break (primary key)

Page 9: Lesson 9

SALES ACTIVITY REPORT PAGE 3

REGION: SOUTHEAST LOCATION: ST. PETERSBURG

SALESPERSON: BENWAYACCOUNT # SALES COMMISSION 000069 231- 23- 476530 235- 12-988888 450 5999340 334 100

-------- ------- ** SALESPERSON TOTAL $ 318 $ 70

SALESPERSON: HUMMER

ACCOUNT # SALES COMMISSION000100 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

SALES ACTIVITY REPORT PAGE 2

REGION: NORTHEAST LOCATION: BALTIMORE

SALESPERSON: BENWAYACCOUNT # SALES COMMISSION 000069 231- 23- 476530 235- 12-988888 450 5999340 334 100

-------- ------- ** SALESPERSON TOTAL $ 318 $ 70

SALESPERSON: HUMMER

ACCOUNT # SALES COMMISSION000100 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 1

REGION: MIDWEST LOCATION: CHICAGO

SALESPERSON: BENWAYACCOUNT # SALES COMMISSION 000069 231- 23- 476530 235- 12-988888 450 5999340 334 100

-------- ------- ** SALESPERSON TOTAL $ 318 $ 70

SALESPERSON: HUMMER

ACCOUNT # SALES COMMISSION000100 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

Page 10: Lesson 9

INCREMENTSALESPERSON

TOTAL

WRITEDETAIL

LINE

CALCULATECOMISSION

READSORTED

SALES-FILE

WRITESALESPERSON

HEADING

INITIALIZESALESPERSON

INCREMENTLOCATION

TOTAL

WRITESALESPERSON

TOTAL

PROCESSONE

TRANSACTION

PROCESSONE

SALESPERSON

SORTTRANSACTION

FILE

READSORTED

SALES-FILE

PREPARESALES

REPORT

WRITECOMPANY

TOTAL

Figure 15.5 One-level Algorithm (a) Hierarchy Chart (Use Keyed/Logical Files to read in sequence)

Page 11: Lesson 9

Figure 15.5 One-level Algorithm (b) Pseudocode

Sort transaction file on location, salespersonOpen sorted-file, print-fileRead first recordPERFORM UNTIL no more data Initialize salesperson totals MOVE SR-NAME to PREVIOUS-NAME Write salesperson headings PERFORM UNTIL SR-NAME NOT EQUAL PREVIOUS-NAME or no more data Calculate commission Write detail line Increment salesperson totals Read next record END PERFORM Write Salesperson totals Increment company totals by salesperson totals END PERFORMWrite company totalsClose filesStop run

Page 12: Lesson 9

Figure 15.7 Two-level Algorithm(a) Hierarchy Chart

INCREMENTSALESPERSON

TOTAL

WRITEDETAIL

LINE

CALCULATECOMISSION

WRITELOCATIONHEADING

INITIALIZELOCATION

INCREMENTREGIONTOTAL

WRITELOCATION

TOTAL

PROCESS ONESALESPERSON

READSORTED/LGLSALES-FILE

WRITESALESPERSON

HEADING

INITIALIZESALESPERSON

INCREMENTLOCATION

TOTAL

WRITESALESPERSON

TOTAL

PROCESSONE

TRANSACTION

PROCESSONE

LOCATION

READSORTED/LGLSALES-FILE

PREPARESALES

REPORT

WRITECOMPANY

TOTAL

Page 13: Lesson 9

Figure 15.7 Two-level Algorithm (b) Pseudocode

Sort transaction file on location, salespersonOpen sorted-file, print-fileRead first recordPERFORM UNTIL no more data Initialize location totals MOVE SR-LOCATION to PREVIOUS-LOCATION Write location headings PERFORM UNTIL SR-LOCATION NOT EQUAL PREVIOUS-LOCATION

or no more dataInitialize salesperson totalsMOVE SR-NAME to PREVIOUS-NAMEWrite salesperson headingsPERFORM UNTIL SR-NAME NOT EQUAL PREVIOUS-NAME or SR-LOCATION NOT EQUAL PREVIOUS-LOCATION or no more data Calculate commission Write detail line (if any) Increment salesperson totals Read next recordEND PERFORMWrite Salesperson totalsIncrement location totals

END PERFORM Write location totals Increment company totalsEND PERFORMWrite company totalsClose filesStop run

Page 14: Lesson 9

PROCESSONE

REGION

SORTTRANSACTION

FILE

READSORTED

SALES-FILE

PREPARESALES

REPORT

WRITECOMPANY

TOTAL

INCREMENTSALESPERSON

TOTAL

WRITEDETAIL

LINE

CALCULATECOMISSION

WRITELOCATIONHEADING

INITIALIZELOCATION

INCREMENTREGIONTOTAL

WRITELOCATION

TOTAL

PROCESS ONESALESPERSON

READSORTED

SALES-FILE

WRITEREGION

HEADINGS

INITIALIZEREGION

INCREMENTCOMPANY

TOTAL

WRITEREGIONTOTAL

PROCESSONE

LOCATION

WRITESALESPERSON

HEADING

INITIALIZESALESPERSON

INCREMENTLOCATION

TOTAL

WRITESALESPERSON

TOTAL

PROCESSONE

TRANSACTION

Figure 15.9 Three-level AlgorithmHierarchy Chart

Page 15: Lesson 9

Figure 15.9 Three-level Algorithm (b) Pseudocode

Sort transaction file on region, location, salespersonOpen sorted-file, print-fileRead first recordPERFORM UNTIL no more data Initialize location totals MOVE SR-REGION to PREVIOUS-REGION Write region headings PERFORM UNTIL SR-REGION NOT EQUAL PREVIOUS-REGION

or no more dataInitialize location totalsMOVE SR-LOCATION to PREVIOUS-LOCATIONWrite location headingsPERFORM UNTIL SR-LOCATION NOT EQUAL PREVIOUS-LOCATION or SR-REGION NOT EQUAL PREVIOUS-REGION or no more data Initialize salesperson totals

MOVE SR-NAME to PREVIOUS-NAME Write salesperson headings

PERFORM UNTIL SR-NAME NOT EQUAL PREVIOUS-NAME or SR-LOCATION NOT EQUAL PREVIOUS-LOCATION

or SR-REGION NOT EQUAL PREVIOUS-REGION

or no more data Calculate commission Write detail line (if any) Increment salesperson totals Read next record END PERFORM

Write Salesperson totals Increment location totals

END PERFORM Write location totals Increment region totals

END PERFORM Write region totals Increment company totals by region totalsEND PERFORMWrite company totalsClose filesStop run

Page 16: Lesson 9

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 level’s total (if any)

6. Increment the next higher level’s 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 level’s total (running total)

4. Read the next record