{"title":"Organize AL code with region directives","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/directives/devenv-directive-region/","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/directives/devenv-directive-region, 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/directives/devenv-directive-region","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":"Learn how to use the region directive in AL to organize code into collapsible blocks and improve readability in Microsoft Dynamics 365 Business Central.","date":"2026-10-05","meta":{"topic":"concept-article"},"outline":[{"level":1,"title":"Organize AL code with region directives","slug":"organize-al-code-with-region-directives","at":0,"chars":1393},{"level":2,"title":"Organize code into regions","slug":"organize-code-into-regions","at":103,"chars":402},{"level":2,"title":"Syntax","slug":"syntax","at":505,"chars":68},{"level":2,"title":"Remarks","slug":"remarks","at":573,"chars":247},{"level":2,"title":"Example","slug":"example","at":820,"chars":259},{"level":2,"title":"Related information","slug":"related-information","at":1079,"chars":314}],"text":"# Organize AL code with region directives\n> APPLIES TO: Business Central 2020 release wave 2 and later\n## Organize code into regions\nUse the `#region` directive to mark a block of code that you can expand or collapse. Regions can improve readability in large files and help you focus on the code you're currently editing. The `#endregion` directive specifies the end of a `#region` block.\n> NOTE\n> Add a comment after the `#region` directive to describe the code block, as shown in the following example.\n## Syntax\n```al\n#region [comment]\n    code\n```\n```al\n#endregion\n```\n## Remarks\nA `#region` block must be terminated with a `#endregion` directive.\nA `#region` block can't overlap with an `#if` block. However, a `#region` block can be nested in an `#if` block, and an `#if` block can be nested in a `#region` block.\n## Example\nIn this example, the `#region` directive makes a code block that is up for refactoring collapsible.\n```al\n#region Refactoring candidate\n    procedure CalculateLegacyValue()\n    begin\n        // Refactor this implementation.\n    end;\n#endregion\n```\n## Related information\nDevelopment in AL<../devenv-dev-overview>\nAL development environment<../devenv-reference-overview>\nPragma directive in AL<devenv-directive-pragma>\ndevenv-directives-in-al#conditional-directives\nDeprecating explicit and implicit with statements<../devenv-deprecating-with-statements-overview>"}