Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crystal reports, sub-reports, and shared variables

I have a formula @InitVars in the page header which includes the following, and similar lines:

shared numbervar runWaste:=0;

In Details v, I have a sub-report, which has a formula @SetRunWaste:

shared numbervar runWaste;
if (OnFirstRecord) then
(
if not(isnull({x.x-or})) and 
not(isnull({x.y-override})) and {x.y-override} = true then
runWaste:={x.x-or} 
  else
runWaste:= {x.x}
);
runWaste

I can see the output of this formula in the sub-report is 18.00.

However, both in another sub-report, in Details az, and in the main report in Details w (as a test), I have the following formula @test:

shared numbervar runWaste;
runWaste;

In both places, it shows as 0.00.

Why is it showing 0 not 18?

I'm using Crystal Reports version 11.0.0.895.

like image 390
LeBleu Avatar asked Jun 05 '09 22:06

LeBleu


2 Answers

The problem is that @InitVars is in the page header, not the report header. It is resetting the variable to 0 at the top of every page.

Moving @InitVars to the report header fixed it so the correct number comes up in the sub-report in Details az.

I still see some odd behavior when I include the variable in the main report, but since that was just for debugging, not the main target, I don't care.

like image 58
LeBleu Avatar answered Oct 08 '22 11:10

LeBleu


I have a vague memory that I'm now having a hard time substantiating about shared variables not passing back up from a subreport. Still looking; good thing it's Friday afternoon.

Edit: I can't find what I was looking for, so a general thought. Check evaluation time, and make sure that the later section on the main report is evaluating after the subreport (WhilePrintingRecords might be your friend here).

like image 38
Adrien Avatar answered Oct 08 '22 12:10

Adrien