| Author |
Message |
kemigirl
Newbie
Joined: 05 May 2009
Online Status: Offline
Posts: 14
|

Topic: Shared Variables - not calculating properly Posted: 13 Jul 2009 at 1:28pm |
Hi! I am new to subreports and could use some help. I've read several threads here about subreports but have struggled to figure out how to apply the concepts to my particular report. I have a main report with 2 subreports. All of them are grouped by the same type of date group (basically by month). My 1st subreport contains information that overlaps date groups with the 2nd subreport and with the main report. I want to add the values from the 1st sub into the 2nd sub and into the main report, by group. I set up the totals from the 1st subreport as shared variables and I can see them in the other subreport and in the main report, as long as I put this particular first subreport in the RH of the main report. However, the numbers from this subreport get added in to every single group on the main report and the 2nd subreport, rather than just the corresponding group. It's like it doesn't recognize that I only want a group total to come in, rather than the subreport total. Main ReportRH (contains 1st subreport with shared variables) april 2009 10 may 2009 25 Group 1 february 2009 87 march 2009 76 april 2009 54 RF (contains 2nd subreport) may 2009 35 In this case, I want the april total to get added into the main report in group one with the other april total. I want the May total to get added in only to the 2nd subreport. I know I'm missing something very basic. Grrrrr.  Any thoughts?
|
IP Logged |
|
|
|
DBlank
Moderator
Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
|

Posted: 13 Jul 2009 at 7:42pm |
You would need to create/set shared variables per month-year and pass those back and forth and add them up.
|
IP Logged |
|
lockwelle
Moderator
Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
|

Posted: 14 Jul 2009 at 6:32am |
Since you are getting 2 values at once, the shared variable is being updated twice. As hilfy's tag line says, the computer does what it is told, not what you thought you told it.
DBlank's solution is what you are going to need. If it is only month, you would need 12 variables so that you can place the correct value in the correct section. Or you could try a shared array ( I haven't used a shared array yet, but I think that is what I would try).
Just remember, Crystal is very simple. It starts at the top of your data and reads down. If it sees a subreport, it will go off and read that from the top to the bottom and then return to the main report and continue reading. So if you need a value 'earlier' than its position, use a subreport. If the value is summary, you can place it later in the report. If it is later in teh report, and it is not a running total (as you don't want) remember to reset any shared variables.
HTH
|
IP Logged |
|
kemigirl
Newbie
Joined: 05 May 2009
Online Status: Offline
Posts: 14
|

Posted: 15 Jul 2009 at 6:33am |
|
Thank you both for responding so quickly.
I guess I'm going to become best friends with this subreport. I'm having trouble wrapping my arms around the concepts you recommended, especially with a drill-down factor...how I get the items in the subreport to show up in the appropriate group on the main report and also on the 2nd subreport.
Do either of you have any suggestions for a resource I can use to help me work through subreports? This is my first one, and from what I hear, there are many more coming my way... (d'oh)
|
IP Logged |
|
lockwelle
Moderator
Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
|

Posted: 15 Jul 2009 at 6:57am |
The best resource that I have found for Crystal, something that I can actually use and isn't the Help file repeated or a simple guide, is Brian's book. Much I already knew, but whenever I am confused or looking for something, I can usually find it there...or here in a post ;)
Looking at the sample, if the RF is just a reiteration of the RH, then just use the shared variable that is created in RH (you've already done the counting, just display it).
|
IP Logged |
|
DBlank
Moderator
Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
|

Posted: 15 Jul 2009 at 7:18am |
I also second a recomendation for Brian's book.
Based on your description of Drilling Down you may want to consider a different approach and move your sub reports on GHs and GFs instead of the Report Headr and Footer. You can link the reports on the Month Value. This would also allow you to pass the variable per month without creating 12 of them.
This of course changes the look of you report and breaks your sub reports into month groupings. You also need to make sure the data in the main report has a group per month that each sub report needs or the sub reports would skip that month too and be omitted from the report entirely.
|
IP Logged |
|
kemigirl
Newbie
Joined: 05 May 2009
Online Status: Offline
Posts: 14
|

Posted: 15 Jul 2009 at 12:42pm |
Ok (you guys are genius btw)...I think I have this almost working. I have the main report properly showing drilldown now for subreport #1. This was done by way of putting subreport #1 in the GF, as it
is linked to the main report. I also have the shared variables coming through into my
formulas by setting separate variables for the different months and placing that subreport in the RH.  The last piece I'm trying to do is to figure out the drilldown in subreport #2. I have subreport #2 sitting in the report footer and when you drill down I want it to show employee records from that subreport #2 along with employee records from subreport #1. Subreport 2 is in the RF because it's not linked to the main report. It is also grouped by the same date type as the rest of the report. If I could have my way, I suppose I would be inserting a subreport into
another subreport, but I know that's not possible. I am looking for a
way to link subreport 1 and subreport 2 to each other without touching
the main report, since #2 isn't linked to the main report in the first place. I feel like I'm talking in circles now and I'm not sure how to explain this any better. Is what I'm trying to do even possible? Thanks again for all your help...this has been VERY educational.
Edited by kemigirl - 15 Jul 2009 at 12:53pm
|
IP Logged |
|
DBlank
Moderator
Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
|

Posted: 15 Jul 2009 at 2:21pm |
Hey Kemigirl,
I am having a difficult time visualizing the set up you are describing so I am not sure I will ne able to answer your question.
You are correct that you cannot add a subreport to a subreport.
The drill down is also a bit tricky. In the main report you can conditionally suppress using drilldowngrouplevel function but "drilling down" onto a sub report has no impact on that number in the main report so you cannot conditionally suppress a section in the subreport using that value from the main report (at least I have not figured it out yet).
Perhaps if you posted a visual of what you currently have and what you want it would help to come up with a solution.
Or maybe Lockwelle has an idea from your last post...
|
IP Logged |
|
kemigirl
Newbie
Joined: 05 May 2009
Online Status: Offline
Posts: 14
|

Posted: 15 Jul 2009 at 4:34pm |
|
Oh boy...here goes.
Report Header contains Subreport #1 with saved variables - info from here is supposed to feed into main groups below and into sub#2 for drilldown. Main Report Groups (grouped by month) January 2009 - showing formulas and can drilldown to info from main report and sub#1 February 2009 - same March 2009 - same April 2009 - same May 2009 - same Report Footer contains subreport #2 June 2009 - shows drilldown for sub#2 and is supposed to show those for #1 also July 2009 - same
The drilldown on any of these groups should show you a set of employee records by date. I have information in sub#1 that needs to show up in the drilldown in sub#2. Sub#2 does not currently have a link to the main report because the main report doesn't have June and July, so I will lose those records since those groups don't exist.
If an actual screenshot would help, just let me know. I can fudge data so I can at least display what I'm doing.
Thanks again for your time!
**Edit: possible solution? I got the brilliant idea last night of trying to create a shared stringvar in sub#1 for each field in the record (i.e. employee number, employee name, etc.). I then called it in the group footer of subreport #2 and I was able to see it upon drilldown. However it only brings one record over and doesn't bring the remaining records (currently there are 6 remaining records). Is there any way to make a shared variable display multiple records rather than just one? This attempt was just a stab in the dark.
Edited by kemigirl - 16 Jul 2009 at 6:10am
|
IP Logged |
|
lockwelle
Moderator
Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
|

Posted: 16 Jul 2009 at 6:14am |
Most of my reports are straight financials, and no one drills down, and I try to avoid subreports...just a preference as sometimes they are necessary.
Unfortunately, Crystal is pretty simple. If you want data in a report, you need to put it there. So if data from subreport 1 is needed in subreport 2, you would need to somehow include it in the data that subreport 2 uses and display it. Crystal will use shared variables (obviously) but to display other info...you need to select it, which might mess up subreport 2.
there are times that being able to put subreports inside of subreport would be really useful, but I can see it becoming a maintenance nightmare, not to mention the coding behind it. People complain of how slow Crystal runs, imagine even more subreports....
Maybe DBlank has some ideas...
|
IP Logged |
|
|
|