Using the ON-BREAK Option
In the following program, the ON-BREAK option of the PRINT command accomplishes two related tasks: it starts a new group each time the value of state changes, and it prints state only when its value changes. Note that ON-BREAK works as well for implicit as for explicit PRINT commands, such as in the following example, where state, city, name, and phone are implicitly printed as part of the select paragraph.
The sample program here is identical to ex5a.sqr except for the line that prints the state column, which appears like this:
Program ex5b.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) on-break
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
The output for the ex5b.sqr program is:
State City Name Phone
IN Davenport Harold Alexander Fink 3015553645
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
New York John Conway 2125552311
New York Corks and Bottles, Inc. 2125550021
New York Kate's Out of Date Dress Shop 2125559000
Queens Eliot Richards 2125554285
OH Cleveland Quentin Fields 2165553341
Everretsville Gregory Stonehaven 2165553109
Zanesville Isaiah J Schwartz and Company 5185559813
With break processing, the state abbreviation is printed only once for each group.