Saving a Value When a Break Occurs

In ex5d.sqr, the state_tot procedure prints the total number of customers per state. Because it is called with the AFTER argument, this procedure is run only after the value of the ON-BREAK column, state, has changed.

Sometimes, however, you may want to print the previous value of the ON-BREAK column in the AFTER procedure. For example, you may want to print the state name and the totals for each state. Printing the value of state will not work because its value will have changed by the time the AFTER procedure is called.

The solution is to save the previous break value in a string variable. To do this, use the SAVE qualifier of ON-BREAK. For example:

begin-select
state (,1) on-break after=state_tot save=$old_state

You can then print the value of $old_state in the state_tot procedure.