One Star

[resolved] how can i add many bigdecimal ?

i have to do this operation but it returns exception error . 
row13.montant.subtract(row20.montant.add(row21.montant).add(row18.montant).add(row17.montant).add(row3.position) 
please how can i resolve this problem? 
Thank you
12 REPLIES
Four Stars

Re: [resolved] how can i add many bigdecimal ?

Hi Emy,
What error you are getting? is it null pointer? Check the post
http://www.talendforge.org/forum/viewtopic.php?id=7782
Vaibhav
One Star

Re: [resolved] how can i add many bigdecimal ?

But i have to sum many values of bigdecimal so more than two values . Ho can i calculate it please
Six Stars

Re: [resolved] how can i add many bigdecimal ?

tAggregateRow will sum them for you.
Moderator

Re: [resolved] how can i add many bigdecimal ?

Hi emy,
Could you please give us more info about your current job situation. What's your job requirment?
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
Four Stars

Re: [resolved] how can i add many bigdecimal ?

row13.montant.subtract(row20.montant.add(row21.montant).add(row18.montant).add(row17.montant).add(row3.position))
I think you missed last close bracket... check again

Vaibhav
One Star

Re: [resolved] how can i add many bigdecimal ?

Yes of course , 
I'm going to show you my job to understand what i mean :
and this is the SQL request :
Ecart = ( Montant4 - ( Position3 + Montant22 + Montant21 + Montant20 + Montant19 + Montant18 ))
and this is it on Talend : 
Ecart= row4.Montant.subtract(row3.Position.add(row22.Montant).add(row21.Montant).add(row20.Montant).add(row19.Montant).add(row18.Montant))
But it returns this error : 
Exception in component tMap_1
java.lang.NullPointerException
at java.math.BigDecimal.add(Unknown Source)
at myfirstproject.glob2_0_1.glob2.tMysqlInput_1Process(glob2.java:3288)
at myfirstproject.glob2_0_1.glob2.runJobInTOS(glob2.java:18077)
at myfirstproject.glob2_0_1.glob2.main(glob2.java:17942)
i know how to sum 2 bigdecimal but in this case what can i do i have to sum 6 bigdecimal and substract them . 
Thanks for ur answer please help me
One Star

Re: [resolved] how can i add many bigdecimal ?

Yes of course , 
I'm going to show you my job to understand what i mean :

and this is the SQL request :
Ecart = ( Montant4 - ( Position3 + Montant22 + Montant21 + Montant20 + Montant19 + Montant18 ))
and this is it on Talend : 
Ecart=row4.Montant.subtract(row3.Position.add(row22.Montant).add(row21.Montant).add(row20.Montant).add(row19.Montant).add(row18.Montant))
But it returns this error : 
Exception in component tMap_1
java.lang.NullPointerException
at java.math.BigDecimal.add(Unknown Source)
at myfirstproject.glob2_0_1.glob2.tMysqlInput_1Process(glob2.java:3288)
at myfirstproject.glob2_0_1.glob2.runJobInTOS(glob2.java:18077)
at myfirstproject.glob2_0_1.glob2.main(glob2.java:17942)
i know how to sum 2 bigdecimal but in this case what can i do i have to sum 6 bigdecimal and substract them . 
Thanks for ur answer please help me
Four Stars

Re: [resolved] how can i add many bigdecimal ?

Hi Emy,
You have null pointer exception... it means some of your column contains null value...
You will have to handle null for each column like - check the post - http://www.talendforge.org/forum/viewtopic.php?id=7782
row2.Price2==null?row1.Price1:row1.Price1.add(row2.Price2)
This is going to be a two to three line code if you do it in single tMap... but if you prefer, you can use tJavaRow to make it more simple and add it column wise..
Vaibhav
Seventeen Stars

Re: [resolved] how can i add many bigdecimal ?

hi all,
my question is "is it normal that you have null value" ?
manage null value is a tecnical issue but what's your business rule when application 's encountering null value espacially when you're doing calculation ? 
how many null value do you have from sources ? Smiley Wink
Could it be null ?
regards
laurent
One Star

Re: [resolved] how can i add many bigdecimal ?

sanvaibhav : how can i write this line row2.Price2==null?row1.Price1:row1.Price1.add(row2.Price2) for three or four bigdecimal . it does'nt work !!

kzone : yes all of them can be null .
One Star

Re: [resolved] how can i add many bigdecimal ?

thank you alll , i have found a solution Smiley Very Happy 
Four Stars

Re: [resolved] how can i add many bigdecimal ?

Emy,
Please let us know your solution... it seems you are very happy...
Vaibhav