Link to home
Start Free TrialLog in
Avatar of Ingrid Bowrin
Ingrid BowrinFlag for Trinidad and Tobago

asked on

Sharing values from subreport to main report in Crystal Reports

I am trying to share a variable from a subreport with a main report in Crystal 2011. In the subreport we are using the following code;
WHILEPRINTINGRECORDS;
SHARED NUMBERVAR SAVAL := Sum ({PLS_POLICYSUBAGENT.PLS_AMOUNTT}, {PLS_POLICYSUBAGENT.PLS_VERNO})
The main report uses the following code;
WHILEPRINTINGRECORDS;
SHARED NUMBERVAR SAVAL; SAVAL;
 When we put "@SAVAL" in the main report to use in another formula the results are not being displayed. When we try to display "@SAVAL" it is not lining up with the data on the Details line. (See attached screenshot).

Can someone help me resolve this please?
Doc112.docx
Avatar of Raghavendra Hullur
Raghavendra Hullur
Flag of India image

Hi,

Couple of things to check:

1. Is the field which is created in sub report is used in the report to set the value for the same? Unless it's used in the report, the value will not be set.
2. Is your sub report in a section above the section in which your main report field is looking for shared value?
Avatar of Ingrid Bowrin

ASKER

1. Yes the value from the sub report is being displayed in the main report. But we also need to use it in a formula to calculate another total in the main report.

2. The sub report is in a section above the field looking for the shared value.
1. Displaying it in main report is fine, is it being used in sub report to set the value for the same? Can you run the sub report whether the value is being set?

You need to pull the formula field into the report design area in sub report to set the value, then only the value will be available in main report.
Avatar of Mike McCracken
Mike McCracken

You have one in the details section and the other in the group footer.

Try this
Right click the detail section in the left margin
Click SECTION EXPERT
Make sure the detail section is selected
Click to check UNDERLAY FOLLOWING SECTION
Close SECTION EXPERT

mlmcc
I got the field to line up in the report, (we split the detail section into detail a & detail b and put the sub report in a and the shared varible in b) however, I want to do a sum on it in the group footer. However, when I right click on it to summarize it I'm not getting the option to summarise it.
You cannot summarize a field containing WhilePrintingRecords;

An option would be to store the value from shared variable into another variable and use that variable for summarization.
Thanks for the feedback. Can I get an example please?
ASKER CERTIFIED SOLUTION
Avatar of Raghavendra Hullur
Raghavendra Hullur
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
THe problem is summaries are done in one of the early passes through the report but the shared variables are not evaluated until the last or next to last pass through the report thus they aren't available when the summary functions are evaluated.

The easy way t do what you want is a 3 formula summary

Formula 1 declares a global variable in the group header and sets it to 0
Formula 2 in your case in the detail section B you would have a formula to add the current value to the total
Formula 3 goes in the group footer to display the total

I didn't look at the sample report but that is what it should be doing.

mlmcc
Thanks mlmcc for the answer. We have done all that but the summarized value is not resetting. However, we had to do a reset function for the formula in Detail b. Could this reset function be preventing the second reset function to work?
What is the reset function in detail B?

mlmcc
The reset formula is;

shared numbervar saval :=0;

"saval" is the shared variable from the subreport. This one works just fine.
Can you upload the report you have with the second set of formulas?

mlmcc