I have a formula @InitVars in the page header which includes the following, and similar lines:
shared numbervar runWaste:=0;
In Details v,
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.
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).
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
- Add New Item->Crystal Report
- If we want to create Crystal Report our own format select “As a Blank Report” from crystal report gallery
- Right Click on the “Database fields” in the Database fields and select tables from the database then make Links (if necessary)
- Right Click from “Details Section” and Add sub report.
- 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