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

Announcements
Qlik and ServiceNow Partner to Bring Trusted Enterprise Context into AI-Powered Workflows. Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Design a logic in talend

Hi All

I am a newbie to talend. Please help me to implemement below logic in Talend.

 

if (In_Date_Check = '1') then
Out_Years := date_diff(to_date(CURDATE('DD/MM/YYYY'), 'DD/MM/YYYY'), In_Date, 'Y')
if (Out_Years < 0) then
Out_Status := 'Valid'
Out_Status_Note := 'Age is negative'
elseif (Out_Years >= 0 and Out_Years < 18) then
Out_Status := 'Valid'
Out_Status_Note := 'Minor'
elseif (Out_Years >= 18 and Out_Years <= 120) then
Out_Status := 'Valid'
Out_Status_Note := 'Adult'
else
Out_Status := 'Invalid'
Out_Status_Note := 'Current age is over 120 years'
endif
else
Out_Status := 'Invalid'
Out_Status_Note := 'Invalid date input'
endif

Labels (2)
5 Replies
TRF
Champion II
Champion II

You can use ternary notation to replace "if-then-else" like this:

"AAA".equals(row1.field1) ? "Only A" : "BBB".equals(row1.field1) ? "Only B" : "Something else"

You can combine as many levels as needed but more than 3 or 4 make code difficult to read/maintain.

To get current date use the following expression:

TalendDate.getCurrentDate()

Finally to compare dates, use:

TalendDate.compareDate(myDate1, myDate2)

This will render -1 if first date is less than second one, 0 if both are equals and 1 if first date is bigger than second.

 

Anonymous
Not applicable
Author

@TRF 

 

Thanks for the reply. I was doing as per this way only but If I test that code in Expression tab it always throws some java error.

ERROR-Exception in thread 'main'. Unresolved compilation error. For simple codes also it throws some erro

TRF
Champion II
Champion II

Share your code
Anonymous
Not applicable
Author

I have sent a private message.

TRF
Champion II
Champion II

Thanks to continue in the post.
At least replace -- by - for substraction and replace == by equals() for strings comparison