Sorts and Breaks in Reports
To produce a report that is orderly and easy to read, you must sort the retrieved data based on one or more of the columns. The data must be sorted if you want to include subtotals or other summary information in your report. In addition, you must specify the break columns in which a change of value signals Report-Writer to look for subtotaling or other special statements. For example, the Population Example in the appendix, “Report-Writer Report Examples” is a 1970 U.S. population report by region and state. To generate the regional population subtotals, the states must first be grouped by the value of the region column in the database, and breaks must occur at each change of value in the region column.
The easiest way to group rows is to sort them on the column that is used as the grouping column (in this example, region). Often, a report is sorted on more than one column. In such cases, the rows are first grouped on the basis of the first sort column (called the major sort column) and, within those groups, on the basis of the next sort column (called a minor sort column), and so forth. The sort order is specified by naming the columns in the .sort statement in a section containing report set‑up statements. If you have a .query statement with an order by clause, you cannot use the .sort statement.
By default, Report-Writer assumes the break columns are the same as the sort columns. In the above example, for instance, no other breaks need be specified. However, you can override the default breaks by specifying break columns with the .break statement. Use the .break statement to specify your break columns if you have a .query statement with an order by clause.
The currently active list of break columns (specified by either the .sort or .break statement) is known as the break list. The first column in the break list indicates a major break column, while those that follow are considered minor break columns. A break on one break column automatically produces a break on all subsequent break columns in the currently active break list.
In the Account Example of the appendix “Report-Writer Report Examples,” break columns are not explicitly specified, so breaks can occur on the sort columns. Report-Writer sorts the data based on acctnum (the major sort column) and, within acctnum, based on date. When a change occurs in the value of date, the date break occurs and Report-Writer looks for some of your formatting instructions to process. When a change in value occurs in the acctnum column, breaks in both acctnum and date occur.
You need not specify actions for every break in your report. You can specify sort columns (which produce breaks) simply for the appearance of the report. In the Population Example, in the appendix, “Report-Writer Report Examples,” breaks in region invoke a number of summary and heading actions, whereas breaks in state do not.
Under certain conditions, such as with numeric columns of rounded values, breaks occur by default when the formatted value changes, not when the actual value changes. For example, assume a column is rounded to the first decimal place. There can be no break between the actual values of 35.87 and 35.92, because each rounds to 35.9.
You have control over how numeric values are rounded through the format specification. For more information, see Format Specifications in the chapter “Report-Writer Expressions and Formats.” To force breaks to occur on the actual values rather than on the formatted values, specify the ‑
t flag (see
report Command--Run a Report) on the report command line.
Last modified date: 08/14/2024