Calculation more Request Order

What do you mean by repeat?

When you set a filter on Requisition No. in the Requisition table, then calling CALCSUMS will calculate the total for all records in the Requisition table. That’s the beauty in CALCSUMS. It’s using the sum index field, so you don’t need a REPEAT-UNTIL to get the sum of Amount’s. The line “IF Requisition.ISEMPTY THEN EXIT(0);” doesn’t really have to be there for the function to work, leaving it out would give you the same. It’s just there for a tiny bit of performance. ISEMPTY is “cheap” whereas CALCSUMS not so much.

Right now, if the above code doesn’t work, then it is either because your definition of the sum index field does not match the key used. Or your data are not as you think they are. As I have pointed out earlier in this thread, then if the table data examples where your full data set, then it would only return the value for one record.

Also please understand the difference between := and +=

VarNo := 1; Means set the variable to 1. The existing value is overwritten.

VarNo += 1; Means add 1 to the existing value of the variable. You use it when you want to add to the value.

So in your case, if something had previously been added to the PRAmount variable, then your message would not show the amount for the requisition no.

Thanks Erik. It’s work after I change call procedure.

Happy to hear that Dinh, your last reply was not that clear about it. And just in time, I was almost about to give up! [emoticon:8fbf4ba171e24a4584fd0845f27df978][emoticon:4191f5ee34e248a29fa0dbe8d975f74a]

I hope you learned something from it.

Thank so much Erik.

I have edit call procedure and work.

  PRAmount+=GetRequisitionAmount(PurchLine."Requisition No");
UNTIL PurchLine.NEXT=0

Very good, but while we are add it then drop the BEGIN-END:

    PRAmount+=GetRequisitionAmount(PurchLine."Requisition No");
  UNTIL PurchLine.NEXT = 0;

Also if PurchLine is a local var and the first time you use it, then don’t need the RESET.

Thanks so much Erik.

One very important piece of advice.

NEVER prefix variables with their type. Eg change
recRequisition → RequisitionHeader.
recPurchLine → PurchLine

It will be extremely difficult for you to write stable, readable and debugged code this way, and absolutely IMPOSSIBLE for another person later to debug.

Your first priority to get this code to work is to define first exactly what you want, Second is to start again and use correct notation and naming conventions.