As for how to make this compute routine work, can you provide the code to modify?
We cannot provide you any such code as we do not know whether or not your compute routine is working. You have provided us with no evidence about what it is calculating, and it would be a waste of our time to continue.
You need to either (1) add an XDUMP after the compute routine is done to verify the results, or (2) proceed on the assumption that it is working and write the PRINT and TOTAL routines. Please stop asking us to tell you how to modify the compute routine because we don't know if it needs modification at this point. The only thing known for sure is that you had the increment of R6 in the wrong place and hence the first record would not have any calculations done.