Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi, i need help, I'm trying to add a glaobal vairalbe with a filed (bigdecimal) and im getting the following error: The operator + is undefined for the argument type(s) Object, BigDecimal
Note : im doing this in the tjavaflex:
Start Code:
int sumfxd = 0;
int sumfxc = 0;
int summmd = 0;
int summmc = 0;
globalMap.put("sumfxd", sumfxd);
globalMap.put("sumfxc", sumfxd);
globalMap.put("summmd", sumfxd);
globalMap.put("summmc", sumfxd);
Main Code:
if (row1.Module.equals("FX") && row1.Entrysign.equals("D")) {
globalMap.put("sumfxd" , globalMap.get("sumfxc")+row1.Amount);
}
else if (row1.Module.equals("FX") && row1.Entrysign.equals("C")) {
globalMap.put("sumfxc" , globalMap.get("sumfxc") + row1.Amount);
}
else if (row1.Module.equals("MM") && row1.Entrysign.equals("D")) {
globalMap.put("summmd" , globalMap.get("summmd") + row1.Amount);
}
else if (row1.Module.equals("MM") && row1.Entrysign.equals("C")) {
globalMap.put("summmc" , globalMap.get("summmc") + row1.Amount);
}
Thanks
There are two issues here. Values stored in the globalMap are held as Objects. Due to this, you need to cast the value to one you are expecting. Also, your "Amount" field looks like it is a BigDecimal. You therefore have to use the BigDecimal methods for addition. This code below *should* work...
int sumfxd = 0; int sumfxc = 0; int summmd = 0; int summmc = 0; globalMap.put("sumfxd", new BigDecimal(sumfxd)); globalMap.put("sumfxc", new BigDecimal(sumfxc)); globalMap.put("summmd", new BigDecimal(summmd)); globalMap.put("summmc", new BigDecimal(summmc)); Main Code: if (row1.Module.equals("FX") && row1.Entrysign.equals("D")) { globalMap.put("sumfxd" , ((BigDecimal)globalMap.get("sumfxc")).add(row1.Amount)); } else if (row1.Module.equals("FX") && row1.Entrysign.equals("C")) { globalMap.put("sumfxc" , ((BigDecimal)globalMap.get("sumfxc")).add(row1.Amount)); } else if (row1.Module.equals("MM") && row1.Entrysign.equals("D")) { globalMap.put("summmd" , ((BigDecimal)globalMap.get("summmd")).add(row1.Amount)); } else if (row1.Module.equals("MM") && row1.Entrysign.equals("C")) { globalMap.put("summmc" , ((BigDecimal)globalMap.get("summmc")).add(row1.Amount)); }
Global variables must be casted to the according data type when you want to get the current values:
(Integer)globalMap.get("sumfxc")
There are two issues here. Values stored in the globalMap are held as Objects. Due to this, you need to cast the value to one you are expecting. Also, your "Amount" field looks like it is a BigDecimal. You therefore have to use the BigDecimal methods for addition. This code below *should* work...
int sumfxd = 0; int sumfxc = 0; int summmd = 0; int summmc = 0; globalMap.put("sumfxd", new BigDecimal(sumfxd)); globalMap.put("sumfxc", new BigDecimal(sumfxc)); globalMap.put("summmd", new BigDecimal(summmd)); globalMap.put("summmc", new BigDecimal(summmc)); Main Code: if (row1.Module.equals("FX") && row1.Entrysign.equals("D")) { globalMap.put("sumfxd" , ((BigDecimal)globalMap.get("sumfxc")).add(row1.Amount)); } else if (row1.Module.equals("FX") && row1.Entrysign.equals("C")) { globalMap.put("sumfxc" , ((BigDecimal)globalMap.get("sumfxc")).add(row1.Amount)); } else if (row1.Module.equals("MM") && row1.Entrysign.equals("D")) { globalMap.put("summmd" , ((BigDecimal)globalMap.get("summmd")).add(row1.Amount)); } else if (row1.Module.equals("MM") && row1.Entrysign.equals("C")) { globalMap.put("summmc" , ((BigDecimal)globalMap.get("summmc")).add(row1.Amount)); }
Sorry @TRF I think I must have clicked "reply" before you had posted your answer
Yours is better as you have carrefully check the expected data type!
Thank you very much, it worked,
I was a bit confused but you example works PERFECT
THANK YOU !!