The value assigned to a variable must be used.
Title The value assigned to a variable must be used.
Description The value assigned to a variable must be used. Else the variable is not necessary.
Reason for the rule Unused variable can be confusing for the reader and can cost performance to the system.
Bad code sample
procedure AddEntities@1(FilterStr@1000 : Text[250])
var
Vendor@1001 : Record Vendor;
Count@1002 : Integer;
begin
Count := 0;
Vendor.SETFILTER("No.",FilterStr);
if Vendor.FINDSET() then
repeat
"User ID" := USERID();
"Vendor No." := Vendor."No.";
if INSERT() then
Count += 1;
until Vendor.NEXT() = 0;
end;
Good code sample
procedure AddEntities@1(FilterStr@1000 : Text[250])
var
Vendor@1001 : Record Vendor;
begin
Vendor.SETFILTER("No.",FilterStr);
if Vendor.FINDSET() then
repeat
"User ID" := USERID();
"Vendor No." := Vendor."No.";
if INSERT() then;
until Vendor.NEXT() = 0;
end;
Good and bad practices for fixing the rule Remove the variable or make use of it if not using it was a mistake.
Remarks
As long as its an info/warning message and not an error, I'm OK with this.
Because of the debugger limitations, I often have variables that exist only for that.
We currently ship every rule in CodeCop as info or warning.
How should a List be assigned before use?
The following sample shows a warning due to using Contains in the loop, I do not see a good way around it. Suggestions? (My actual code is different, so the sample was just to make it easy to understand)
procedure DoSomething()
var
GLEntry: Record "G/L Entry";
GLAccountNoList: List of [Code[20]];
begin
// Set some filters on GLEntry
if GLEntry.FindSet() then
repeat
DoSomethingWithEntry(GLEntry);
if not GLAccountNoList.Contains(GLEntry."G/L Account No.") then
GLAccountNoList.Add(GLEntry."G/L Account No.");
until GLEntry.Next() = 0;
DoSomethingToEachGLAccount(GLAccountNoList);
end;
procedure DoSomethingWithEntry(GLEntry: Record "G/L Entry")
begin
end;
procedure DoSomethingToEachGLAccount(GLAccountNoList: List of [Code[20]];)
begin
end;

@AskeHolst I think you're looking for issue #5614
Thank you @mjmatthiesen #5614 was the right one. And there was even a solution there: "List is initialized via .Add()" so problem solved.
So isn't this issue done, and can be closed?