Four Stars

Design a logic in talend

Hi All

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'
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

Sixteen Stars

Re: Design a logic in talend

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.

TRF
Four Stars

Re: Design a logic in talend

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

Sixteen Stars

TRF
Four Stars

Re: Design a logic in talend

I have sent a private message.

Sixteen Stars

Re: Design a logic in talend

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

TRF

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog