5
votes

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.

3

3 Answers

9
votes

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.

1
votes

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).

0
votes

From the article Adding Sub reports ,Find Sub Total and Grand Total(To main Report):

Crystal Reports is a business intelligence application used to design and generate reports from a wide range of data sources. Sub Reports are child reports of the main report which can be embedded in main report. Sub reports are very much useful in building reports.

Adding Sub reports find the sub total and grand total of each sub report in the main report

Main report

Sub Report 1

Sub Total: sum (LabTotal )

Sub Report 2

Sub Total: sum (ItemTotal)

Grand Total

Sub reports are very useful option in crystal report. Suppose we want to find

Adding Crystal report

  1. Add New Item->Crystal Report
  2. If we want to create Crystal Report our own format select “As a Blank Report” from crystal report gallery
  3. Right Click on the “Database fields” in the Database fields and select tables from the database then make Links (if necessary)
  4. Right Click from “Details Section” and Add sub report.
  5. Repeat the same things that we have done in the main report and drag needed fields to details section sub report

For Eg: We are creating labour report the total labour rate can be calculated as

In Formula field –name LabTotal

WhilePrintingRecords; Shared NumberVar LabTotal := Sum ({PC_LABOUR_DETAILS.Total})

({PC_LABOUR_DETAILS) -- table Total ---field

and add sum of LabTotal in to the sub total field

If we have another sub report to add ion the main page ,again right click on the “Details Section” and add new section ->Details(b) And repeat step 4 and 5 Here we are adding second sub report for material and subtotal of materials can be caculated as

In Formula field –name ItemTotal

WhilePrintingRecords; Shared NumberVar ItemTotal := Sum {PC_MATERIAL_DETAILS.Total})

({PC_MATERIAL_DETAILS) --table Total -- field

and add sum of ItemTotal in to the sub total field

Main report

To find the grand total of both sub reports

In Formula field name-GrandTotal

WhilePrintingRecords; Shared NumberVar ItemTotal; Shared NumberVar LabTotal; NumberVar TotalAmount; TotalAmount := ItemTotal+LabTotal; TotalAmount