Pragma Warning Directive

APPLIES TO: Business Central 2020 release wave 2 and later

The #pragma warning instruction can enable or disable certain warnings. This can be used as a solution to avoid getting warnings on, for example, string length on fields that you can't change. With the #pragma warning disable statement you disable the emit of the warning for a specific location in code, and with #pragma warning restore you restore the warning back to its original state. If you don't restore, the disable instruction is valid for the rest of the file.


It's important to be aware that most warnings are there for a reason, and suppressing them could lead to sudden impact if warnings are changed to errors, such as obsoletes.


#pragma warning disable warning-list  
#pragma warning restore warning-list  


warning-list A comma-separated list of warning numbers.

When no warning numbers are specified, disable disables all warnings, and restore enables all warnings.


To find warning numbers in AL, build your AL project in Visual Studio Code and then look for the warning numbers in the Output window. For more information, see Using the Code Analysis Tool.


The following example illustrates how the specific rule AL0468 is temporarily turned off for a specific field definition.

table 50110 MyTable
        #pragma warning disable AL0468
        field(1; TableWithLongIdentifierThatExceedsOurMax; Integer) { }
        #pragma warning restore

See Also

Development in AL
AL Development Environment
Pragma Directive in AL
Conditional directives
Deprecating Explicit and Implicit With Statements