Sum temporary table

Hi Guys,

Is it possible to sum a form grid column (e.g. Cost), given that it’s datasource is a temporary table and where it should be saved is also a temporary table? cause I have no idea on how to do this.

to further explain the scenario:

tempTableHeader.TotalCost → field to update every time the grid column ‘tempTableLines.Cost’ changes its value (as soon as the user left the ‘Cost’ column), placed in a header group of the form

tempTableLines.Cost → editable source field column in the grid that needs to be summed. placed under the header group of the form.

Hope to get some help from you guys.

Thank you very much in advance.

It’s actually pretty simple. Create a new TempTableLines buffer with the same data:

TempTableLines costSum;
costSum.setTmpData(tempTableLines); //tempTableLines is the form datasource buffer

And select data as usual:

select sum(Cost) from costSum;

Hi Martin,

Thanks for your reply. Just a correction in my previous post,

tempTableLines.Cost is placed in a grid under the header group of the form.

And also, where should I put exactly this method?

Thank you very much. :slight_smile:

It depends when you want to update the header. It may be launched when the Cost on line is modified (field’s modified()), when the line is saved (write()) or so.