Modify all records in a table code

Hi Team,

I have a small challenge in my programming. Am trying to replace account no. field in a Gen. Journal Line table and I have written the following codeunit:


count := 0;

IF genjnal.FIND(’+’) THEN

REPEAT

IF genjnal.“Fixed Asset Sequence No.” < 10 THEN

genjnal.“Account No.” := genjnal.“Fixed Asset Code” + ‘000’ + FORMAT(genjnal.“Fixed Asset Sequence No.”);

IF genjnal.“Fixed Asset Sequence No.” > 10 THEN

BEGIN

IF genjnal.“Fixed Asset Sequence No.” < 100 THEN

genjnal.“Account No.” := genjnal.“Fixed Asset Code” + ‘00’ + FORMAT(genjnal.“Fixed Asset Sequence No.”);

IF genjnal.“Fixed Asset Sequence No.” > 100 THEN

genjnal.“Account No.” := genjnal.“Fixed Asset Code” + ‘0’ + FORMAT(genjnal.“Fixed Asset Sequence No.”);

END;

genjnal.MODIFY;

count := count + 1;

UNTIL genjnal.NEXT = 0;


However, when I run it, the changes are not effected. What could I be going wrong?

Sinkala

IF genjnal.FIND(’+’) THEN

This is to find the last record…

Try with

IF genjnal.FIND(’-’) THEN

which is for first record

or

IF genjnal.FINDSET THEN

which is for set of records

I believe one record will change by above code and that is the last record in the table.As suggested by other person , use

genjnal.FIND(‘-’) or genjnal.FINDSET

Hi Dhan & Mohana,

Thanks, it worked. Thanks a lot team.

Sinkala

Depending on the G/L-Account setup, Instead of

genjnal.“Account No.” := genjnal.“Fixed Asset Code” + ‘0’ + FORMAT(genjnal.“Fixed Asset Sequence No.”);

I would rather validate the “Account No.”:

genjnal.VALIDATE(“Account No.”, genjnal.“Fixed Asset Code” + ‘0’ + FORMAT(genjnal.“Fixed Asset Sequence No.”));

However, the mentioned solution is correct.