Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

how to summarize a global variable to a field (big decimal)

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

 

 

Labels (1)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

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));


}

View solution in original post

5 Replies
TRF
Champion II
Champion II

Global variables must be casted to the according data type when you want to get the current values:

(Integer)globalMap.get("sumfxc")

 

Anonymous
Not applicable
Author

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));


}
Anonymous
Not applicable
Author

Sorry @TRF I think I must have clicked "reply" before you had posted your answer

TRF
Champion II
Champion II

Yours is better as you have carrefully check the expected data type! 

0683p000009MA9p.png

Anonymous
Not applicable
Author

Thank you very much, it worked,

 

I was a bit confused but you example works PERFECT

 

THANK YOU !!