# Unused Initialized Variables

##### Tags:

- C/AL

##### Categories:

- Best Practice

The value assigned to a variable must be used. Else the variable is not necessary.

Bad code

    PROCEDURE AddEntities@1(FilterStr@1000 : Text[250]);
    VAR
        Vendor@1001 : Record 23;
        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

    PROCEDURE AddEntities@1(FilterStr@1000 : Text[250]);
    VAR
        Vendor@1001 : Record 23;
    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;

Last modified February 24, 2022: Added tags & categories + cleanup (5ee04366) by waldo1001