I have a formula @InitVars in the page header which includes the following, and similar lines:
shared numbervar runWaste:=0;
In Details v,
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