Using the Object Model to Build Batch Reporting Applications


So far this chapter has focused on on-demand reporting, meaning that reports are processed as they are requested and they generally go away when the viewing or printing is completed. One of the biggest uses of the Report Designer Component today is for batch reporting; that is, running a large number of reports at once. This section covers some features and best practices relevant to batch reporting.

Working with Reports with Saved Data

When using the standalone report designer, you might have noticed an option on the File menu called Save Data with Report. This enables a report to be saved with the last returned dataset so that it can be viewed again without connecting to the database. Reports with saved data are in effect an offline report.

Applications using the Report Designer Component can both create and view reports with saved data. This enables you to run a batch of reports and then be able to view them at any point later. This can be useful for reports based on queries that take a long time to run, or also for achieving an archiving process for reports.

Creating a report with saved data is very simple. You just export to the Crystal Reports format by using the crEFTCrystalReport identifier. All exported reports have saved data. You can control where this report is saved and archive it for later.

Viewing a report with saved data doesn't actually require any code at all. The logic of the report engine is: If the report has saved data, use it and only hit the database again if the user clicks the Refresh button or the developer forces a refresh by calling the DiscardSavedData method off the Report object. You can always tell which copy of the data is being used from examining the DataDate property of the Report object.

Hopefully you can imagine how applying this principle to batch reporting would be powerful. A set of reports could be run overnight, producing another set of reports with saved data that can be viewed offline.

Looping Through Reports

Another scenario that is relevant to batch reporting is looping through a set of reports. A common example is running either one report many times with different parameters (such as a bank statement) or running a large collection of reports all at once (such as financial statements).

These scenarios can be accomplished by using external report files and writing a loop that opens a report, prints or exports it, and then closes it. The best way to close a report is to set the Report object to Nothing:

Set Report = Nothing


This releases the COM object and releases the report job from memory.

Also, the CRAXDRT library is thread safe, which means that multiple threads can be calling into it at the same time. If a large number of reports need to be processing in a very small amount of time, you can spawn as many as five simultaneous threads that are all running reports at the same time.




Crystal Reports XI(c) Official Guide
Crystal Reports XI Official Guide
ISBN: 0672329174
EAN: 2147483647
Year: N/A
Pages: 365

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net