As I wrote in my answer to Henrique (pls see below) the data is submitted to the function on combination of company, profit center and account (CO_CO, PR_CTR and ACCT) and the result (output table) must also be 'married' with those combinations.
I am not sure how your solution in its current form provides a solution to that question.