Control Break Processing

20
Control Break Processing ITE 370

description

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 - PowerPoint PPT Presentation

Transcript of Control Break Processing

Page 1: Control Break Processing

Control Break Processing

ITE 370

Page 2: Control Break Processing

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

Page 3: Control Break Processing

Control Break Algorithm - Generic• ControlVar ‘* control variable which holds value of current group being processed• GrandTotal ‘* accumulator for whole file• GroupTotal ‘* accumulator for current group,(current value of ControlVar), displaying a sub-total• File ‘* file ordered by control variable, i.e. grouping variable • Row ‘* contains information from a row of File• .Info ‘* information on row to display• .SumField ‘* numeric data to sum for a group• .ControlField ‘* stores value for control variable, i.e. the grouping variable

• BEGIN• File.Open• Row File.Read ‘* read first row of data from File• ControlVar Row.ControlField• Display Heading with ControlVar• GroupTotal 0• GrandTotal 0•  • While Not File.EOF• • If Row.ControlField <> ControlVar Then• Display Sub-totals with GroupTotal• GrandTotal GrandTotal + GroupTotal• ControlVar Row.ControlField• Display Heading with ControlVar• GroupTotal 0• End If•  • Display Row.Info, Row.SumField• GroupTotal GroupTotal + Row.SumField•  • Row File.Read ‘* read next row of data from file• End While•  • ‘* display sub-totals for last group• Display GroupTotal• GrandTotal GrandTotal + GroupTotal• Display GrandTotal•  • File.Close• END

Page 4: Control Break Processing

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

Page 5: Control Break Processing

Input File – Baseball (sorted by Control Variable - Nickname)

Last Name HomeRuns 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

Page 6: Control Break Processing

Baseball Example• Begin

• Players.Open 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

• TeamHR Initialize Group Total to 0

• TotalHR 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 TeamHR Subtotals

• TotalHR = TotalHR + TeamHR Increment Grand Totals

• Team Player.Nickname, New Team Name

• Display Heading Team

• TeamHR = 0 Re-Initialize the Group Total for new Team

• End IF

•  

Display (Players.Last, Player.HR) Output Players Name, Number of HR

• TeamHR = TeamHR + PlayerHR Increment Group Total

• Player Player.Read, Read next row

• End While

•  

• Display TeamHT Display Team Subtotal

• TotalHR = TotalHR + TeamHR Increment Grand Total

• Display TotalHR Display Grand Total

• Players.Close Close Data File

•  

• End

Page 7: Control Break Processing

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.HomeRuns– Control Field – Player.Nickname

Page 8: Control Break Processing

Walk ThroughControl Var (Team) Group Total (Team HR) Grand Total (Total HR)

.Sum Field (Player.HR) .Control Field (Player.Nickname)

Control Var (Team) Group Total (Team HR) Grand Total (Total HR)

Row.Info (Player.Last)

Output

Page 9: Control Break Processing

Walk ThroughControl Var (Team) Group Total (Team HR) Grand Total (Total HR)

Smokey

.Sum Field (Player.HR)

41

.Control Field (Player.Nickname)

Control Var (Team) Group Total (Team HR)

041Angels

Grand Total (Total HR)

0

Row.Info (Player.Last)

Angels

Output

Angels:Smokey 41

Page 10: Control Break Processing

Walk ThroughControl Var (Team) Group Total (Team HR) Grand Total (Total HR)

Jones

.Sum Field (Player.HR)

28

.Control Field (Player.Nickname)

Control Var (Team) Group Total (Team HR)

04169

Angels

Grand Total (Total HR)

0

Row.Info (Player.Last)

Angels

Output

Angels:Smokey 41Jones 28

Page 11: Control Break Processing

Walk ThroughControl Var (Team) Group Total (Team HR) Grand Total (Total HR)

Chapman

.Sum Field (Player.HR)

14

.Control Field (Player.Nickname)

Control Var (Team) Group Total (Team HR)

04169

Angels

Grand Total (Total HR)

0

Row.Info (Player.Last)

Orioles

Output

Angels:Smokey 41Jones 28

69

Page 12: Control Break Processing

Walk ThroughControl Var (Team) Group Total (Team HR) Grand Total (Total HR)

Chapman

.Sum Field (Player.HR)

14

.Control Field (Player.Nickname)

Control Var (Team) Group Total (Team HR)

014Orioles

Grand Total (Total HR)

069

Row.Info (Player.Last)

Orioles

OutputAngels:

Smokey 41Jones 28

69Orioles:

Chapman 14

Page 13: Control Break Processing

Walk ThroughControl Var (Team) Group Total (Team HR) Grand Total (Total HR)

Chapman

.Sum Field (Player.HR)

14

.Control Field (Player.Nickname)

Control Var (Team) Group Total (Team HR)

014

Orioles

Grand Total (Total HR)

069

Row.Info (Player.Last)

Orioles

Output

Angels:Smokey 41Jones 28

69Orioles:

Chapman 14

Page 14: Control Break Processing

Walk ThroughControl Var (Team) Group Total (Team HR) Grand Total (Total HR)

Smith

.Sum Field (Player.HR)

25

.Control Field (Player.Nickname)

Control Var (Team) Group Total (Team HR)

025

Red Sox

Grand Total (Total HR)

06983

Row.Info (Player.Last)

Red Sox

OutputAngels:

Smokey 41Jones 28

69Orioles:

Chapman 1414

Red Sox

Page 15: Control Break Processing

Walk ThroughControl Var (Team) Group Total (Team HR) Grand Total (Total HR)

Smith

.Sum Field (Player.HR)

25

.Control Field (Player.Nickname)

Control Var (Team) Group Total (Team HR)

025

Red Sox

Grand Total (Total HR)

06983

Row.Info (Player.Last)

Red Sox

Output

Angels: Red SoxSmokey 41 Smith 25Jones 28

69Orioles:

Chapman 1414

Page 16: Control Break Processing

Walk ThroughControl Var (Team) Group Total (Team HR) Grand Total (Total HR)

Brewer

.Sum Field (Player.HR)

29

.Control Field (Player.Nickname)

Control Var (Team) Group Total (Team HR)

02554

Red Sox

Grand Total (Total HR)

06983

Row.Info (Player.Last)

Red Sox

Output

Angels: Red SoxSmokey 41 Smith 25Jones 28 Brewer 29

69Orioles:

Chapman 1414

Page 17: Control Break Processing

Walk ThroughControl Var (Team) Group Total (Team HR) Grand Total (Total HR)

Miller

.Sum Field (Player.HR)

15

.Control Field (Player.Nickname)

Control Var (Team) Group Total (Team HR)

02554

Red Sox

Grand Total (Total HR)

06983

Row.Info (Player.Last)

White Sox

Output

Angels: Red SoxSmokey 41 Smith 25Jones 28 Brewer 29

69 54Orioles:

Chapman 1414

Page 18: Control Break Processing

Walk ThroughControl Var (Team) Group Total (Team HR) Grand Total (Total HR)

Miller

.Sum Field (Player.HR)

15

.Control Field (Player.Nickname)

Control Var (Team) Group Total (Team HR)

015White Sox

Grand Total (Total HR)0

6983

137

Row.Info (Player.Last)

White Sox

Output

Angels Red SoxSmokey 41 Smith 25Jones 28 Brewer 29

69 54Orioles White Sox

Chapman 14 Miller 1514

Page 19: Control Break Processing

Final OutputAngels

Smokey 41Jones 28Team HR 69

OriolesChapman 14Team HR 14

Red SoxSmith 25Brewer 29Team HR 54

White SoxMiller 15Kennedy 35Parker 40Jackson 29Team HR 119

Total HR 256

Page 20: Control Break Processing

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