Page 1 of 1

Sum Cclculation in Lansa

Posted: Thu Oct 20, 2016 10:25 pm
by wizard
Hello.
12.PNG
12.PNG (4.23 KiB) Viewed 7018 times
This is a field from my database that I have successfully display it into webpage.
The question is how do it do to calculate total sum of the field (calculate sum of every row on that field)?
Does it need to be done in srvroutine or in evtroutine at webpage?
Please help.

Regards

Re: Sum Cclculation in Lansa

Posted: Fri Oct 21, 2016 4:36 am
by LANSAGuru
Whether you do this on the server or on the client does not matter.
You can

a) do it on the server and return the sum
or
b) do the sum in the browser

So you have the values in a list. Simply spin the list and accumulate the sum.

#sum := 0
Selectlist #listname
#sum += #yourfield
endselect

Now #sum has the total.

Re: Sum Cclculation in Lansa

Posted: Fri Oct 21, 2016 8:16 am
by HamadSheikh
Just before your Add_Entry line, where you add your entry into your list, you can accumulate your total e.g.

#TotalField := #TotalField + #NumFieldFromList

After you are done populating the list, your #TotalField will contain the sum of all #NumFieldFromList entries.
Don't forget to reset #TotalField to zero before each list gets built.