Crystal reports, sub-reports, and shared variables

2019-02-22 17:25发布

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条回答
祖国的老花朵
2楼-- · 2019-02-22 18:05

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

查看更多
▲ chillily
3楼-- · 2019-02-22 18:14

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.

查看更多
贼婆χ
4楼-- · 2019-02-22 18:16

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

  • @kristina: Please don't just copy and paste content from other sites without giving proper credit to the original author. Thank you. – Bill the Lizard Nov 18 '09 at 15:05

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.

查看更多
登录 后发表回答
相关问题
查看全部
相关文章
查看全部
收藏的人(4)