{"title":"CodeCop Warning AA0206","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/analyzers/codecop-aa0206/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/analyzers/codecop-aa0206, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/analyzers/codecop-aa0206","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"The value assigned to a variable must be used, otherwise the variable is not necessary.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"CodeCop Warning AA0206","slug":"codecop-warning-aa0206","at":0,"chars":1261},{"level":2,"title":"Description","slug":"description","at":72,"chars":103},{"level":2,"title":"Reason for the rule","slug":"reason-for-the-rule","at":175,"chars":111},{"level":2,"title":"Bad code example","slug":"bad-code-example","at":286,"chars":382},{"level":2,"title":"Good code example","slug":"good-code-example","at":668,"chars":341},{"level":2,"title":"Good and bad practices for fixing the rule","slug":"good-and-bad-practices-for-fixing-the-rule","at":1009,"chars":115},{"level":2,"title":"Related information","slug":"related-information","at":1124,"chars":137}],"text":"# CodeCop Warning AA0206\nThe value assigned to a variable must be used.\n## Description\nThe value assigned to a variable must be used, otherwise the variable is not necessary.\n## Reason for the rule\nUnused variable can be confusing for the reader and can cost performance to the system.\n## Bad code example\n```al\nprocedure AddEntities@1(FilterStr@1000 : Text[250])\nvar\n    Vendor@1001 : Record Vendor;\n    Count@1002 : Integer;\nbegin\n    Count := 0;\n    Vendor.SETFILTER(\"No.\",FilterStr);\n    if Vendor.FINDSET() then\n    repeat\n        \"User ID\" := USERID();\n        \"Vendor No.\" := Vendor.\"No.\";\n        If Vendor.Insert() THEN;\n    until Vendor.NEXT() = 0;\nend;\n```\n## Good code example\n```al\nprocedure AddEntities@1(FilterStr@1000 : Text[250])\nvar\n    Vendor@1001 : Record Vendor;\nbegin\n    Vendor.SETFILTER(\"No.\",FilterStr);\n    if Vendor.FINDSET() then\n    repeat\n        \"User ID\" := USERID();\n        \"Vendor No.\" := Vendor.\"No.\";\n        if Vendor.INSERT() then;\n    until Vendor.NEXT() = 0;\nend;\n```\n## Good and bad practices for fixing the rule\nRemove the variable or make use of it if not using it was a mistake.\n## Related information\nCodeCop Analyzer<codecop>\nGet Started with AL<../devenv-get-started>\nDeveloping Extensions<../devenv-dev-overview>"}