Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Might be a noobish question, but what do you use a subreport for? 1

Status
Not open for further replies.

aaronburro

Programmer
Jan 2, 2003
158
US
What is the advantage of using subreports without the "on demand" factor included? Can someone show me an example that a subreport actually makes the report "easier" or more efficient? The reason I ask is that I assume there must be some reason for subreports to exist, but I can't seem to figure it out, and as I learn more and more about CR, I will begin to see how I can use a subreport, but only if I know what scenario to expect to use one in.
 
There is no advantage of using subreports, and in fact I avoid them if at all possible. Performance can be very bad with subreports. However there are times when a subreport is the the only way a report can be written.

A common example with Macola, the ERP package I support, is when you need to link on a substring of a database field rather than the entire field. It is easy to write a formula to extract the substring, but you cannot link to another table based on a formula.

Therefore you write a subreport, and link on the formula, which is allowed in subreport linking. Again given the database structure, its the only way to get the report needed.

Software Sales, Training, Implementation and Support for Macola, eSynergy, and Crystal Reports
 
The only instance where I intentionally employ subreports are for disparate datasets that need to be displayed in one report.

In those examples the subreports are located in the report headers or repoart footers.

An example would be a Corporate dashboard report.

The first part of the report might be the finances, wherein the sql would be pulling from a finance database. The next page of the report might be pulling order and shipping information from another database, and the next part might be related to HR concerns.

Creating the Ordering and HR as separate subreports allows for the same amount of database work as having 3 reports, the difference being that it's all presented in one report.

dgillz gives an excellent example of how he leverages subreports because they are unable to create a database object such as a view to build out the proper data for creating a join.

In general if you're able to create database objectws, you'll avoid subreports by creating the dataset on the database, but there are instances when you cannot, hence the subreport.

Keep in mind that if a subreport is in a group section, that subreport will run as many times as there are groups, hence the poor performance.

-k
 
...or if the tables are not indexed!!!

I've HAD to do it more than once in my last contract. We were using an application that used paradox and most of the tables didn't have indices and so couldn't be linked, a nightmare!!!!

Patrick
 
A crystal report is built around a set of 'rows', detail lines. If you want two different sequences in the same docutment, or maybe totalling by two different sets of criteria, you can get this using a subreport in the report header or footer.

Crystal also shows its limits when you try to get a lot of different 'tables' into a single 'row'. In Crystal 8.5, at least, a subreport was the easiest way to get something working.

It is also a way to show history records for an account, when you still want to see the account as a detail record when it has no history. You could do this rather better using SQL, but only if you have SQL and know how to use it.

Subreports make a lot of work for computers, but save time for humans. You decide which is more important for your particular circumstances.

Where I work, we go to a lot of trouble to make our mainframe screens and reports run efficiently. We use Crystal mostly for investigations and management information, cases where it doesn't much matter if a job takes twice as long because the user can be doing something else in the meantime. For a big Crystal report that is run frequently, it would be worth going to some trouble to make it efficient. In other cases it makes sense to save programmer-time.

[yinyang] Madawc Williams (East Anglia, UK) [yinyang]
 
Is worth mentioning that in some cases a Cross Tab can sometime be used instead of subreports but you do have to consider the limitations

Mo
 
Subreports have all sorts of advantages if you use them correctly. But DGillz is correct in that if you don't need them, then don't use them.

Use them when you can't join the tables in a main report, because they are either not in the same DB or the join to both are many-many.

Example of the later is a report including a customer table and two transaction tables (orders and credits). If you join these with SQL, and a customer has 3 credits and 8 orders, you get 24 detail lines. Do the Customer-Orders in the main report and the credits in the subreport and the 11 records will process correct.

Of course you don't get any customers who have credits and no orders. In that situation, use Orders and Credits both in subreports.

The SQL guys will suggest joining those tables with a UNION join, but some of the older DB's don't let you do this.

Another example of Subreports is a KPI report. A one page summary with unlinked subreports is a great solution here.

As for perfomance, I've made things go faster with subreports being used for the design.

Editor and Publisher of Crystal Clear
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top