Design a logic in talend

Four Stars

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

Sixteen Stars TRF
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

@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

Sixteen Stars TRF
Sixteen Stars

Re: Design a logic in talend

Share your code

TRF
Four Stars

Re: Design a logic in talend

I have sent a private message.

Sixteen Stars TRF
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

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

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

Best Practices for Using Context Variables with Talend – Part 3

Read about some useful Context Variable ideas

Blog