One Star

[resolved] Substring and IfThenElse

Hi there,
I am still quite new to Talend and trying to build my DS jobs on Talend. I was quite surprised to find that there is nothing in StringHandling for Substring. I wasted 1 hr used many left, right and change in many variables to make substring work. While searching forum I found a suggestion to replicate Substring by using this "rha.ACTES.substring(0, java.lang.Math.min(rha.ACTES.length(),8))"
Not sure what is rha and ACTES but it didnt work for me. Sorry I am not great in Java and yes its Java based project I am working on.
Again for IfThenElse I found "String?value:value" It worked for me. Not sure if there is real IfThenElse in Talend for non Java programmer.
Please advice.
Thanks
1 ACCEPTED SOLUTION

Accepted Solutions
Community Manager

Re: [resolved] Substring and IfThenElse

Hello
using this "rha.ACTES.substring(0, java.lang.Math.min(rha.ACTES.length(),8))"

You can use the substring(int firstIndex, int lastIndex) method of String class. eg:
"shong".substring(0,3) ==>sho
rha.ACTES.substring(0, java.lang.Math.min(rha.ACTES.length(),8))
rha is the flow name, ACTES is column name.
Again for IfThenElse I found "String?value:value" It worked for me. Not sure if there is real IfThenElse in Talend for non Java programmer.

yes, you are right. the ifthenelse statement is replaced by format: "condition?value1:value2". You can aslo create a routine and use the ifthenelse in java code.
Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
11 REPLIES
Community Manager

Re: [resolved] Substring and IfThenElse

Hello
using this "rha.ACTES.substring(0, java.lang.Math.min(rha.ACTES.length(),8))"

You can use the substring(int firstIndex, int lastIndex) method of String class. eg:
"shong".substring(0,3) ==>sho
rha.ACTES.substring(0, java.lang.Math.min(rha.ACTES.length(),8))
rha is the flow name, ACTES is column name.
Again for IfThenElse I found "String?value:value" It worked for me. Not sure if there is real IfThenElse in Talend for non Java programmer.

yes, you are right. the ifthenelse statement is replaced by format: "condition?value1:value2". You can aslo create a routine and use the ifthenelse in java code.
Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] Substring and IfThenElse

Hi Shong,
Thanks again for your assistance.

I ran it and yeah substring worked. Now regarding IfThenElse - I wasted quite a lot of time and everythime I tested the syntax I received error from talend but when I ran it it worked. I attached pic2 showing this.
Now when I run my half complete job which goes to directory, extracts file properties and store in file - I find it does not work properly. For example : Traces misses one field randomly to write in file and one function which substring does not work always. Pic1 is showing how program is missing one field randomly by traces.
I checked for special characters in file names but couldnt find any big issue.
I have also sent export of file to you in mail for your ref.
Thanks for your help.
Regards
Amit
One Star

Re: [resolved] Substring and IfThenElse

Hi Shong,
Please ignore my previous mail. Its working now. I have no idea why it was failing but I rebuilt whole job and it works. But when I use Oracle table instead of File output it gives errors (which I can not interpret and understand).
Is there any way a non java programmer can understand these errors?
Regards
Amit
Community Manager

Re: [resolved] Substring and IfThenElse

Hello
Please show us the error code and the error message, a screenshot of your job will be better.Smiley Happy
Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] Substring and IfThenElse

Hi Shong,
Thanks for the reply. I tried attaching two screen shot one with disabling Oracle link and one with active link. But some how I am getting "Unable to copy from clipboard". I will send them asap too.
Error when I Activate the Oracle link is:
connecting to socket on port 3378
connected
connecting to socket on port 5172
connected
Exception in component tOracleOutput_1
java.lang.NullPointerException
at test.siebel_binary_0_1.Siebel_Binary.tFileList_1Process(Siebel_Binary.java:1426)
at test.siebel_binary_0_1.Siebel_Binary.runJobInTOS(Siebel_Binary.java:2304)
at test.siebel_binary_0_1.Siebel_Binary.main(Siebel_Binary.java:2206)
disconnected
disconnected
Job Siebel_Binary ended at 16:29 10/08/2009.
I just copied the links going to file to Oracle table and made it drop/create-insert.
Another question, Is it possible to continue use this table as source table or do I need to create another job for this?
Regards
Amit
Community Manager

Re: [resolved] Substring and IfThenElse

Hello
Exception in component tOracleOutput_1
java.lang.NullPointerException

Can you upload a screenshot of your job or export your job and send it to me? I would debug your job...
Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] Substring and IfThenElse

Hi Shong,
I sent the export to you.
Two more queries:
1> In my Oracle link I can see one magnifier symbol but not in other link what does it mean?
2>Can this OracleOutput be used as input once its successfully filled with data?
Regards
Amit
Community Manager

Re: [resolved] Substring and IfThenElse

Hello Amit
After I import your job and find that you have selected 'use a existing connection' option, but there is not a tOracleConnection in your job, so the job throws an null pointer exception.
1> In my Oracle link I can see one magnifier symbol but not in other link what does it mean?

tOracleOutput is a output component, it needs a input component, but you desativate the link, if you don't want this component to work, you should desativate this component, not the link.
2>Can this OracleOutput be used as input once its successfully filled with data?

If it is used as a input, the data comes from the previous component, not DB. So, you should use a tOracleInput if you want to query record from a database.
Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] Substring and IfThenElse

Hi Shong,
Thanks for reply.
I have used 'use a existing connection' option. I have removed it as it had details of my production server. Connection is working properly only issue is this DB link does not work. Please use any connection string with that job to see real error.
Regards
Amit
One Star

Re: [resolved] Substring and IfThenElse

Hi Shong,
New development : When I removed the Oracle connection stage and hardcoded the connection string in OracleOutput it start working. I am completely lost. My understanding was one connection can be used for all Input and output Oracle stages.
Thanks for your help mate!
Regards
Amit
One Star

Re: [resolved] Substring and IfThenElse

Hi All,
I am also facing the error for Substring
E.g
row3.RES_NUMBER.substring(0,6): it is giving me the error
if i use the below code :
row3.RES_NUMBER.substring(0, java.lang.Math.min(row3.RES_NUMBER.length(),6))
result : no error.

i don't know the reason
Please help me in understanding the logic behind this.
Thanks!