Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Shared Variable Problem Post Reply Post New Topic
Page  of 2 Next >>
Author Message
sfullergs
Newbie
Newbie


Joined: 06 Nov 2019
Online Status: Offline
Posts: 13
Quote sfullergs Replybullet Topic: Shared Variable Problem
    Posted: 26 Nov 2019 at 2:39am
I have a subreport that is on a primary report. Everything on the subreport works fine and displays on the main report fine. I have two summary fields on the subreport that I need to pass to the main report, but cannot get the shared variable to work. The two summary fields I need to pass are sum of @actualcfs and count of tbnatur.desc. The subreport is in the group header on the main report.

I have this formula in the subreport on the report footer and it comes up with the proper number if I display it on the subreport:
WhilePrintingRecords;
Shared NumberVar CountCFS := Sum ({@ActualCFS});

I have this formula on the main report in the report footer:
WhilePrintingRecords;
Shared NumberVar CountCFS;
CountCFS

The problem is, on the main report, the only number that will display with this formula is the last number on the subreport. I don't really need this to do any math on the main report, as all of the math is done on the subreport and is correct. I just need it to pass the result of the summary fields from sub to main report.

Here is a screenshot: https://www.dropbox.com/s/jepnvf47caseerm/crystalPNG.PNG?dl=0

Edited by sfullergs - 26 Nov 2019 at 2:42am
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 26 Nov 2019 at 4:49am
not entirely sure what your set up is...
here are a few things to try/think about
1. place the Count CFS result in the sub report to make sure it is giving you the total expected in the SR but displayed in the MR (not passed though).
2. the sub report cannot be be suppressed
3. The main report variable should be in a section below the SR execution (e.g. SR in reportfooter a and Main Report variable in reportfooter b)
4. Make sure you are not using that same variable in the MR for anything else.


Edited by DBlank - 26 Nov 2019 at 4:50am
IP IP Logged
sfullergs
Newbie
Newbie


Joined: 06 Nov 2019
Online Status: Offline
Posts: 13
Quote sfullergs Replybullet Posted: 26 Nov 2019 at 5:34am
Originally posted by DBlank

not entirely sure what your set up is...
here are a few things to try/think about
1. place the Count CFS result in the sub report to make sure it is giving you the total expected in the SR but displayed in the MR (not passed though).
2. the sub report cannot be be suppressed
3. The main report variable should be in a section below the SR execution (e.g. SR in reportfooter a and Main Report variable in reportfooter b)
4. Make sure you are not using that same variable in the MR for anything else.

1. The CountCFS result is in the subreport, and it does give the correct number.

2. The subreport is not suppressed.

3. On the main report, the subreport is in the group header and the variable is in the report footer.

4. The variable is not used anywhere else.

It seems like the variable is working per se, because I am getting at least one value from the subreport. Basically, both reports are grouped by the field tbnatur.desc. The value that gets passed is the value for the last entry, as you can see in the screen shot. Like I said, all the math is good on the subreport and it all works. For some reason it just isn't passing the value of the formula @ActualCFS on the subreport to the main report, it is just passing the value for the last entry on the subreport.

Edited by sfullergs - 26 Nov 2019 at 5:38am
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 26 Nov 2019 at 6:10am
The last entry or the last group sum?
If it is the last groups sum that is the 'correct' value for it to display based on where you have these items placed in the MR.
Because the SR is in a group header it will run one instance of the report for each group. It is not returning any value from one group to the next or back to the main report for it to summarize across groups but rather it is displaying the final group result in the report footer.
IP IP Logged
sfullergs
Newbie
Newbie


Joined: 06 Nov 2019
Online Status: Offline
Posts: 13
Quote sfullergs Replybullet Posted: 26 Nov 2019 at 7:13am
Originally posted by DBlank

The last entry or the last group sum?
If it is the last groups sum that is the 'correct' value for it to display based on where you have these items placed in the MR.
Because the SR is in a group header it will run one instance of the report for each group. It is not returning any value from one group to the next or back to the main report for it to summarize across groups but rather it is displaying the final group result in the report footer.

This sounds like an accurate assessment of what is happening. Any suggestions? I've been kicking this around for 2 days with no luck.
IP IP Logged
sfullergs
Newbie
Newbie


Joined: 06 Nov 2019
Online Status: Offline
Posts: 13
Quote sfullergs Replybullet Posted: 26 Nov 2019 at 8:01am
OK, so, it looks like I got these to work a little better by tweaking the formulas.

Subreport formula:
Shared NumberVar CountCFS;
CountCFS := CountCFS + Sum({@ActualCFS});
CountCFS;

Main report formula:
Shared NumberVar CountCFS;

The odd thing now is, this, and another shared variable that I'm passing are each short of what they should be by exactly 554. Oddly enough, they display correctly on the subreport.

Edited by sfullergs - 26 Nov 2019 at 8:07am
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 26 Nov 2019 at 10:07am
I think you will want to do what you had but in each GH1 set the variable to 0 then in GF2 place the variable returning result from the SR in GF2. Create another set of variable formula's inside the MR to add each returned instance. Place a set to 0 in the RH then an addition of each the field + the SR returned variable GF3.
IP IP Logged
sfullergs
Newbie
Newbie


Joined: 06 Nov 2019
Online Status: Offline
Posts: 13
Quote sfullergs Replybullet Posted: 26 Nov 2019 at 10:55am
Here are the two parts of what you said that I'm not sure on how to write it. I did the other things you mentioned and I see what it is getting at but I'm just not sure on the code for these.

Originally posted by DBlank

Create another set of variable formula's inside the MR to add each returned instance.


Originally posted by DBlank

then an addition of each the field + the SR returned variable GF3.


Edited by sfullergs - 26 Nov 2019 at 10:56am
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 27 Nov 2019 at 6:30am
Been a while since i did this but I think you will need to create the 3 formula's using a variable in the main report.This can reference the other variable passing thegroup sum back to the MR. This is used to then sum each of those instances. In the summing formula (second formula, reference the shared variable value you returned for each group. It should be placed in a GF section below where you passed the SR value back into the MR.

Whileprintingrecords; // place this formula in Report header
Numbervar ReportSum:=0;


Whileprintingrecords; // place this formula in Group footer 3
Numbervar ReportSum:=ReportSum+ {@CountCFS};


Whileprintingrecords; // place this formula in Report footer to get the total sum
Numbervar ReportSum;
IP IP Logged
sfullergs
Newbie
Newbie


Joined: 06 Nov 2019
Online Status: Offline
Posts: 13
Quote sfullergs Replybullet Posted: 29 Nov 2019 at 8:25am
So, the numbers that were displaying were actually correct. So it was right to begin with. The real problem seems to be this:

Basically, this report compares calls for service for one year (main report) compared to another year (sub report) and the tbnatur.desc field shows that the call nature is. The problem is that sometimes, for example, a call nature may not have been used in 2019 (main report) but was used in 2018 (sub report) but since that row does not exist on the main report, that result from the subreport will not show up on the main report. However, if that row exists on the main report but not on the subreport, the row will display and the value for the subreport will just be blank. That part is fine. Basically, I want to blend the subreport into the main report. If that row does not exist on the main report but does on the subreport, I want the result from the subreport to be on the main report.

The reason for the difference in the numbers was because of this issue. The subreport (year 2018) had some natures (tbnatur.desc) on it that had been used in 2018 but had not been used in 2019 (main report). Since there was no listing for the call nature in the main report, the numbers/listing would not come over from the subreport. I need to figure out how to get those fields that exist in the subreport but not in the main report to show up in the main report. Any suggestion?
IP IP Logged
Page  of 2 Next >>
Post Reply Post New Topic
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



This page was generated in 0.016 seconds.