Presentation on theme: "This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed."— Presentation transcript:
This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed. If you have opened this lesson in PowerPoint, use the PowerPoint menus to view it in slide show mode. If you have opened this lesson in a browser and see a bar similar to that below, click on the Slide Show icon A notice similar to the one below may appear warning that ActiveX or other scripts are disabled. Enable the controls for this website in order to see the animations.
The Control Break Algorithm This slide show discusses a famous algorithm for generating reports. Christine S. Wolfe Ohio University Lancaster 2008-Aug-01 Vocabulary: control break detail footer grand total header level subtotal summary
The report shown below is a type that is commonly found in business. It lists a set of records that are grouped together based on some common value. At the end of each group, subtotals are displayed and a grand total appears at the end. This type of report is called a “control break” report. Click Tip Control break reports are named that way because the report takes a little “break” in the processing every time the value in the “control” field changes.
1000100.00 1000200.00 3000210.00 1000 50.00 2000300.00 3000150.00 1000 30.00 3000 50.00 SalesmanIDAmount The data below represents the text file that contains the data for the report. If we only needed a grand total, the solution would be easy. It would be a simple loop like the ones we’ve used to calculate totals and find highest and lowest values. Total 8 1090.00
1000100.00 1000200.00 3000210.00 1000 50.00 2000300.00 3000150.00 1000 30.00 3000 50.00 SalesmanID Amount NumSales TotalSales 0 0 1000 100.00 1 200.00 2 300.00 1000 210.00 3000 3 510.00 8 1090.00 50.00 3000 Click through the algorithm to calculate the total amount sold.
1000100.00 1000200.00 1000 30.00 1000 50.00 2000300.00 3000150.00 3000 50.00 3000210.00 SalesmanIDAmount The previous example did not produce subtotals for each sales person. To calculate subtotals, the input file must first be sorted on the control field. Salesman Num Total 1000 4 380.00 2000 1 300.00 3000 3 410.00 Total 8 1090.00
This is the algorithm seen on slide 5 that was used to calculate the grand total.
The steps outlined in blue must be added to the algorithm to process the control break.
Key to solving a control break problem is to save the value of the control field into a holding variable so that each new record can be compared to the holding value in order to determine whether or not the control value has changed. Variables must also be declared and initialized to hold the subtotals.
The subtotal variables are updated at the same time and in the same way as the grand totals.
As each record is read, the value in the control field is compared to the holding value. If they are different it means that it is time to end one group and start another group. 3 steps make up the control break processing: The contents of the holding variables and subtotal variables are printed. The holding variable(s) are reset to the new value. The subtotal variables are reset to zero.
After the last record is processed, the subtotals for the last group are displayed.
This is another control break report. Click to see the parts of the report.
REPORT HEADER REPORT FOOTER GROUP HEADER GROUP FOOTER DETAIL LINE
group info (before read) description report header (before reads) details 1 / record report footer (after reads) Grand Totals group info (after read) Sub-Totals group info (before read) description details 1 / record group info (after read) Sub-Totals This is the only information that is read directly from the file. This is the layout of a single level control break. (You can tell it is a single level because there is only one level of grouping.) A group is a set of records that have the same value in one of their fields.
group header report header details report footer group footer group header details group footer This is the layout of a 2-level control break. (You can tell it is a 2- level because there are 2 levels of grouping.) group header group footer details group header details group footer details group header group footer group header details group footer details