{"title":"CodeCop Warning AA0181","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/analyzers/codecop-aa0181/","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-aa0181, 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-aa0181","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":"Avoid getting the dataset when an enumeration is not used, which will decrease performance.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"CodeCop Warning AA0181","slug":"codecop-warning-aa0181","at":0,"chars":1021},{"level":2,"title":"Description","slug":"description","at":113,"chars":107},{"level":2,"title":"Reason for the rule","slug":"reason-for-the-rule","at":220,"chars":192},{"level":2,"title":"Bad code example","slug":"bad-code-example","at":412,"chars":236},{"level":2,"title":"Good code example","slug":"good-code-example","at":648,"chars":236},{"level":2,"title":"Related information","slug":"related-information","at":884,"chars":137}],"text":"# CodeCop Warning AA0181\nThe FindSet() or Find() methods must be used only in connection with the Next() method.\n## Description\nAvoid getting the dataset when an enumeration is not used, which will decrease performance.\n## Reason for the rule\nIf you use `FindSet()` or `Find()` you must have a `Next()` method. Otherwise, you are wasting CPU and bandwidth since multiple records are loaded but you only use one.\n## Bad code example\n```al\ncodeunit 1 MyCodeunit\n{\n   var\n      customer: Record Customer;\n\n   procedure Foo()\n   begin\n      if customer.FindFirst() then\n         repeat\n         ...\n         until customer.Next() = 0;\n      end;\n}\n```\n## Good code example\n```al\ncodeunit 1 MyCodeunit\n{\n   var\n      customer : Record Customer;\n\n   procedure Foo()\n   begin\n      if customer.FindSet() then\n         repeat\n         ...\n         until customer.Next() = 0;\n      end;\n}\n```\n## Related information\nCodeCop Analyzer<codecop>\nGet Started with AL<../devenv-get-started>\nDeveloping Extensions<../devenv-dev-overview>"}