简体   繁体   English

子报表中的Crystal报表共享变量未显示在主报表的页眉中

[英]Crystal reports shared variable in sub report not displaying in page header of main report

I have a sub report section that displays details (line items) related to an order. 我有一个子报告部分,其中显示与订单相关的详细信息(订单项)。 Within this sub report I have created a shared variable for returning the sum of a weight field: 在此子报告中,我创建了一个共享变量以返回权重字段的总和:

WhilePrintingRecords;
Shared numbervar WeightTotal := Sum ({Report.TotalWeight})

In my main report I have created another variable to display the sub reports total weight: 在主报告中,我创建了另一个变量来显示子报告的总重量:

WhilePrintingRecords;
shared numbervar WeightTotal;
WeightTotal;

This works fine for displaying the total within the report footer or the page footer. 这对于在报表页脚或页面页脚中显示总计非常有用。 However, I need to display this amount in the page header. 但是,我需要在页眉中显示此数量。

I have tried creating another report variable with the EvaluateAfter() function to attempt to bring this data into the header section. 我尝试使用EvaluateAfter()函数创建另一个报告变量,以尝试将此数据带入标头部分。 That didn't work. 那没用。

I have also tried following the suggestions of creating a global variable in the main report as per this thread: Crystal Reports: global variable running total not displaying in header 我也尝试按照以下建议按照在主报表中创建全局变量的建议进行操作: Crystal Reports:全局变量运行总计未显示在标题中

Is performing a task like this even possible? 是否可以执行这样的任务? The underlying data is generated by sp's (both shared across a few different reports). 基础数据是由sp生成的(在几个不同的报告中共享)。 I could break out a new sp to simply sum this total but I would prefer to delegate this to crystal. 我可以创建一个新的sp来简单地求和,但是我更愿意将其委托给crystal。

The problem is that while the use of WhilePrintingRecords in your second formula forces Crystal to evaluate it later than normal during the final evaluation pass, this is also when subreports are evaluated. 问题是,虽然在第二个公式中使用WhilePrintingRecords会强制Crystal在最终评估过程中比平时更晚地评估它,但这也是在评估子报表时。 This means that any formulas in the main report are processed relative to the subreport. 这意味着将对于子报表处理主报表中的任何公式。 In your case, the formula in the header is evaluated before the subreport in the details section, even with the WhilePrintingRecords keyword. 对于您而言,即使使用WhilePrintingRecords关键字,也要在详细信息部分的子报表之前评估标题中的公式。 This diagram is awesome for understanding the different passes: Multi-Pass Reporting Process . 该图对于理解不同的通过非常有用: Multi-Pass Reporting Process

You could try using a SQL Expression to do a simple aggregate summation for each details section. 您可以尝试使用SQL表达式为每个详细信息部分执行简单的汇总求和。 Not knowing anything about your data source or schema it's hard to give an example, but here's the general idea. 不了解您的数据源或架构,很难给出一个例子,但这是一般的想法。 You can use any valid SQL for your data source as long as it returns a scalar. 只要返回标量,就可以将任何有效的SQL用于数据源。

select sum(weight)
from table
where table.orderID="table"."orderID"

An alternative would be to use an additional inner grouping level per order, get rid of the subreports altogether, and use Crystal's sum() function or a global variable to get the weight per inner group. 另一种方法是每个订单使用一个额外的内部分组级别,完全删除子报表,并使用Crystal的sum()函数或全局变量来获得每个内部组的权重。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM