Control Break Processing ITE 370 Control Break Processing
Control Break Processing ITE 370
Control Break Processing • Classic File Processing Technique • Used in Main Frame Systems • Used in Report Utilities – Crystal Reports • Designed to work on the file – Regardless of Length – Even if Length Changes • Don’t hard code to file • You know the design & makeup of file, but not content
• • • • • • • • • • Control Break Algorithm - Generic Control. Var Grand. Total Group. Total File Row . Info . Sum. Field . Control. Field ‘* control variable which holds value of current group being processed ‘* accumulator for whole file ‘* accumulator for current group, (current value of Control. Var), displaying a sub-total ‘* file ordered by control variable, i. e. grouping variable ‘* contains information from a row of File ‘* information on row to display ‘* numeric data to sum for a group ‘* stores value for control variable, i. e. the grouping variable BEGIN File. Open Row File. Read ‘* read first row of data from File Control. Var Row. Control. Field Display Heading with Control. Var Group. Total 0 Grand. Total 0 While Not File. EOF If Row. Control. Field <> Control. Var Then Display Sub-totals with Group. Total Grand. Total + Group. Total Control. Var Row. Control. Field Display Heading with Control. Var Group. Total 0 End If Display Row. Info, Row. Sum. Field Group. Total + Row. Sum. Field Row File. Read ‘* read next row of data from file End While ‘* display sub-totals for last group Display Group. Total Grand. Total + Group. Total Display Grand. Total File. Close END
Example • Print a report to include the names of baseball players and the number of home runs for each player, each team & total homeruns (grouped by team / nickname) • Requires: – Sequential File Processing (Data Reader) – Header – Detail Lines – Total Lines
Input File – Baseball (sorted by Control Variable - Nickname) Last Name Home. Runs Nickname Smokey 41 Angels Jones 28 Angels Chapman 14 Orioles Smith 25 Red Sox Brewer 29 Red Sox Miller 15 White Sox Kennedy 35 White Sox Parker 40 White Sox Jackson 29 White Sox
Baseball Example • • • Begin Players. Open Data File Players. Read Get player data from row. Read gives value to Row. Info Team Player. Nickname, Assign Nickname to Control Var (Team) Display Heading (Team) Output Team. HR Initialize Group Total to 0 Total. HR Initialize Grand Total to 0 While Not Players. EOF While there are players, process the detail rows of report If Player. Nickname <> Team Then Check to see if the is the End of the Section • • • • • Display Team. HR Subtotals Total. HR = Total. HR + Team. HR Increment Grand Totals Team Player. Nickname, New Team Name Display Heading Team Re-Initialize the Group Total for new Team. HR = 0 End IF Display (Players. Last, Player. HR) Output Players Name, Number of HR Team. HR = Team. HR + Player. HR Increment Group Total Player. Read, Read next row End While End Display Team. HT Display Team Subtotal Total. HR = Total. HR + Team. HR Increment Grand Total Display Total. HR Display Grand Total Players. Close Data File
Variables • Control Variable – Holds the Value of the current control variable – Team Nickname • Counters and Accumulators – Group Totals • Team Homeruns – Grand Totals • Total Homeruns • Row Information – Player. Last – Sum Field – Player. Home. Runs – Control Field – Player. Nickname
Walk Through Control Var (Team) Row. Info (Player. Last) Output Group Total (Team HR) . Sum Field (Player. HR) Grand Total (Total HR) . Control Field (Player. Nickname)
Walk Through Control Var (Team) Group Total (Team HR) Grand Total (Total HR) Angels 0 41 0 Row. Info (Player. Last) Smokey Output Angels: Smokey 41 . Sum Field (Player. HR) 41 . Control Field (Player. Nickname) Angels
Walk Through Control Var (Team) Angels Row. Info (Player. Last) Jones Output Angels: Smokey 41 Jones 28 Group Total (Team HR) 0 41 69. Sum Field (Player. HR) 28 Grand Total (Total HR) 0 . Control Field (Player. Nickname) Angels
Walk Through Control Var (Team) Angels Row. Info (Player. Last) Chapman Output Angels: Smokey 41 Jones 28 69 Group Total (Team HR) 0 41 69. Sum Field (Player. HR) 14 Grand Total (Total HR) 0 . Control Field (Player. Nickname) Orioles
Walk Through Control Var (Team) Group Total (Team HR) Grand Total (Total HR) Orioles 0 14 0 69 Row. Info (Player. Last) Chapman Output Angels: Orioles: Smokey 41 Jones 28 69 Chapman 14 . Sum Field (Player. HR) 14 . Control Field (Player. Nickname) Orioles
Walk Through Control Var (Team) Orioles Row. Info (Player. Last) Chapman Output Angels: Orioles: Smokey 41 Jones 28 69 Chapman 14 Group Total (Team HR) 0 14. Sum Field (Player. HR) 14 Grand Total (Total HR) 0 69. Control Field (Player. Nickname) Orioles
Walk Through Control Var (Team) Red Sox Row. Info (Player. Last) Smith Output Angels: Orioles: Red Sox Smokey 41 Jones 28 69 Chapman 14 14 Group Total (Team HR) 0 25. Sum Field (Player. HR) 25 Grand Total (Total HR) 0 69 83. Control Field (Player. Nickname) Red Sox
Walk Through Control Var (Team) Red Sox Row. Info (Player. Last) Smith Group Total (Team HR) 0 25. Sum Field (Player. HR) Grand Total (Total HR) 0 69 83. Control Field (Player. Nickname) 25 Red Sox Output Angels: Orioles: Smokey 41 Jones 28 69 Chapman 14 14 Red Sox Smith 25
Walk Through Control Var (Team) Red Sox Row. Info (Player. Last) Brewer Group Total (Team HR) 0 25 54. Sum Field (Player. HR) Grand Total (Total HR) 0 69 83. Control Field (Player. Nickname) 29 Red Sox Output Angels: Orioles: Smokey 41 Jones 28 69 Chapman 14 14 Red Sox Smith Brewer 25 29
Walk Through Control Var (Team) Red Sox Row. Info (Player. Last) Miller Group Total (Team HR) 0 25 54. Sum Field (Player. HR) Grand Total (Total HR) 0 69 83. Control Field (Player. Nickname) 15 White Sox Output Angels: Orioles: Smokey 41 Jones 28 69 Chapman 14 14 Red Sox Smith Brewer 25 29 54
Walk Through Control Var (Team) White Sox Row. Info (Player. Last) Miller Group Total (Team HR) 0 15 . Sum Field (Player. HR) Grand Total (Total HR) Grand Total 0 (Total HR) 69 83 137. Control Field (Player. Nickname) 15 White Sox Output Angels Orioles Smokey 41 Jones 28 69 Chapman 14 14 Red Sox Smith Brewer White Sox Miller 25 29 54 15
Final Output Angels Smokey Jones Team HR 41 28 69 Chapman Team HR 14 14 Smith Brewer Team HR White Sox Miller Kennedy Parker Jackson Team HR Total HR 25 29 54 Orioles Red Sox 15 35 40 29 119 256
Control Break Processing • Program 1 • You must determine when the section breaks need to occur • Requirements: – Connection Object – Command Object (SQL Command) – Data Reader Object – Read / Compare Items in Data Reader Object
- Slides: 20