Referencing to the row above

Hi everyone, i am novice to Navision. I am working on a report that needs to compare two different rows within the same same table. I want it to compare the amount where document type is finance charge memo and where the next row document type is payment being compared to the amount the payment is being applied and if the payment is less than the finance charge it should take the payment as finance charge. can someone Please help me out.

IF “Document Type”=“Document Type”:: “Finance Charge Memo” THEN BEGIN
Fincharge :=“Remaining Amount”;

IF “Document Type”=“Document Type”::Payment THEN BEGIN
Principal:= “Closed by Amount”;
// ***************************************************************8
IF Amount < Fincharge THEN
Fincharge := Amount;

IF Principal=0 THEN
Fincharge :=-ABS(Amount)
// ***************************************************************8
Fincharge :=ABS(Amount)-ABS(Principal);

Hi Newcommer,

I must admit that I don’t understand exactly what You want to achieve, but I can understand that You want to compare 2 lines in the same table, if certain prerequisites are fullfilled.

As I understand it, You only want this thing to happen, if the finance charge memo is positioned just before the payment, but don’t see You making sure of that in the code.
I can see that You put the value of amount in a variable called FinCharge, if the document type is finance charge memo… So far so good.
But how do You make sure that You haven’t run through some lines of document type = say… invoice, before You get to the payment-line?

Personally I think I would create a function in the report, that calls for a VAR-record-parameter, and call it when I come to a record with document type payment (I take it that it was the payment line that was to be modified)…
In the function, I would define a record-variable, of same type, and in this retrieve the record just before the one sent to the function as parameter.
(Remember to make sure You have the same sorting and filters)