Sum Cclculation in Lansa

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
Posts: 10
Joined: Thu Aug 25, 2016 12:48 pm

Sum Cclculation in Lansa

Post by wizard » Thu Oct 20, 2016 10:25 pm

12.PNG (4.23 KiB) Viewed 1599 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.


Posts: 68
Joined: Thu Mar 24, 2016 5:31 am

Re: Sum Cclculation in Lansa

Post by LANSAGuru » Fri Oct 21, 2016 4:36 am

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

Now #sum has the total.

Posts: 27
Joined: Fri Mar 18, 2016 3:49 am
Location: USA

Re: Sum Cclculation in Lansa

Post by HamadSheikh » Fri Oct 21, 2016 8:16 am

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.

Post Reply