28 10-1 structured cobol programming nancy stern hofstra university robert a. stern nassau community...

28
28 10-1 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin- Stout John Wiley & Sons, Inc. PowerPoint Winifred J. Rex Presentation Bowling Green State University 10th edition

Upload: cameron-mcgee

Post on 27-Dec-2015

223 views

Category:

Documents


2 download

TRANSCRIPT

28 10-1

Structured COBOL Programming

Nancy Stern Hofstra University

Robert A. Stern Nassau Community College

James P. Ley University of Wisconsin-Stout

John Wiley & Sons, Inc.

PowerPoint Winifred J. Rex Presentation Bowling Green State University

10th edition

28 10-2

Control Break Processing

Chapter 10

28 10-3

Chapter Objectives

To familiarize you with

• Main types of computer-generated reports

• Techniques used for efficient printing of group reports and control totals

Control break processing and control break printing

28 10-4

Chapter Contents

• Introduction to Control Break Processing

• Program Requirements for Control Break Processing

Multiple-Level Control Breaks– Program 5

28 10-5

Types of Reports

• Detail or Transaction Reports– Include one or more lines of output for

each input record read

• Exception Reports– Printout of individual records that meet

(or fail to meet) certain criteria

• Summary Reports– Summarizes rather than itemizes to

provide more comprehensive information

28 10-6

Control Break Processing

• Produces summary report using control fields to indicate when totals are to print

• Records with same value for control field grouped together in file

• Totals printed for each group of records with same control field value

28 10-7

Control Break Example

• Consider file of sales records, each with three fields: – Salesperson's department number,

salesperson's number, sales amount

• Department number is control field

• Records in sequence by control field– All records for salespeople in Dept 01

followed by records for those in Dept 02, …

28 10-8

Sample Sales Input Data

01 12345 098855

01 12346 353700

01 12347 003499

02 12222 987700

02 12234 008777Amt-Of-Sales-In

SlsNo-In (Salesman Number)

Dept-In

Note: data is SORTED!!!

28 10-9

Control Break Example

• Report includes detail printing– One line for each record with salesperson's

amount of sales

• Report also includes summary lines or group printing – Total line written for each department– After all records for Dept 01 read and

printed, total for Dept 01 printed– Same is done for Dept 02, and so on

28 10-10

Control Break Sample Report

Dept Salesperson No Amt of Sales

01 12345 $988.55

01 12346 $3,537.00

01 12347 $34.99

Total for Dept is $4,560.54

02 12222 $9,877.00

02 12234 $87.77

Total for Dept is $9,964.77

28 10-11

Control Break Example• Records must be in sequence by some control field

(department number)– Here, dept number– Could be classification (frosh, soph, junior, …)– Any kind of meaningful classification…

• Sales records for Dept 01 read in, printed, Dept total accumulated

• Continues until record read in with different Dept number

• Change in Dept triggers printing of Dept total for Dept 01

• May want a grand total for all departments at the end too.

28 10-12

Single-Level Control Break

• Single-level means program has only one control field whose value triggers printing of totals

• Control break occurs when there is change in control field value from one record to the next– Recall: data is sorted.

28 10-13

Single-Level Control Break

• Many steps (initialization, heading routines) same as previous programs

Detail routine must be modified to check for control breaks

New module added to handle control break processing

28 10-14

Detecting a Control Break

• For first record read, move control field to hold area in WORKING-STORAGE– Then process this record.

• If control field of subsequent records is same as hold area – Perform detail processing

• If they are not equal, control break occurs – Perform control break routine

28 10-15

Detail Processing

When control field is equal to hold area

• Add amount to control total or other values that are being accumulated…

• Print detail record (if desired)

• Read next record

• Continue until there is a change in the value of the control field.

28 10-16

Control Break Routine

If control field of record read is not equal to hold area, you must suspend normal record processing to handle the control break:– Print control total for previous group– Initialize control total field to zero– Reinitialize hold field with new control field value of

the record just read,

• Perform detail processing of this new ‘first’ record and proceed as before.

28 10-17

Handling first record

• First record has no previous control field value for comparison

• Add field to use as "flag" to determine if record is first one processed (e.g., First-Record initialized to 'YES')

• When record read, if First-Record = 'YES'– Save control field value in hold area– Turn "off" flag by setting it to 'NO'

28 10-18

Forcing Final Control Break

• Totals printed when record with new control field is read

• Last group of records has no subsequent record to trigger printing because we hit end of file.

• Include statements in end of job routine to move final group total to output record and print it with its totals as you would on a normal control break.

28 10-19

Printing a Final Total

• May accumulate final total by – Adding amount from each record to

“control group total” and “final total” in detail routine

– Adding control group total to final total in control break routine

• Second method more efficient since additions made once for each group instead of once for each record

28 10-20

Multiple Level Control Breaks

• Suppose a sales record is created each time a salesperson makes a sale

• Each salesperson may have multiple sales records

• Report will include two levels of totals– Total sales for each salesperson– Total sales for each department

28 10-21

Multiple Level Control Breaks

• Two control fields: Dept-In and SlsNo-In

• Records sorted by major control field (Dept-In)

• Within department, sorted by minor control field (SlsNo-In)

28 10-22

Sample Sales Input Data

Dept-In SlsNo-In Amt-Of-Trans-In

01 004 127.23

01 004 100.14

01 006 027.45

01 006 052.23

01 006 126.27

02 003 111.14

02 003 027.23

In sequence within Dept 01

Discuss the sort sequence…

28 10-23

Double-Level Control Break• Two hold areas, one for each control field Check for control break on each

– If no change in Dept-In or SlsNo-In, just add Amt-Of-Trans-In to salesperson total

– If Dept-In changes, perform major control break routine

– If no change in Dept-In but SlsNo-In changes, perform minor control break routine

But this requires care, especially when printing totals, resetting control variable values (for next record) and clearing accumulators for the minor break without messing up the totals for the major break.

28 10-24

Major Control Break Routine• Begins by forcing minor control break

– This processes last salesperson’s total for previous department– Do all that is required for a single control break based on

salesman number….– This may involve printing salesman totals, etc…Now:

• Print department total• Reinitialize department total to zero• Save new Dept-In in hold area• Print heading for new department and all that.• Note: you will likely have a new department.• Don’t forget EOF considerations, which will force both a

major and minor control break.

28 10-25

SORTED INPUT FILE - FOR DEMO ON SINGLE CONTROL BREAK

\DEPTNAME SALES OTHER FIELDS

1 ALBERT 426.00

1 BOZO 726.00

1 CONNER 260.00

2 AMATO 4567.00

2 BISHOP 634.00

3 ALPHONSE 300.00

3 COOK 500.00

3 JASPER 395.00

3 MOTHER 2496.00

4 JOCKO 789.00

4 JULIET 000.00

4 NOVEMBER 100.00

4 OSCAR 2000.00

7 ALPHA 6299.00

7 BRAVO 7000.00

7 COCOA 420.00

8 DELTA ....

8 FOXTROT

8 GOLF

9 ROMEO

9 SIERRA

9 TANGO

10 EOF

28 10-26

Minor Control Break Routine

• Print total for previous SlsNo-In

• Add salesperson total to department total

• Initialize salesperson total to zero

• Move new SlsNo-In to hold area

28 10-27

Chapter Summary

• Control break program may have any number of control fields

• All input records must be in sequence by minor control fields within intermediate control fields within major control fields

• Sort file before processing if records are not already in this order

28 10-28

Chapter Summary

• Control break routines– Higher-level breaks force lower-level

breaks– Appropriate control total line printed– Appropriate control total is initialized– Appropriate control field is initialized