Suppose I have code such as:
READ MYVIEW IN LOGICAL SEQUENCE BY CITY
*
AT BREAK OF CITY
break code, e.g. citywide subtotals
END-BREAK
The way this “works” is:
Natural reads a record from Adabas.
Natural checks to see if the new value of CITY is different than the old value for CITY. If so, Natural executes the AT BREAK logic, then proceeds to execute the logic of the READ loop. If not, Natural simply executes the READ loop.
Suppose the last city on my file is PARIS. There is no “next record” to cause the processing of PARIS subtotals. Thus, Natural “forces” a final break at the end of the loop. This is done before an AT END OF DATA clause (where I might have logic for final totals).
While it is true one can always write code using IFs to perform logic similar to that of AT BREAK, a programmer must write (and debug/maintain) code to deal with the following that Natural does automatically:
The first record (new value is different than old value, but old value is null).
System functions (computed and RESET automatically by Natural)
The final “forced” break, as discussed above.
Multiple breaks. For example, I am reading by a superdescriptor that concatenates city and state. I have two successive records with values Portland (city) - Maine (state) and Portland (city) - Oregon (state). Unless the programmer is careful, their program might only recognize the state break, not the city break. In Natural, by placing the AT BREAK OF CITY clause prior to the AT BREAK OF STATE clause, Natural knows there is an implied hierarchy, and a state break “forces” a city break.
One further note. Suppose I have a clause such as AT BREAK OF CITY. The only time, while in the AT BREAK clause, that OLD (CITY) equals CITY is during the final forced break. (forgetting about special cases like WHERE clauses, security, etc.)
steve