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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SubReports and passing data back to Main Report 2

Status
Not open for further replies.

wakthar

Programmer
Jul 27, 2007
14
GB
I have a report which contains 3 subreports which are the same subreport.
My main report contains 3 subreport objects which refer to the same subreport.

For example I have

Reg Con A B C D A B C D A B C D
1 2 1 1 1 1 2 2 2 2 3 3 3 3
4 5 4 4 4 4 5 5 5 5 6 6 6 6
7 8 3 3 3 3 2 2 2 2 1 1 1 1
Total 8 8 8 8 9 9 9 9 10 10 10 10

Please ignore the values as I've just used simple numbers to illustrate the problem.

My subreport contains the following

A B C D


What I've done is in the GF2 section, added 3 of my above subreports next to each other but I need to pass back the totals from each of the subreports!

Firstly am I doing it right or is there a better way?
Secondly, if I am doing it correctly, how do I pass back grnd totals for each of A,B,C and D in the separate subreports???

Thanks in advance.


 
Your example is too abstract. Try using actual {table.field} names. It is unclear what A,B,C, and D are (are they multiple instances of the same field? Different fields?) or what kind of summaries you want. Also explain what groups you have in the main report, and how the subs are linked to the main report (on what fields).

If you are using the same sub, in the same report section, why would the result be different per sub? You can pass the results back by setting the summaries up as shared variables:

whileprintingrecords;
shared numbervar A := sum({table.A});

Then in the main report you can reference it by using a formula like the following:

whileprintingrecords;
shared numbervar A; //just the first two lines to show the results or
A * 5 (if you want to do a calculation with A,e.g.)

-LB

 
It is a little vague.
Main report consists of the following columns

Region ContractNo Revenue Income Revenue Income Revenue Income

where the first Revenue and Income columns are for the required month, the second and third Revenue Income columms are for the previous months.
The report needs to be grouped by region and contractno.

I have added a subreport which will show the Revenue and Income columns.

I have inserted this subreport for the other 4 Revenue Income columns so in the designer we have

region cont_num subreport1 subreport1.rpt subreport1.rpt-01

I have linked the subreport with the input parameters of period, year, region and contractno.

In each subreport I have declared shared variables to hold the sum of Revenue and sum of Income totals.
In each subreport I have grouped by region and contractno, and have added the summary of Revenue and Income.

An example of the formula for shared variable s_Income1 for subreport1 is as follows

WhilePrintingRecords;
Shared numbervar s_Income1:= Sum({Contract.c_Income}, {Contract.region})

For subreport1.rpt I ahve done similiar but renamed shared variable to s_Income2 and so forth.

The actual summary variables appear in the GF1 section.

** Do I need to add the formula fields into any section? **

In the main report I have created formula fields such as Income_1 as follows:

WhilePrintingRecords;
Shared numberVar s_Income1;
s_Income1

I have also done the same for all the shared variables across the 3 subreports.

In the main report RF section I need the totals for all these shared variables. At the moment they are showing 0.

This is an example of what it should look like


Reg ContNo Revenue Income Revenue Income Revenue Income
2 24 20.00 10.00 30.00 20.00 10.00 5.00
2 16 5.00 3.00 9.00 13.00 4.00 16.00

Total 25.00 13.00 39.00 33.00 14.00 21.00


Thanks for your help so far!
 
Yes, the shared variable formulas need to be placed on the subreport canvas. Because the subs are linked by the group fields, the formula could leave out the group condition and be placed in the subreport report footer.

Since you are referencing the variables in the group footer of the main report, the values should appear once you place the shared variable formulas on the subreport. If they don't, then it is likely that you have either suppressed the subreport or suppressed the section the subreport is in, which you cannot do with shared variables. You can however, suppress all sections within the subreports, format the subreport to "suppress blank subreport", and format the section in which the subs are located to "suppress blank section".

-LB
 
Thanks.

I still have a problem though. When I run the report the total section just displays the last values from the Income and Revenue columns.

I forgot to add that the subreport has the following layout:

GF2 Sum({Contract.c_Revenue}) Sum({Contract.c_Income})
RFa sharedRevenue sharedIncome

All the sections of my subreport ae hidden apart from GF2.

In my main report the GF2 section contains the subreports.
I have added the formulas containing the shared variables in the RF section.

Any ideas??
 
I didn't understand that you were trying to summarize the subreport results. In the main report, in GF2b (insert a section below the one in which your subs are located), add a formula like this (using the same shared variable names:

whileprintingrecords;
shared nunbervar s_Income1;
shared numbervar Revenue1;
numbervar suminc := suminc + s_Income1;
numbervar sumrev := sumrev + Revenue1;
//add all variables you want to summarize to this same formula which can be suppressed

Then in the report footer, in separate formulas, reference each result, as in:

whileprintingrecords;
numbervar suminc;

If any of your subs can have null results, you need to also have resets for your shared variables.

-LB
 
Brilliant!!

It all works fantastically except like you say when I have nulls for some of my shared variables.

How did I have resets for any shared variables which may be null?
 
I've found the answer.

Once again thanks guys!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top