{"title":"Deprecating explicit and implicit with statements","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/devenv-deprecating-with-statements-overview/","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/devenv-deprecating-with-statements-overview, 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/devenv-deprecating-with-statements-overview","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":"Rationale and description of why explicit and implicit with statements are deprecated in AL.","date":"2025-05-21","meta":{"topic":"overview"},"outline":[{"level":1,"title":"Deprecating explicit and implicit with statements","slug":"deprecating-explicit-and-implicit-with-statements","at":0,"chars":9935},{"level":2,"title":"The explicit with statement","slug":"the-explicit-with-statement","at":981,"chars":1430},{"level":2,"title":"Symbol lookup","slug":"symbol-lookup","at":2411,"chars":1614},{"level":2,"title":"The implicit with statement","slug":"the-implicit-with-statement","at":4025,"chars":1270},{"level":3,"title":"Codeunits","slug":"codeunits","at":4204,"chars":1091},{"level":2,"title":"Pages","slug":"pages","at":5295,"chars":890},{"level":2,"title":"Warnings and using pragma","slug":"warnings-and-using-pragma","at":6185,"chars":2386},{"level":3,"title":"AL0606 - use of explicit with","slug":"al0606---use-of-explicit-with","at":6575,"chars":246},{"level":3,"title":"AL0604 - use of implicit with","slug":"al0604---use-of-implicit-with","at":6821,"chars":1750},{"level":2,"title":"Suppressing warnings","slug":"suppressing-warnings","at":8571,"chars":875},{"level":3,"title":"suppressWarnings setting","slug":"suppresswarnings-setting","at":8753,"chars":284},{"level":3,"title":"Pragmas","slug":"pragmas","at":9037,"chars":409},{"level":2,"title":"Related information","slug":"related-information","at":9446,"chars":489}],"text":"# Deprecating explicit and implicit with statements\n> APPLIES TO: Business Central 2020 release wave 2 and later\n> NOTE\n> With Business Central 2022 release wave 2, the AL:Go! template for creating new AL projects in Visual Studio Code, now enables explicit with statements by default, by adding the NoImplicitWith option to the features property in the generated app.json file.\nThe extensibility model and the AL programming language are successors to the C/AL language. And the with statement has up until now been supported in AL. While using the with statement might make code harder to read, it can also prevent code in Business Central online from being upgraded without changes to the code or even worse - upgraded, but with changed behavior. We distinguish between two types of with statements; the explicit type of with using the keyword, and the implicit with which isn't expressed directly in code. The next sections describe the explicit and implicit types one by one.\n## The explicit with statement\nIn Business Central online, your code is recompiled when the platform and application versions are upgraded. The recompilation ensures that it's working and the recompile regenerates the runtime artifacts to match the new platform. Breaking changes without due warning aren't allowed, but the use of the with statement makes it impossible, as Microsoft, to make even additive changes in a nonbreaking way. This problem isn't alone isolated to changes made by Microsoft; any additive change has the potential to break a with statement in consuming code.\nThe following example illustrates code written using the with statement; referred to in this context as the explicit with.\n```al\ncodeunit 50140 MyCodeunit\n{\n    procedure DoStuff()\n    var\n        Customer: Record Customer;\n    begin\n        with Customer do begin\n            // Do some work on the Customer record.\n            Name := 'Foo';\n\n            if IsDirty() then\n                Modify();\n        end;\n    end;\n\n    local procedure IsDirty(): Boolean\n    begin\n        exit(false);\n    end;\n}\n```\nThe `DoStuff()` procedure processes work on the Customer record and calls a local procedure `IsDirty()` to check whether to update the record or not. Looking at the code above it looks like it does nothing since `IsDirty()` returns false - assuming that the `IsDirty()` call (line 11) is in fact calling the local `IsDirty()` procedure.\n## Symbol lookup\nIf we take another look at the above code sample again, what would happen to that code if IsDirty was added to the base application between two releases? To understand that, we need to take a look at how compilers turn syntax into symbols. When the AL compiler meets the IsDirty call it must bind the syntax name to a procedure symbol.\nWhen the AL compiler searches for the symbol `IsDirty()` in the sample above it searches in following order:\n1. Customer table\n  User-defined members on the Customer table and Customer table extensions\n  Platform-defined members, for example, `FindFirst()` or `Modify()`\n2. MyCodeunit codeunit\n  User-defined members, for example, `IsDirty()`\n  Platform-defined members\n3. Globally defined members\nThe first time the search for IsDirty finds the name IsDirty, it doesn't continue to the next top-level group. That means that if a procedure named IsDirty is introduced in the Customer table (platform or application) that procedure is found instead of the procedure in MyCodeunit.\nThe solution for the explicit with is to stop using it. Using the with statement can make your code vulnerable to upstream changes. The example below illustrates how to rewrite the sample in #the-explicit-with-statement:\n```al\n// Safe version\ncodeunit 50140 MyCodeunit\n{\n    procedure DoStuff()\n    var\n        Customer: Record Customer;\n    begin\n        // Do some work on the Customer record.\n        Customer.Name := 'Foo';\n\n        if IsDirty() then\n            Customer.Modify();\n    end;\n\n    local procedure IsDirty(): Boolean\n    begin\n        exit(false);\n    end;\n}\n```\n## The implicit with statement\nThe implicit with is injected automatically by the compiler in certain situations. The next sections describe, how it works on codeunits and pages.\n### Codeunits\nWhen a codeunit has the TableNo property set, there's an implicit with around the code inside the OnRun trigger. The implicit with is indicated with the comments in the code example below.\n```al\ncodeunit 50140 MyCodeunit\n{\n    TableNo = Customer;\n\n    trigger OnRun()\n    begin\n        // with Rec do begin\n        SetRange(\"No.\", '10000', '20000');\n        if Find() then\n            repeat\n            until Next() = 0;\n\n        if IsDirty() then\n            Error('Something is not clean');\n        // end;\n    end;\n\n    local procedure IsDirty(): Boolean\n    begin\n        exit(false);\n    end;\n}\n```\nSimilar to the #the-explicit-with-statement, the code looks like it calls the local IsDirty method, but depending on the Customer table, extensions to the Customer table, and built-in methods that might not be the case. If any of these implement an IsDirty method with an identical signature that returns true, then the example above fails with an error. If an IsDirty method with a different signature is implemented, then this code doesn't compile and fails to upgrade.\n## Pages\nPages on tables have the same type of implicit with, but around the entire object. Everywhere inside the page object the fields and methods from the source tables are directly available without any prefix.\n```al\npage 50143 ImplicitWith\n{\n    SourceTable = Customer;\n\n    layout\n    {\n        area(Content)\n        {\n            field(\"No.\"; \"No.\") { }\n            field(Name; Name)\n            {\n                trigger OnValidate()\n                begin\n                    Name := 'test';\n                end;\n            }\n        }\n    }\n\n    trigger OnInit()\n    begin\n        if IsDirty() then Insert()\n    end;\n\n    local procedure IsDirty(): Boolean\n    begin\n        exit(Name <> '');\n    end;\n}\n```\nOn pages, it's not only the code in triggers and procedures that is spanned by the implicit with on the source Rec; also the source expressions for the fields are covered.\n## Warnings and using pragma\nFrom Business Central 2020 release wave 2 we begin to warn about the use of explicit and implicit with for extensions that are targeting the cloud. There are two different warnings: AL0604 and AL0606.\n> NOTE\n> The warnings become errors with a future release. We will at the earliest remove with statement support from the Business Central 2021 release wave 2.\n### AL0606 - use of explicit with\nThe warning has a Quick Fix code action that allows you to convert one or more statements inside the with statement to fully qualified statements, which means statements as shown in #the-explicit-with-statement.\n### AL0604 - use of implicit with\nJust qualifying with Rec. won't solve this problem. The `IsDirty()` is still vulnerable to upstream change. We want to remove the implicit with, but also offer an opt-in model to avoid forcing everyone to upgrade their code at once.\nThe solution for that is to introduce pragmas in AL. A pragma is an instruction to the compiler on how it should understand the code. The pragma instructs the compiler not to create an implicit with for the Rec variable.\nThe following shows the syntax for the implicit with pragma. The pragma must be used before the beginning of the codeunit or page. See directives/devenv-directive-pragma and directives/devenv-directive-pragma-implicitwith.\n```al\n#pragma implicitwith disable|restore\n```\nThe fixed example under #pages will then look like this:\n```al\n#pragma implicitwith disable\npage 50143 ImplicitWith\n{\n    SourceTable = Customer;\n\n    layout\n    {\n        area(Content)\n        {\n            field(\"No.\"; Rec.\"No.\") { }\n            field(Name; Rec.Name)\n            {\n                trigger OnValidate()\n                begin\n                    Rec.Name := 'test';\n                end;\n            }\n        }\n    }\n\n    trigger OnInit()\n    begin\n        if IsDirty() then Rec.Insert()\n    end;\n\n    local procedure IsDirty(): Boolean\n    begin\n        exit(Name <> '');\n    end;\n}\n#pragma implicitwith restore\n```\nThe Quick Fix code actions automatically inserts the pragma before and after the fixed object.\n> TIP\n> Remember to Enable Code Actions in the settings for the AL Language extension. See devenv-code-actions.\nIn the app.json file, you can set the NoImplicitWith flag to disable implicit with when you've rewritten all code. See devenv-json-files#appjson-file.\n## Suppressing warnings\nThere are two ways of suppressing warnings to unclutter warnings while working on other issues and then afterwards you can fix the warnings at your own pace.\n### suppressWarnings setting\nWarnings can be suppressed globally in an extension by specifying the suppressWarnings in the app.json file. See AL Language extension configuration<devenv-al-extension-configuration>. The syntax is:\n```json\n\"suppressWarnings\": [ \"AL0606\", \"AL0604\" ]\n```\n### Pragmas\nIt's also possible to use `#pragma` to suppress individual warnings for one or more lines of code. See directives/devenv-directive-pragma-warning.\n```al\n#pragma warning disable AL0606\n    // No AL0606 will be shown for code here.\n    with Customer do begin\n        Name := 'Foo';\n        Insert();\n    end;\n\n#pragma warning restore AL0606\n// Suppression of AL0606 is restored to global state.\n```\n## Related information\nAL development environment<devenv-reference-overview>\nDeveloping extensions in AL<devenv-dev-overview>\ndirectives/devenv-directives-in-al\ndirectives/devenv-directive-pragma\ndirectives/devenv-directive-pragma-implicitwith\ndirectives/devenv-directive-pragma-warning\nBest practices for deprecation of code in the Base App<devenv-deprecation-guidelines>\nMicrosoft timeline for deprecating code in Business Central<devenv-deprecation-timeline>\ndevenv-al-simple-statements"}