7.8 Printing Totals

Most reports that show a column of numbers also show sub-totals and a grand total. An example of a sub-total would be the total of all invoices for a particular customer. An example of a grand total would be the total of all invoices for all customers. In either case, the total is always reset to zero after printing the amount. Thus, the customer sub-total only contains the total for a particular customer because it is reset to zero prior to processing the next customer.

Some reports need to show a cumulative total. An example might be printing an account balance after each transaction. For these types of totals the amounts should not be reset to zero after printing. This type of total is referred to as a Running Total.

To illustrate total fields, we will add (to the example used in the preceding section) a total count of subscriptions to all magazines which will be printed at the end of the report. (Note: Currently our report shows only the number of subscriptions to each magazine.) This total field should be placed in the Report Footing section, as this is the section which is printed only at the end of the report.

We want our total to be 'lined up' under the column labeled Subscribers. An easy way to do this is to start with the detail line itself (i.e., the line contained in the Detail section). With the Report Section screen displayed, press the NEXT key <F3> or the PREVIOUS key <F2> until the Detail section is displayed, as shown in below:

gifs/00000001.gif

Now position the cursor on the starting column of the field to be totaled (i.e., the subscriber field) and use the PREVIOUS or NEXT function to display the appropriate Report Section screen (in this case, the Report Footing section).

Notice that the cursor did not move when you changed sections. The cursor is still in the same column as the starting column of the subscriber field. At this point, you could press the ADD key <F6> and add the total field, but first we should consider how this would affect the printing of the report.

The report will have (among other columns) a column of numbers, with each row representing a record in the RMSfile. These rows would then be followed by an additional row containing a number with no indication as to its significance. The whole purpose of displaying a total, however, is to highlight a summary piece of information. Therefore, we need some way to highlight the total.

Perhaps the most common way to highlight totals is to draw a line between the column of numbers and the total. This can be done in a report by using the minus sign (-).

We must also consider the likelihood that our field total may require one or more digits than the individual totals did and format the report accordingly. (Note: In our example we will allow room for 1 additional digit.)

First press the Left Arrow key once. Next, type a minus sign ( - ) six times. Once this has been done, use the Arrow keys to reposition the cursor one line below, but in the same column as, the left-most minus sign. Now press the ADD key <F6>. This will cause a blank Field Description form to be displayed and allow you to enter the necessary information to process the desired total.

A total field differs from all others in that the Field Name field of the Field Description form is left blank. The name of the field being totaled is instead entered into the field labeled Sum of. The Field Description form in our example should be filled in as shown in the following screen:

gifs/00000001.gif

Pressing the STORE key <F5> stores the contents of this Field Description and redisplays the current Report Section screen, which should look like the following:

gifs/00000001.gif

At this point, you may once again select the PICTURE function (by pressing the GOLD key <F1> followed by the P key) to make sure things are 'lined up' as they should be. The screen should appear as shown in the following screen:

gifs/00000001.gif

Press a key (i.e., any key) to redisplay the current Report Section. Once this has been done you may press the EXIT key <F8> which writes to the file designated by the command that invoked the visual report (in this case, the pathname defined for the logical report demo~newmag) and return to the system prompt.