只有当波段(组)等于子报告所在的波段时,您才可能尝试增加变量(我将其命名为 totalSum)。为此,您需要报告中的一个字段来为您提供当前乐队(组)。
<variable name="totalSum"
class="java.lang.Integer"
resetType="Report"
incrementType="Group"
incrementGroup="ITEM_BUNDLE"
calculation="Nothing">
<variableExpression>
<![CDATA[new Boolean($F{reportPart}.equals("The_band_with_the_subreport")).booleanValue() ? $V{returnValue} : $V{totalSum}]]>
</variableExpression>
<initialValueExpression>
<![CDATA[new Integer(0)]]>
</initialValueExpression>
</variable>
我不确定这是否有效,我没有上下文来测试它。但您也可以尝试第二种解决方案- 使用三个变量。例如,您将子报表返回的值(比如说returnValue)保存在一个变量中,并使用另外两个变量来保存总和 - 一个直到子报表被调用(比如说partialSum),第二个变量存储两个变量之间的总和returnValue 和 partialSum。我们称之为总和。然后你会有这样的总和:
<variable name="totalSum"
class="java.lang.Integer"
resetType="Report"
incrementType="Group"
incrementGroup="ITEM_BUNDLE"
calculation="Nothing">
<variableExpression>
<![CDATA[$V{returnValue} + $V{partialSum}]]>
</variableExpression>
<initialValueExpression>
<![CDATA[new Integer(0)]]>
</initialValueExpression>
</variable>
对于 partialSum,你会有这样的东西:
<variable name="partialSum"
class="java.lang.Integer"
resetType="Report"
calculation="Sum"
incrementType="None">
<variableExpression>
<![CDATA[new Boolean($F{reportPart}.equals("The_band_with_the_subreport")).booleanValue() ? $V{returnValue} : new Integer(0)]]>
</variableExpression>
<initialValueExpression>
<![CDATA[new Integer(0)]]>
</initialValueExpression>
</variable>
我希望这能有所帮助。从 iRport 直接在您要使用的报告上进行所有这些设置会更容易。