Summary tools

Hi folks, I am doing an export and need to compute some summary data.
This is basically a flat file and the significant fields are
account string,cost
If the account strings match I want to roll those lines up and sum the cost.

below is an example

A100,1000
B100,2000
C100,3000
A100,4000
B100,2000

my output should be
A100,5000
B100,4000
C100,3000

any ideas?

There are a lot of manners to do that…

Not the efficient way, but in full flow code:

(assuming you have a document list with 2 string account & cost)

  • sort the document (pub.document:sortDocuments ? or custom service)
  • loop the sorted document
    • when it’s the same account -> sum
    • when it’s different -> store/add the line (account & sum)

But you can also create a java service with a Map (TreeMap ?).
It’s just a question of algorithm.

Thanks, I didn’t think about a sorting routine.