Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Multiple Subreports with Multiple Shared Variables Post Reply Post New Topic
Author Message
thegreatmonk
Newbie
Newbie
Avatar

Joined: 06 Oct 2009
Location: United States
Online Status: Offline
Posts: 4
Quote thegreatmonk Replybullet Topic: Multiple Subreports with Multiple Shared Variables
     Posted: 06 Oct 2009 at 7:32am
I am working with a Main report that consists of 30+ Subreports, all of which are exactly the same except for the Program which they are under.  Each subreport has 10 Sums that need to be shared with the Main report so that it will show different groups of Grand Totals for each of the sums.
 
My question: Is there a way around having to create 300+ different formulas with shared variables in the main report to refrence each of the variables in the subreport just to get a sum?
 
Is there no way to refrence subreport1.sumOfColumn1 + subreport2.sumOfColumn1 + ... + subreportX.sumOfColumn1  ? 
 
 
 
 
 
 
 
 
 
 
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 06 Oct 2009 at 9:25am
You can reference all the subreport variables from the main report by declaring them in a single formula:

Global NumberVar SR1_C1, SR1_C2, SR2_C1, SR2_C2;
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
thegreatmonk
Newbie
Newbie
Avatar

Joined: 06 Oct 2009
Location: United States
Online Status: Offline
Posts: 4
Quote thegreatmonk Replybullet Posted: 06 Oct 2009 at 1:59pm
Its working great for the first column sum, but none of the other columns are summing correctly.
 
i used :
whileprintingrecords;
shared numbervar sr1_c1;
shared numbervar sr2_c1;
shared numbervar sr3_c1;
sr1_c1 + sr2_c1 + sr3_c1 + ...
 
following the exact same format, i created 9 more formulas to refrence the rest of the colums' variables
 
whileprintingrecords;
shared numbervar sr1_c2;
shared numbervar sr2_c2;
shared numbervar sr3_c2;
sr1_c2 + sr2_c2 + sr3_c2 + ...
 
but for some reason every other column shows 0.
 
i've more than triple checked the variable declarations in each subreports formulas, and that they showed the correct number but still no luck.
 
 


Edited by thegreatmonk - 06 Oct 2009 at 2:00pm
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 06 Oct 2009 at 2:03pm
are the subreports being run in their own section and BEFORE the section that the main report does the calculation? If they aren't in their own section, then you can't guarantee the order that they are calculated internally and can return zeros without you realizing it.
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
thegreatmonk
Newbie
Newbie
Avatar

Joined: 06 Oct 2009
Location: United States
Online Status: Offline
Posts: 4
Quote thegreatmonk Replybullet Posted: 07 Oct 2009 at 12:13pm
Well I  figured out why it wasn't working.  The shared variables weren't handling null values correctly for some of the columns so since the second column was actually null, nothing that was calculated after that worked. 
 
Every variable now has something like:
shared numbervar r1_c1:= (
If ISNULL(Sum (@r1_c1)) THEN 0
    ELSE Sum (@r1_c1)));
 
and it seems to be working fine now.
Thanks for all your help!
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum