Help With Code

Hey! I’m currently a newbie to NATURAL. I think it is a great computer language. I’m working on a program and I came across a problem. This is what I’m trying to do:

If the previous payee isn is the same as the current payee isn then add the previous tranaction amount and current transaction amount. Store that amount in total isn transaction amount. Move that amount to CHK.TRAN-AMT.

Here is what I came up with:

MOVE CHK.PAYEE-ISN TO #CURR-PAYEE-ISN
MOVE CHK.TRANS-AMT TO #CURR-TRANS-AMT
COMPUTE #PREV-PAYEE-ISN = #CURR-PAYEE-ISN - 1
COMPUTE #PREV-TRANS-AMT = #CURR-TRANS-AMT - 1
IF #CURR-PAYEE-ISN = #PREV-PAYEE-ISN
ADD #PREV-TRANS-AMT #CURR-TRANS-AMT GIVING #TOTAL-ISN-TRANS-AMT
MOVE #TOTAL-ISN-TRANS-AMT TO CHK.TRANS-AMT
END-IF

However, this didn’t work. When I ran my program, the #CURR-PAYEE-ISN = 4473 and #PREV-PAYEE-ISN = 4472. That is not right. #PREV-PAYEE-ISN is suppose to be the isn before #CURR-PAYEE-ISN which is 30897. Some how I nedd to read/get the isn before #CURR-PAYEE-ISN. If anyone can shed some light, I would greatly appreciate. THANK YOU IN ADVANCE!

Lost,
NatBeginner

Hi NatBeginner,

Can you explain what you want to do and not what you did? Is this a database read or something else? What is CHK.TRAN-AMT? When it is read from the database, the “Move that amount to CHK.TRAN-AMT” is nonsense unless this value is stored back into the database (which in the described case itself is nonsense).
Are the records grouped/sorted and when how are they sorted?

If we should shed some light on you, don’t hide behind a rock!

I guess your CHK.PAYEE-ISN is the ISN of a database record. For Natural this is just a number eg 4473. If you subtract 1 from that number the value is of cause 4472 and NEVER equal to the original value.

x == x - 1 --> never true

Thus you should think about what you really want to do and what values you want to compare (but hard for us to guess).

If you run through a read loop by a descriptor value, the ISN of the record read before is normally not ISN -1. Means you have to save the previous ISN. But even if you compare these two ISNs it will most time fail unless you use a multiple-field as descriptor.

But maybe you don’t want to compare the ISNs but values of the corresponding records??
Or …

Thanks for the comments and replies. They are very helpful. Again thanks!

NatBeginner

What has been helpful with the answers? I’m feeling fooled!