7.7 Sorting Records in Reports

Until now we have not changed the order of the records being printed. The records are printed in the same order in which they are stored in the RMSfile. Very often this is unsatisfactory as most reports require some kind of ordering of the data. By utilizing the Sorted By fields of the Report Description form, the records in the RMSfile can be sorted on up to three fields.

Sorting arranges the records in ascending order by comparing sort fields. Each sorted record has sort fields greater than or equal to the sort fields of the previous record and less than or equal to the sort fields of the next record. Sort fields indicate which fields of the record will be used to determine the record order. Thus, you can sort subscribers by their name, zip code or by any field in the subscribers file. Our next example illustrates this sorting capability.

The example in this section uses the reportfile which we produced in the preceding section. To begin, enter:

c:\> rptedit demo~newmag


c:\> wtrdef demo~newmag

Once the Report Description form is displayed, press the UPDATE key <F4>. As is indicated in the lower left-hand corner of the screen, you are now in UPDATE mode. This allows you to make the following changes to the form's contents:


Typing the field name magazine in the left-most Sorted By field will cause the records in the RMSfile mag to be sorted based on the value of that field prior to being 'reported'. After using the STORE key <F5> to record this change, press the SWITCH key <F7>. The screen should appear as in the following screen:


From now on, when this report is run, the records will be printed in ascending order, based on the value of the magazine field. You should also be aware of the fact that when 'cycling through' the various Report Section screens, Level 1 Heading and Level 1 Footing sections will appear, since a single sort field has now been defined. (Note: This example is continued in the following section of this chapter.)