Understanding Break Logic
A break is a change in the value of a column or variable. Records with the same value—for example, records with the same value for state—logically belong to a group. When a break occurs, a new group begins.
Use break logic in a report to:
Add white space to reports.
Avoid printing redundant data.
Perform conditional processing on variables that change.
Print subtotals.
For example, you can use break logic to prepare a sales report with records that are grouped by product, region, salesperson, or all three. Break logic also enables you to print column headings, count records, subtotal a column, and perform additional processing on a count or subtotal.
Here is a sample program without break logic:
Program ex5a.sqr
begin-program
do list_customers
end-program
begin-heading 2
print 'State' (1,1)
print 'City' (1,7)
print 'Name' (1,24)
print 'Phone' (1,55)
end-heading
begin-procedure list_customers
begin-select
state (,1)
city (,7)
name (,24)
phone (,55)
position (+1) ! Advance to the next line
from customers
order by state, city, name
end-select
end-procedure ! list_customers
State City Name Phone
IN Davenport Harold Alexander Fink 3015553645
IN Miningville Harry's Landmark Diner 3175550948
MI Bell Harbor Sam Johnson 3135556732
NH Frogline Jerry's Junkyard Specialties 6125552877
NJ Teaneck Clair Butterfield 2015559901
NM Big Falls Joe Smith and Company 8085552124
NY Mamaroneck Harriet Bailey 9145550144
NY New York John Conway 2125552311
NY New York Corks and Bottles, Inc. 2125550021
NY New York Kate's Out of Date Dress Shop 2125559000
NY Queens Eliot Richards 2125554285
OH Cleveland Quentin Fields 2165553341
OH Everretsville Gregory Stonehaven 2165553109
OH Zanesville Isaiah J Schwartz and Company 5185559813
When you sort output by state, city, and name (note the ORDER BY clause in the BEGIN-SELECT statement), the records are grouped by state. To make the grouping more apparent, you can add a break.