{"title":"CodeCop Warning AA0205","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/analyzers/codecop-aa0205/","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-aa0205, 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-aa0205","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":"Always initialize a variable before usage.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"CodeCop Warning AA0205","slug":"codecop-warning-aa0205","at":0,"chars":1756},{"level":2,"title":"Description","slug":"description","at":69,"chars":114},{"level":2,"title":"Reason for the rule","slug":"reason-for-the-rule","at":183,"chars":175},{"level":2,"title":"Bad code example 1","slug":"bad-code-example-1","at":358,"chars":185},{"level":2,"title":"Good code example 1","slug":"good-code-example-1","at":543,"chars":190},{"level":2,"title":"Bad code example 2","slug":"bad-code-example-2","at":733,"chars":143},{"level":2,"title":"Good code example 2","slug":"good-code-example-2","at":876,"chars":158},{"level":2,"title":"Remarks","slug":"remarks","at":1034,"chars":585},{"level":2,"title":"Related information","slug":"related-information","at":1619,"chars":137}],"text":"# CodeCop Warning AA0205\nVariables must be initialized before usage.\n## Description\nAlways initialize a variable before usage. This can improve readability and make debugging easier.\n## Reason for the rule\nUsing uninitialized variables may lead to strange behavior, the code may become harder to debug and in some cases readability of the code can decrease.\n## Bad code example 1\n```al\nvar\n    x: Integer;\n    z: Integer;\n\nprocedure Proc1()\nvar\nbegin\n    Proc2(z);\n    x := z;\nend;\n\nprocedure Proc2(z: Integer)\nvar\nbegin\n    z := 10;\nend;\n```\n## Good code example 1\n```al\nvar\n    x: Integer;\n    z: Integer;\n\nprocedure Proc1()\nvar\nbegin\n    Proc2(z);\n    x := z;\nend;\n\nprocedure Proc2(var z: Integer)\nvar\nbegin\n    z := 10;\nend;\n```\n## Bad code example 2\n```al\n procedure TestFunc()\n    var\n        a: Integer;\n        b:​ Integer;\n    begin\n​        b := a + 1;\n    end;\n```\n## Good code example 2\n```al\nprocedure TestFunc()\n    var\n        a: Integer;\n        b: Integer;\n    begin\n        a := 0;\n\n        b := a + 1;\n    end;\n```\n## Remarks\nVariables of the following types are analyzed: Integer, BigInteger, Boolean, Byte, Char, Code, Date, DateTime, Decimal, List, Record, and Time.\nSome variables need special initialization, for example, List is initialized using `.Add()`, Record is initialized via `.Init()`, `.Clear()`, or assignment. Local record variables and arrays are ignored. Global record variables can be initialized in other method.\nInitialization is possible using evaluate, for, foreach statements. If a variable is passed in a method through var, the rule considers it initialized in the method.\n## Related information\nCodeCop Analyzer<codecop>\nGet Started with AL<../devenv-get-started>\nDeveloping Extensions<../devenv-dev-overview>"}