Return Value subreport iReport

I am using iReport 4.0.2 and I want to show the result in my main report. For example, in my main report, we have two columns, and I want to get the sum of these two columns, just like this format:

AB sum 10 5 15 

Where A is one field of the main report, and B is the return value of my sub-register. It works well. But the key point is that sometimes subreport does not return any value, which is a problem. In this case, the result of the sum is as follows:

 AB sum 10 NULL 

As we see here, B is the return value of subreport, but it does not have a value of NULL or 0. That's why we have this problem.

I am trying to find how to get the return value from a subreport when SQL returns no results. I know that iReport has the "When there is no data" property, but this does not help. So I want to know if we have another way to solve the problem in iReport or using some SQL skills.

+3
source share
2 answers

I think that in your second example, B is actually null, but perhaps your text box has the property "Empty when null". I was able to reproduce your results, with the exception of a space for B.

The real problem is that you cannot add or subtract with a zero value. JasperReports will just print zero. You need to add some logic to provide a default value if one of the variables in the expression is zero. for instance

 $F{MAIN_REPORT_FIELD} - ($V{SUB_RESULT} == null ? 0 : $V{SUB_RESULT}) 

Unfortunately, this does not work for reports that use Groovy for expressions in JasperReports 4.0.2 ( Case 0005138 ) and will always return null.

You have several options:

  • You can upgrade to JasperReports / iReport 4.1.1, which solves this problem.
  • You can switch to using Java for expressions.

    Depending on your report, it will either be painless or it will be a difficult task. Any fields that do not have the correct Expression class should be fixed, and you should probably be more explicit in any expression that performs operations on non-primitive / wrapper types.

+2
source
  • if you make the sum of the main field and the auxiliary report field in the main report and then in the sum expression (main field of the report + (subreportfield == null? 0: subreportfield).

  • return the values โ€‹โ€‹of the subordinate data to the main report variable.

Then enter the sum of the main field of the report and the return variable bareport.

Follow the same condition as above.

0
source

Source: https://habr.com/ru/post/1489660/


All Articles