Add the result of a variable to another variable

Asked

Viewed 43 times

0

I have the following problem:

I developed a report in iReport 5.5.1 where I added the data of a column into a variable because I need to show this total, and then I need to take these totals and sum it all into a new variable in order to show the total macro, exemplifying:

There are several types of fault and each with its total, for example,

"Joãozinho had 20 fouls for pain in the foot and 10 fouls for laziness"

My first variable, would return the numbers 20 and 10, now the second would add up these results and show. But when I try to do this in a conventional way, that would be creating a variable and the value expression assign the other, iReport simply goes crazy and makes some sums without foot or head.

Follows the code:

<variable name="TOTDIAS_LICENCA" class="java.math.BigDecimal" resetType="Group" resetGroup="LICENCA_PRORROGA" calculation="Sum">
    <variableExpression><![CDATA[$F{TOTDIAS}]]></variableExpression>
</variable>
<variable name="variable1" class="java.lang.String" resetType="Group" resetGroup="LICENCA_PRORROGA" calculation="Sum"/>
<variable name="DIAS_PRORROG" class="java.math.BigDecimal" resetType="Group" resetGroup="LICENCA_PRORROGA">
    <variableExpression><![CDATA[$V{TOTDIAS_LICENCA}.compareTo( $F{DIAS_MINIMO})>0 ?$V{TOTDIAS_LICENCA}.subtract($F{DIAS_MINIMO}) : new BigDecimal(0)]]></variableExpression>
    <initialValueExpression><![CDATA[0]]></initialValueExpression>
</variable>
<variable name="TOTFINAL" class="java.lang.Integer" resetType="Group" resetGroup="AQUISITIVO" calculation="Sum">
    <variableExpression><![CDATA[$V{DIAS_PRORROG}]]></variableExpression>
    <initialValueExpression><![CDATA[0]]></initialValueExpression>
</variable>

inserir a descrição da imagem aqui

1 answer

0

Hello good night before anything else, in case you don’t know iReport is out of use, the staff has been using Jasper Reports for development, which is based on the eclipse much like iReport. That being said, variables have execution times when used in components and, as you can see in this print, this simple variable resets its value at the end of the Driver OS group, which in my rule has meaning to occur at this time.

Propriedades Variavel

Already in this other I have a sum and reset only at the end of the report and should be incremented only in the group Driver OS ie is a general counter of all records different from the above that counts only in the location of my subreport

inserir a descrição da imagem aqui

And as I said about the Textfield Valuation Time, in this property you will notice that you can manipulate according to your situation using various values, NOW, REPORT, PAGE, COLUMN, BAND, AUTO, MASTER besides the groups you create, maybe in ireport is a little different or does not have any of these values, but no doubt your calculation problem is in those states of Textfield and either reset us or increment the variable.

inserir a descrição da imagem aqui

The only solution to your problem and you make several combinations using these values until you get what you need and until you can understand how it works, it is a little complex and the exercise will undoubtedly help your evolution with the generation of reports.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.