150 likes | 164 Views
Learn the fundamentals of control breaks in report generation, including single and multiple control breaks with practical examples and step-by-step instructions. Enhance your data analysis skills.
E N D
Any Questions? Control Breaks
Agenda • Control Breaks • Also known as Reports with sub-totals.
Report Types • Transaction Reports • Summary or Group Reports • Exception Reports
Control Break • Occurs when there is a change in key fields when reading sequentially through a file
Where’s the Control Break? Customer Accounts Date: 05/04/05 Page: 999 Date Amount Customer: 1015 Cindy Laurin 05/01/00 $100.00 05/02/00 $200.00 05/03/00 $300.00 * Totals: 1015 Cindy Laurin $600.00 Customer: 1016 Bruce Nugent 05/01/00 $100.00 * Totals: 1016 Bruce Nugent $100.00 ** Totals: All Customers $700.00 *** End of Report
What do you do at a Control Break? • Print the totals for the save or previous key • Initialize the accumulators used for the group or level • Print headings for the new or file key
Single Control Breaks Example • QGPL/CHAP8AS4 contains all a record for each student enrolled in College X. • Each student’s record lists their name, student number, school, class, GPA and number of credits. • Your task is to produce a Summary Report listing Average GPAs for each school to find out which school has the easier program.
Steps to solve problem • Create a logical file over CHAP8AS4 that sorts the data in School Sequence. • Write a Control Break program that calculates and prints the average for each school.
Single Control Break(using ifs) Read the First Record (check for EOF) If not EOF Write the heading for file-key Move file-key to save-key Do While not End of File If save-key file-key Calculate & Write totals for save-key Initialize Accumulators Move file-key to save-key Write headings for file-key Process Record Read the next Record (check for EOF) ENDDO Calculate & Write totals for save-key
Single Control Break (Using Nested Loops) Read the First Record (check for EOF) Do While not End of File Write the heading for file-key Move file-key to save-key Do While file-key = save-key and not EOF Process Record Read the next record (check for EOF) ENDDO Calculate & Write totals for save-key Initialize Accumulators ENDDO
Multiple Control Breaks Example • QGPL/CHAP8AS4 contains all a record for each student enrolled in College X. • Each student’s record lists their name, student number, school, class, GPA and number of credits. • Your task is to produce a Summary Report listing Average GPAs for each class and school to find out which school has the easier program.
Steps to solve problem • Create a logical file over CHAP8AS4 that sorts the data in School & Class Sequence. • School is the Primary or Major Key • Class is the Secondary or Minor Key • Write a Control Break program that calculates and prints the average for each class & school.
Multiple Control Breaks (Using Ifs) Read the First Record (check for EOF) If not EOF Write the headings for file-key Move file-key to save-key Do While not End of File If save-Primary-key file-Primary-key Calculate & Write totals for save-Secondary-key Calculate & Write totals for save-Primary-key Initialize Primary & Secondary Accumulators Move file-key to save-key Write headings for Primary & Secondary file-keys If save-Secondary-key file-Secondary-key Calculate & Write totals for save-Secondary-key Initialize Secondary Accumulators Move file-Secondary-key to save-Secondary-key Write headings for file-Secondary-key Process Record Read the next Record (check for EOF) ENDDO Calculate & Write totals for save-Secondary-key Calculate & Write totals for save-Primary-key
Multiple Control Breaks (Using Nested Loops) Read the First Record (check for EOF) Do While not End of File Write the headings for file-Primary-key Move file-Primary-key to save-Primary-key Do While not EOF and file-Primary-key = save-Primary-key Write headings for file-Secondary-key Move file-Secondary-key to save-Secondary-key Do While not EOF and file-Secondary-key = save-Secondary- key and file-Primary-key = save-Primary-key Process Record Read the next record (check for EOF) ENDDO Calculate & Write totals for save-Secondary-key Initialize Secondary Accumulators ENDDO Calculate & Write totals for save-Primary-key Initialize Primary Accumulators ENDDO