Preprocessor directives in AL
AL preprocessor directives cover conditional compilation (#if, #else, #elif, #endif, #define, #undef), regions (#region, #endregion) and pragmas (#pragma warning, #pragma implicitwith). It answers questions about compiling code conditionally, suppressing warnings and organizing code in large files.
Path: Development > The AL programming language > Preprocessor directives in AL · tier official · system development · narrative reviewed (checked by Opus)
Overview
Preprocessor directives in AL give the compiler instructions before code is built. They let you include or exclude code based on defined symbols, control compiler warnings, and group code into collapsible sections.
The overview page is the best starting point. It introduces conditional directives, symbol definition, logical operators (and, or, not), regions and pragmas, and mentions global symbols in app.json. Two pages go deeper: one on pragma directives (#pragma warning and #pragma implicitwith) and one on region directives for organizing code.
Key points
- Conditional directives #if, #else, #elif and #endif compile code depending on defined symbols.
- #define and #undef define and undefine symbols; logical operators and, or, not combine them in conditions.
- Global symbols can be set in app.json.
- #region and #endregion mark collapsible blocks of code and can be nested.
- #pragma warning disables or restores compiler warnings.
- #pragma implicitwith controls how implicit with statements are handled.
- Pragma actions include disable, restore and enable.
Learn pages
- AL Preprocessor Directives Overview: Learn how to use conditional, region, and pragma preprocessor directives and define symbols in AL for Microsoft Dynamics 365 Business Central extensions.
- Pragma Directives in AL Overview: Explore the pragma directives and supported actions that control compiler warnings and implicit record contexts in Microsoft Dynamics 365 Business Central.
- Region Directives for Organizing AL Code: Learn how to use the region directive in AL to organize code into collapsible blocks and improve readability in Microsoft Dynamics 365 Business Central.
Source: Microsoft Learn (CC BY 4.0). Descriptions are Learn’s own.