I'm not able to see an issue with the piece of code that you have pasted here. Maybe you could open a bug report with halcust attached and repeatable situation that I can look at?
Actually a new version of this bug is SL>>Reports>>Periodic customer statement "accumulates" amounts
Not sure why it was duplicated, I clicked "submit"only once....