Grouping

<< Click to Display Table of Contents >>

Navigation:  Index >

Grouping

Previous pageReturn to chapter overviewNext page

When you sort information, the resultant data sometimes contains groups of similar data.  An example of this is when you sort a sales table on the salesman name.  After the sort, records are grouped by salesman and there are typically multiple sales orders for each salesman.  ReportPro allows you to identify the grouped data and print information before and after each of the groups.  

 

Specifically, groups allow you to:

 

       Print header and footer bands to identify the details about each group
       Print each group on a new page
       Perform calculations on each of the groups

 

When you create a grouping in ReportPro, you identify the expression that reflects how the data is grouped.  In our salesman example, the grouping expression would be the salesman field since it defines how the data is grouped.  ReportPro uses this expression to trigger the printing of the Group Header and Group Footer bands that are created with you define a grouping.  

 

To specify a grouping, select the Group menu option from ReportPro's main menu.  The Grouping dialog that is displayed is very similar to the Sort Order dialog.

_bm72

 

To specify a grouping simply highlight the field you wish to group on in the Available Fields list box and click the left arrow button.  The field will be added into the Groups list box.  When a second field is added to the Groups list box, it defines a sub-grouping of the first grouping.

 

ReportPro allows you to create groups based on more complex expressions than just field names.  For example, you may wish to create a grouping on the first few characters of a field rather than the entire field.  To define a grouping, click the Define button at the bottom of the Grouping dialog.

_bm73

 

The Define Group dialog allows you to manually create a new grouping.  The Group Name edit is required and must be a unique group name.  The Expression edit is where you enter the expression you wish to use for the grouping.  If you want to work in the Expression Builder, press the Exp button to the right of the Expression edit.  Once you define the grouping, you are returned to the Grouping dialog.

 

The ability to group on expressions has a few not so obvious benefits.  Not only is it an extremely powerful feature, but it also lets you create multiple Group Header and Group Footer bands that trigger on the same expression.  This is extremely useful when printing multiple variable length fields on a report.  Also, if you correctly define a variable and use it as your grouping expression, you can simulate multiple Body bands.

 

When you close the Grouping dialog, ReportPro will automatically create the required Group Header and Group Footer bands in the report work window.  The Group Header band prints before each group and the Group Footer band prints after each group.

 

Grouping: How it works

 

For the sake of discussion, assume that we are creating a Sales listing report and we wish to list all the Sales for each salesman in Closed Date order.  Let's assume that our Sales table looks like:

 

Salesman

 Closed Date

LLA

 /10/96

GAK

 /15/96

GAK

 /15/96

LLA

 /15/96

LLA

 /17/96

 

First we specify a that the sort order for the report is Salesman first and Closed Date second.  Next we specify that the grouping is on Salesman.

 

When the report is printed the following events will occur:

 

       The table is sorted based on the information specified in the Sort Order dialog.

Salesman

 Closed Date

GAK

 /10/96

GAK

 /15/96

LLA

 /10/96

LLA

 /15/96

LLA

 /17/96

 

       A group will start and remain in effect until Salesman is no longer equal to "GAK".
       The Group Header band will print.
       The Body band will print for each record for which Salesman equals "GAK" resulting in Dates "12/10/93" and "12/15/93" being printed.
       When the Salesman no longer equals "GAK" the Group Footer band is printed.
       Another group will start and remain in-effect until Salesman is no longer equal to "LLA".
       The Group Header band will print.
       The Body band will print for each record for which Salesman equals "LLA" resulting in Dates "12/10/93", "12/15/93" and "12/17/93" being printed.
       When the Salesman no longer equals "LLA" the Group Footer band is printed.
       Since there are no more records in the database the report terminates.