Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Connect 2026! Turn data into bold moves, April 13 -15: Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
_AnonymousUser
Specialist III
Specialist III

If Statement: tMap Expression Builder

I am trying to extract data from a database and build an expression to convert into the correct ouptut format, but i am having difficulty. My project is in Java.
The data is stored as 'string' values in the input database and is in the format:
CISR_VER
2605
2709
0
2803
3001
0
3002
Where the first 2 digits relate to the year (from a base of 1980) and the last two digits relate to the period/month (1 to 12). Therefore 2605 := Year 2006, Period 05...and 3002 := Year 2010, Period 02 and a 0 is blank or no data held.
The output i am trying to achieve is a column in the format
05/2006
09/2007
null or blank
03/2008
01/2010
null or blank
etc....
I have a tMap that trims the last two digits and stores them in Var.Month (i can use the: Integer.parseInt(Var.Month) to convert to an integer)
I have another variable Var.Year that takes the first two digits, converts them into Integer format and adds 1980.
My problem is that where there is a zero in the input source i am getting a 1980 in the output where i need it to be blank/null. I have tried to build an IF function against the expression but cant seem to get the correct syntax.
Is there an easier way to do this in one expression that converts the input to an integer and can trim the digits and add the 1980 base year and add the '/'??
Any help much appreciated!
Labels (2)
21 Replies
Anonymous
Not applicable

I'm absolutly not sure that it is your problem but if you mean that you tried to insert an IF statement in the expression box, it won't work because the code isn't generated for it. You should create a new routine with the same java code and then it will work.
_AnonymousUser
Specialist III
Specialist III
Author

Basically all i need is the correct format of an If expression to test of Var.Year is 0 then dont insert anything into the tMap output column if Var.Year is greater than 0 then add 1980 to the value and insert the value in the output.
Any Ideas?
c0utta
Creator
Creator

Hi Andrew,
Use a tJavaRow to take your incoming data flow and use the following:
if(Integer.parseInt(input_row.CISR_VER) == 0)
{
output_row.CISR_VER = "";
}
else
{
Integer year = Integer.parseInt(input_row.CISR_VER.substring(0, 2));

year += 1980;
output_row.CISR_VER = input_row.CISR_VER.substring(2, 4) + "/" + year.toString();
}

Note that you could do this inline within a tMap expression, but I've expanded it for clarity here.
Cheers,
c0utta
_AnonymousUser
Specialist III
Specialist III
Author

Many Thanks c0utta!
Worked like a charm. I didnt know that a tJavaRow was even possible.
Anonymous
Not applicable

I am trying to use a Var during using a tMap for this and getting an error:
'Syntax error on token(s), misplaced construct(s)'
This is my structure:
OUT_Table:
id
name
OUT_Table.name -> Var where this is being called
if(Integer.parseInt(name.OUT_Table) == 0) {
Var.var1 = null;
} else {
Var.var1 = name.OUT_Table;
}
Then it will go out of the that Var and into the IN_Table
When I try to run this, i get the error: 'Syntax error on token(s), misplaced construct(s)'
Thanks.

Hi Andrew,
Use a tJavaRow to take your incoming data flow and use the following:
if(Integer.parseInt(input_row.CISR_VER) == 0)
{
output_row.CISR_VER = "";
}
else
{
Integer year = Integer.parseInt(input_row.CISR_VER.substring(0, 2));

year += 1980;
output_row.CISR_VER = input_row.CISR_VER.substring(2, 4) + "/" + year.toString();
}

Note that you could do this inline within a tMap expression, but I've expanded it for clarity here.
Cheers,
c0utta
_AnonymousUser
Specialist III
Specialist III
Author

c0utta, i don't understant your affermation: "Note that you could do this inline within a tMap expression, but I've expanded it for clarity here."
I've tryed tjavaRow component and it accepts the common if java statement.
In tMap component in the Expression I'm able only to use the java statement -> Condizion?True:False.. the if statement isn't compiled..
It's right?
Anonymous
Not applicable

Yes but you can use the java statement to do it, just put that in the Expression of your output column :
Integer.parseInt(row1.CISR_VER) == 0?"" 0683p000009MPcz.pngrow1.CISR_VER.substring(2,4) + "/" + ((Integer)(Integer.parseInt(row1.CISR_VER.substring(0, 2)) + 1980)).toString())
It's a little bit more tricky I agree 🙂
janhess
Creator II
Creator II

Why not just have
row1.CISR_VER.equals("0")?"" 0683p000009MPcz.pngrow1.CISR_VER.substring(2,4) + "/" + ((Integer)(Integer.parseInt(row1.CISR_VER.substring(0, 2)) + 1980)).toString())
Anonymous
Not applicable

Yes but you can use the java statement to do it, just put that in the Expression of your output column :
Integer.parseInt(row1.CISR_VER) == 0?""0683p000009MPcz.pngrow1.CISR_VER.substring(2,4) + "/" + ((Integer)(Integer.parseInt(row1.CISR_VER.substring(0, 2)) + 1980)).toString())
It's a little bit more tricky I agree 🙂

"==" sintax does not work.
".equals" sintax does work.
Why do you suggest "=="?