Preprocessor Directives in AL
In AL, like in other programming languages, preprocessor directives can be used to make code conditional, to suppress warnings, or to enable expand and collapse in code. Preprocessor directives can be divided into the following groups. For more information about each type, use the links provided below.
Any code can be made conditional, including table fields, and checked using a conditional directive. To check code using a conditional directive, you must define a symbol to check. A symbol returns a boolean value;
false. Symbols can be defined at the beginning of a source file and the scope of the specific symbol is the file that it is defined within. You can also define symbols in the
app.json file, and then the scope is global for the extension.
Built-in symbols are currently not supported in AL. Symbols must be defined in a specific file or in the
The following conditional preprocessor directives are supported in AL.
|Conditional preprocessor directive||Description|
|#if||Specifies the beginning of a conditional clause. The
|#else||Specifies a compound conditional clause. If none of the preceding clauses evaluates to
|#endif||Specifies the end of a conditional clause that begins with
|#define||Defines a symbol that can be used to specify conditions for a compilation. For example,
|#undef||Undefines a symbol.|
Symbols can be defined globally in the
app.json file. A symbol can also be defined using the
#define directive in code, but if symbols are defined in the
app.json file, they can be used globally. The following example defines
DEBUG as a global symbol. This can then be used from code as illustrated in the Conditional code example below. A symbol has a boolean value, that means it evaluates to
"preprocessorSymbols": [ "DEBUG" ]
For more information, see JSON Files.
#if DEBUG trigger OnOpenPage() begin Message('Only in debug versions'); end; #endif