Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

The Visual FoxPro 9 Report Writer : Page 5

Microsoft has significantly improved the Report Writer in Visual FoxPro 9, while maintaining compatibility with previous versions of Visual FoxPro Reports, making the new Report Writer a great blend of the old and the new.


advertisement
Data Group Enhancements
A few enhancements have been made to Data Groups in the Visual FoxPro 9 Report Writer, including maximum Data Groups and horizontal columns.

Maximum Data Groups
The maximum number of Data Groups has been increased from 20 to 74. In actuality, the maximum of 74 was always true, but the user interface only allowed 20 Data Groups to be entered.

Horizontal Columns
Previously, reports with more than one column defined as horizontal with a Data Group wasted a lot of space. The first position (row 1, column 1) was left blank and data began in column 2 of row 1. Also, a blank band was wasted in between each set of Data Groups, as shown in Figure 10. Even if the height of the Data Group Header band is zero, Visual FoxPro still reserved the space, as shown in Figure 11.


Figure 10. Wasted Space: Prior versions of Visual FoxPro wasted a lot of space when using horizontal columns with Data Groups.
 
Figure 11. Reserved Space: Prior versions of Visual FoxPro reserved space for Data Group Headers, even when none were defined.
In Visual FoxPro 9, the behavior of Data Groups and horizontal columns has been changed. When a new Data Group is encountered, it is printed in column 1 of the next full row. The remainder of this row is left blank and not used for printing details. The details belonging to the Data Group begin in column 1 of the row immediately after the row the Data Group is printed in, as shown in Figure 12. Also, no extra space is reserved if the height of the Data Group Header band is zero, as shown in Figure 13.

The new behavior, although avoiding the previously described situation, may break some existing reports. However, an added benefit of the new behavior is that the Data Group band can be stretched across all the columns, as shown in Figure 14.

Multiple-Detail Bands
The new multiple-detail band feature is one of the biggest, and most often requested, improvements. It allows you to process multiple child tables for each record in a parent table. An example of this type of report is shown in Figure 15.

 
Figure 12. Less Wasted Space: Visual FoxPro 9 does not waste as much space as prior versions when horizontal columns and Data Groups are used.
Tables and Relationships
Understanding how the parent and child tables work together are key to understanding how to use this new feature. As an example of a Multiple-Detail scenario, assume you are writing the report shown in Figure 15. The database for this scenario is:

  • The Customer table is the parent table and contains one record for each insurance customer.
  • The Members table holds one record for each family member of the customer. The Members table is a child table of the Customer table.
  • The Vehicles table holds one record for each vehicle insured by the customer. The Vehicles table is a child table of the Customer table.
  • The Homes table holds one record for each home insured by the customer. The Homes table is a child table of the Customer table.
Driving the Report
One table is necessary to drive the report. In this example, the Customer table is the driving table. If you use the report's Data Environment to define the tables, set the InitialSelectedAlias property to this table. If you are using code to define the tables, make sure the Customer table is the current work area at the time the report runs.

The Target Alias
The target alias is the term used to describe which table is the driving table for a particular detail band. In this example, the Members table is the target alias for Detail 1 band, the Vehicles table is the target alias for Detail 2 band, and the Homes table is the target alias for Detail 3 band.

If no target alias is defined for a Detail band, the behavior it takes on is that of prior versions of Visual FoxPro. In other words, one detail band is processed per parent record. However, if you enter the name of the parent table as the target alias, you'll get very different results. For each record in the parent table, Visual FoxPro processes through all records in the entire parent table, printing each parent record in the Detail band. If you have a table with 10 parent records, and you set the target alias of a detail band to the parent table, the final report prints 10 sets of 10 records, or a total of 100 records.

 
Figure 13. No Reserved Space: Visual FoxPro 9 does not reserve extra space when the Data Group Header band is 0" tall.
Relationships
Relationships play a big part in how multiple-detail bands operate. Visual FoxPro uses the relationships between the parent table and the child tables to navigate through the records. You may use SET RELATION or SET SKIP to define these relationships. If you're opening the tables in the Data Environment, and relationships are already defined in the database, these relationships are honored.

If you're opening the tables in code, Listing 1 shows how to set up the tables for the Insurance Customer Listing shown in Figure 15.

Defining Multiple-Detail Bands
By default, new reports are created with one Detail band. Additional Detail bands are added through the Optional Bands dialog box. To invoke this dialog box, select "Optional Bands..." from the Report menu. This is the same dialog box that was formerly named "Title/Summary."

Click the Add button to add another Detail band to the report. You may define up to 20 Detail bands for each report.

Defining the Target Alias
The target alias is assigned to a Detail band through the Detail dialog box. This dialog box can be invoked by selecting "Edit Bands..." from the Report menu and selecting the applicable Detail band. You can also invoke this dialog box by double-clicking the gray bar of the applicable Detail band.

The Target alias is an expression and you must wrap the table name in quotes. Once you have each target alias defined, the gray bars representing the Detail bands show the target alias.

When creating Multiple-Detail band reports, it's important to prefix field names with the applicable alias name. This prevents any confusion as to which table a field comes from.

Headers and Footers
Another enhancement of the Multiple-Detail band is the ability to add Headers and Footers to each Detail band. These are similar to Group Headers and Footers in some ways, yet different in others. For each parent record that is processed, the following occurs:

 
Figure 14. Streched Data Group Bands: In Visual FoxPro 9, you can expand the Data Group Header band across multiple columns.
  • The Detail 1 Header band is processed.
  • The Detail 1 band is processed once for each child record in the associated target alias.
  • The Detail 1 Footer band is processed.
  • The Detail 2 Header band is processed.
  • The Detail 2 band is processed once for each child record in the associated target alias.
  • The Detail 2 Footer band is processed.
  • The Detail 3 Header band is processed.
  • The Detail 3 band is processed once for each child record in the associated target alias.
  • The Detail 3 Footer band is processed.
  • And so on ....
To turn on Detail Headers and Footers, place a check mark in the selection box for "Detail Header/Footer" in the Detail dialog box for each of the Detail bands. To help sort out the Detail bands from other bands, the triangle preceding the band name is solid and the other triangles are clear.

It's important to note that even if no detail records exist for a particular Detail band, the associated Detail Header and Detail Footer bands still print. If you do not want the Detail Header and Detail Footer bands under this condition, you may use the following Print when logic in each layout object defined in the bands to suppress their printing.

NOT EOF(<target alias>)

 
Figure 15. Multiple-detail Band Feature: This sample Multiple-detail band report has three separate detail bands for each customer.
Be sure to place a check mark in the selection box for "Remove line if blank" for these layout objects as well.

Similar to Group Headers and Footers, Detail Headers and Footers have some of the same options.

  • Start on a new column: Causes the Detail set to start on a new column of the report. Note that this option allows you to assign a Detail set to a specific column. If one Detail set has enough information to overflow the column, it is continued in the next column.
  • Start on a new page: Makes the Detail set start on a new page.
  • Reset page number to 1 for each detail set: With the Start on a new page option, resets the page number to 1 for each new Detail set.
  • Start detail set on new page when less than: Helps prevent orphans. The detail set begins on a new page if the indicated amount of space is not available.
  • Detail Header/Footer: Adds a Detail Header and Detail Footer band around this Detail band.
  • Reprint detail header on each page: With the Detail Header/Footer option, makes the Detail Header band reprint whenever the Detail set overflows to a new page.
Report Variables and Calculations
With the introduction of Multiple-Detail bands, report variables and calculations have some new twists to them. You need to fully understand how they are processed in order to use them effectively. Otherwise, you may not get the results you're expecting.

The "Reset at" prompt on the Report Variables dialog box has been renamed "Reset based on." This more clearly defines that the variable is reset based on the change in value of the selected option. In addition to renaming the control, if more than one Detail band is defined in the report, each Detail band is added to the drop-down list.

Selecting Detail n as the "Reset based on" value tells Visual FoxPro to only process this calculation when processing the detail records in the target alias of this Detail band. The report variable is not altered while records in other target aliases are being processed. This allows you to tie a report variable to one particular Detail band. The value of the report variable is not cleared until the Detail Header band of this same Detail set is processed for the next parent record.

If you chose a "Reset based on" value other than one of the Detail bands, the calculation is processed in several places. First, for each parent record, the calculation is applied. Next, the calculation is applied for each record in the target alias of the first Detail band. Then the calculation is applied for each record in the target alias of the second Detail band, and so on.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date