Jasper - How to remove complete row when 1 perticular field is null? - jasper-reports

I want to print pdf something like this
Name Class RollNo
------- ---------- -----------
John 5 <null>
Mark 5 103
Robert 6 104
I need to add condition if RollNo is null then remove that row in 'detail' band.

You can use the report's filter expression or the detail band's print when expression. The filter expression completely skips the record, which is not counted and does not participate in aggregations, while the band's print when expression simply inhibits the band from printing.
<filterExpression>$F{RollNo} != null</filterExpression>
...OR...
<detail>
<band height="x">
<printWhenExpression>$F{RollNo} != null</printWhenExpression>
<textField>
...

Related

Select non-empty string rows in KDB

q)tab
items sales prices detail
-------------------------
nut 6 10 "blah"
bolt 8 20 ""
cam 0 15 "some text"
cog 3 20 ""
nut 6 10 ""
bolt 8 20 ""
I would like to select only the rows which have "detail" non-empty. Seems fairly straightforward, but not i can't get it to work.
q) select from tab where count[detail] > 0
This gives all the rows still.
Alternatively i tried
q) select from tab where not null detail
This gives me type error.
How can one query for non-empty string fields in KDB???
Rather than use adverbs, you can simplify this with the use of like.
q)select from tab where not detail like ""
items sales prices detail
------------------------------
nut 1 10 "blah"
cam 5 9 "some text"
As you need to perform the check row-wise, use each:
select from tab where 0 < count each detail
This yields to the following table:
items sales prices detail
------------------------------
nut 6 10 "blah"
cam 0 15 "some text"
Use the adverb each:
q)select from ([]detail:("blah";"";"some text")) where 0<count each detail
detail
-----------
"blah"
"some text"
I would use following approach
select from tab where not detail~\:""
where every detail is compared to empty string. Approach with not null detail does not work, because Q treats string as character array and checks if each of array elements is null. I.e. null "abc" returns boolean array 000b, but where clause expects for single boolean value for each "row"
If your table is not big, another way you can check is by converting it to a symbol in the where clause.
q)select from ([]detail:("blah";"";"some text")) where `<>`$detail
detail
-----------
"blah"
"some text"
Or simply
q)select from ([]detail:("blah";"";"some text")) where not null `$detail
detail
-----------
"blah"
"some text"

How to Check param from iReport with database?

Currently I'm doing report using iReport 3.0.0
I have this one field which is Indicator (A, B and C).
I group by this field so that All records will print in different page based on Indicator. (I use iReport Group By function)
However, I have certain time that when it query my sql, it will return only A and C.. How if I wanna generate Ind = B too with text NO RECORD FOUND
This is my current expression:
($F{IND}.equals("A")) ? "SMS MESSAGE NOT FOUND" : (
($F{IND}.equals("B")) ? "CW MESSAGE NOT FOUND" : (
($F{IND}.equals("C")) ? "STATUS MIS-MATCHED" : null
)
)
How can I check if IND = B not exist in my database, then print NO RECORD FOUND ?
Thanks in advance for your help !
You can use a special variable to count the rows in the group B.
Either use the built-in variable ${YOUGROUP_COUNT} (source)
Or increment a variable yourself : see more information here
When you have this variable set up, you can have a textField containing NO RECORD FOUND. Use the attribute printWhenExpression to display this textField only when the group count is equal to zero.
<staticText>
<reportElement x="234" y="10" width="100" height="30" uuid="05895bf2-3ce1-4d88-82fe-ff3fd650eaf6">
<printWhenExpression><![CDATA[${YOURGROUP_COUNT} == 0]]></printWhenExpression>
</reportElement>
<text><![CDATA[NO RECORD FOUND]]></text>
</staticText>
Don't display this static text element in a detail band, because it won't be displayed if there is no record. Use any other band to display it.

Jasper Reports - calculation of total using CalculationEnum.System

I have 3 columns (obtained from the query along with the data)
| A | B | C |
| 5 | 15 | 20 |
| 15| 25 | 40 |
The net total for these columns are to be calculated as below :-
20 40 0.5 (i.e , the total of C = total of A / total of B) . How do I get the total calculated as required in jasper reports using java .
For calculating the total of column 'C' , I have set the calculation enum constant to be calculationEnum.SYSTEM . On setting the expression to be
expression.setText("new Double($F{" +A + "/" +B +"}.doubleValue())"); , it shows that the corresponding field , new Double($F{A/B}.doubleValue()) does not exist . To eliminate this , I have added the field in the list of field columns . But then it shows that the column for the corresponding field doesnot exist .
Is what I have done until now correct ? Or is there any better way in which I can get the total to be calculated as required .
Field A and B need to be of class="java.lang.Number" or one of its sub classes as java.lang.Double
To get the sum of them the expression is:
$F{A}.doubleValue() + $F{B}.doubleValue()
To calculate the SUM($F{A}) / SUM($F{B}) you need to use two variables
<variable name="sumOfA" class="java.lang.Double" calculation="Sum">
<variableExpression><![CDATA[$F{A}]]></variableExpression>
<initialValueExpression><![CDATA[0]]></initialValueExpression>
</variable>
<variable name="sumOfB" class="java.lang.Double" calculation="Sum">
<variableExpression><![CDATA[$F{B}]]></variableExpression>
<initialValueExpression><![CDATA[0]]></initialValueExpression>
</variable>
And then in the textField do the division, remember to set evaluationTime="Report" on the textField so that the variables have been calculated before displaying.
<textField evaluationTime="Report">
<reportElement x="208" y="17" width="100" height="20" uuid="414e6633-58c5-4081-a04b-fe3973f29d96"/>
<textFieldExpression><![CDATA[$V{A}.doubleValue()/$V{B}.doubleValue()]]></textFieldExpression>
</textField>
Create two variables, one for sum of A and one for sum of B.
And then add a text field with the following expression:
($V{sumOfA}/$V{sumOfB})

BIRT Report Tool

I created a Report using BIRT Report Design in Eclipse Java EE IDE(Juno Release).
In that Report, For the single row it have multiple values for the corresponding one column(I used LISTAGG() oracle function to map that).
(i.e.) Result column have multiple values in the below database table output :
No Name Result Mark
-----------------------------------
1 John X 32
XX
XXX
2 Joe X 56
XX
XX
XXX
3 Andrew 34
XXX
XX
XXXX
…
It have both NULL and NOT NULL values in it.
"If the NULL values are in the middle means its showing the results properly in the Report"
Sample Result am getting in Report output for Joe (.pdf form)
No Name Result Mark
-----------------------------------
2 Joe X 56
XX
XX
XXX
Here the problem is,
“If First record has a NULL means it is not showing properly in the Report, instead of that NOT NULL value will print in the front and so on…”
Sample Result am getting in Report output for Andrew (.pdf form)
No Name Result Mark
-----------------------------------
3 Andrew XXX 34
XX
XXXX
But we have TWO NULL values present in the Front of Result column for Andrew (As you see sample oracle table output above)…
Is there any option to show blank in the first row(if it is a null) for the particular row in the birt report tool ?
Kindly Help me to Solve this issue… Thank you!
While I did not try to understand exactly what your issue is, in general when null values in the data are causing problems with a BIRT report. Use one of these two solutions.
Use the data base function to convert the NULL to something else. In SQL I use the command ISNULL
Use a computed column in the BIRT 'Data Set' to create a new column, write whatever you need in JS. In the example below I need to make a decision on a date field that is sometimes null, in comparison to an input parameter.
if (row["START_TIME"] == null){
"F"
} else if (row["END_TIME"] == null){
"T"
}else if (row["START_TIME"].getTime() >= params["WeekOf"].getTime() ){
"T"
}else if(row["END_TIME"].getTime() <= params["WeekOf"].getTime() ){
"F"
}else if(row["END_TIME"].getTime() >= params["WeekOf"].getTime() ){
"T"
}else{
"F"}

How to get sum of entire field?

I'm going to get the sum of a entire field in Jasper Report. I'm passing JRTableModelDataSource from a Java code.
Table
Unit Price | Quantity
100.00 | 5
150.00 | 2
200.00 | 4
I'm printing these values in my report using field.
Field Expression
$F{Unit Price}*$F{Quantity}(This is the variable named '$V{MUL}')
and it prints
500.00
300.00
800.00
And now I need to prints the sum of all these values such as,
500.00
300.00
800.00
------
1600.00
I need to print this 1600.00(Sum of entire Field) in my report.
I tried with this,
SUM($V{MUL})
$V{MUL} is the variable that of multiplied values(500.00,300.00,800.00)
But I got an error. Is this possible to do or How can I do this?
You can do as shown below
<variable name="GrpAmount" class="java.math.BigDecimal" resetType="Group" resetGroup="keyType" calculation="Sum">
<variableExpression><![CDATA[$F{Unit Price}*$F{Quantity}]]></variableExpression>
</variable>