I am working on a jasper report in that I am using a field "RACE_CODE" which contains values like 'abc','lmn','pqr','xyz'. For one person there can be multiple RACE_CODE assigned to it.
So I want the output in term of four digits like:
If a person have RACE_CODE 'abc' and 'xyz' then it should display '1001' and so on.
I can use conditional statement like:
$F{RACE_CODE} == 'abc' && $F{RACE_CODE} == 'xyz' ?
'1001' : ($F{RACE_CODE} == 'abc' ? '1000' : so on
But this is not a feasible way because for four digits I will be having 12 combinations.
Is there any other way in which I can achieve this? Please help to solve this.
1 Answer:
Posted on July 1, 2015 at 12:57am
Why 7 digids? You start only with 4 :) I guess that one of the possible values of $F{RACE_CODE} is "abcxyz" (you don't write example of data). Is it right? In this case you can use expression like this (java code example):
public static void main(String[] args) { String RACE_CODE = "abcxyz"; System.out.println(RACE_CODE.indexOf("abc") == -1 ? "0" : "1" + (RACE_CODE.indexOf("lmn") == -1 ? "0" : "1") + (RACE_CODE.indexOf("pqr") == -1 ? "0" : "1") + (RACE_CODE.indexOf("xyz") == -1 ? "0" : "1")); }
$F{RACE_CODE} == 'abc' && $F{RACE_CODE} == 'xyz' always false.
>>For one person there can be multiple RACE_CODE assigned to it.
Report field have only one value.
Question is unclear
Thanks @sanbez for your response :).
Yeah you are right. One person can have multiple race codes. In my case there are 7 race codes and one person can have many race codes from these seven values. So for this, I want seven digit binary representation.
Want i want is:
IF RACE_CODE CONTAINS (abc,lmn)
then display 1100000
if RACE_CODE CONTAINS (abc,xyz)
display 1000001
I am taking some test values here like abc,lmn,xyz for demo.