{"title":"Working with AL methods","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/devenv-al-methods/","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-al-methods, 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-al-methods","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":"Methods also known as procedures are a fundamental programming element in AL for Business Central.","date":"2024-04-17","meta":{"topic":"concept-article"},"outline":[{"level":1,"title":"Working with AL methods","slug":"working-with-al-methods","at":0,"chars":9274},{"level":2,"title":"Declaring methods","slug":"declaring-methods","at":1813,"chars":3068},{"level":3,"title":"Snippet support","slug":"snippet-support","at":2035,"chars":200},{"level":3,"title":"Attributes (optional)","slug":"attributes-optional","at":2235,"chars":549},{"level":3,"title":"Local and global scope","slug":"local-and-global-scope","at":2784,"chars":617},{"level":3,"title":"Parameters (optional)","slug":"parameters-optional","at":3401,"chars":905},{"level":3,"title":"Return values (optional)","slug":"return-values-optional","at":4306,"chars":575},{"level":2,"title":"Calling methods","slug":"calling-methods","at":4881,"chars":2217},{"level":3,"title":" Parameters","slug":"parameters","at":5975,"chars":1123},{"level":2,"title":"Example 1","slug":"example-1","at":7098,"chars":480},{"level":2,"title":"Example 2","slug":"example-2","at":7578,"chars":278},{"level":2,"title":"Example 3","slug":"example-3","at":7856,"chars":501},{"level":2,"title":"Example 4","slug":"example-4","at":8357,"chars":113},{"level":2,"title":"Example 5","slug":"example-5","at":8470,"chars":193},{"level":2,"title":"Example 6","slug":"example-6","at":8663,"chars":457},{"level":2,"title":"Related information","slug":"related-information","at":9120,"chars":154}],"text":"# Working with AL methods\n> NOTE\n> We're working to improve the onboarding experience for AL developers. If you have feedback about this article, use the Feedback section at the bottom of the article to tell us what you'd like to see.\n> We also welcome contributions to our documentation. Learn more about contributing in Contribute to the help<../help/contributor-guide#contributing>.\nLike other languages, AL methods are a fundamental programming element. A method, also known as a procedure, is a named group of statements that perform an operation or task. Depending on the scope, methods can be run, or called, from the same object in which they are declared or from other parts of the application. The method can take parameters, which are variables or expressions that are sent to the method when it's called. The method can also return a value to the calling code.\nThere are two types of methods: system methods (built-in) and user-defined (custom) methods.\n Built-in methods are part of the platform. Built-in methods can be used for different purposes, such as string handling, text formatting, database handling, and so on. Learn more about the available built-in methods in AL method reference<methods-auto/library> and devenv-essential-al-methods. Learn more about method scope in attributes/devenv-scope-attribute.\n Custom methods are specialized methods for your application to bind the objects, such as tables, pages, and codeunits, together to form a unified whole. You can create special methods for use anywhere in the database.\n> TIP\n> If you already know the name of, for example, a data type, method, property, or trigger, use the Filter by title field in the upper left corner, above the table of contents to find the topic faster. Otherwise, you can scan the table of contents to find it.\n## Declaring methods\nThe method declaration defines the method and has the following syntax:\n```al\n[Attributes(arguments list)]\nlocal procedure <method_name>(parameter list) <return_value_name> : <data_type>[<length>]\n```\n### Snippet support\nTyping the shortcut tprocedure will create the basic structure for a method when using the AL Language extension for Microsoft Dynamics 365 Business Central in Visual Studio Code.\n### Attributes (optional)\nAn attribute is a modifier on a method declaration that specifies information that controls the method's use and behavior. Adding an attribute on a method declaration is also known as decorating a method. For example, decorating a method with the Integration attribute sets the method to be an event publisher. An attribute can have one or more arguments that set properties for the method instance.\nAttributes are placed before the method. Learn more about the available attributes in attributes/devenv-method-attributes.\n### Local and global scope\nA method can be a local method or global method. A local method can only be accessed or called from inside the object in which it is declared. A global method can be called from inside the object in which it is declared and from other objects. To declare a method as a local method, you must use the local keyword in the method declaration. If you don't use the local keyword, the method is declared as a global method.\nTo declare a local method, start the declaration with local:\n```al\nlocal procedure Mymethod()\n```\nTo declare a global method, omit local:\n```al\n procedure Mymethod()\n```\n### Parameters (optional)\nA parameter is one or more variables or expressions that are sent to the method through the method call. The parameter provides information to the method, and the method can modify that information. In the method declaration, you place the parameters in parentheses `()`. If there's more than one parameter, the parameters are separated by semicolons. A parameter is defined by a data type. Some data types, such as Record, require an additional subtype.\nFor example, the following method declaration includes two parameters: MyCustomerand MyDimension:\n```al\n procedure MyMethod(MyCustomer : Record Customer; var MyDimension : List of [Boolean])\n```\nThe example also illustrates how parameters can be passed by value or passed by reference. In the example, the MyCustomer parameter is passed by value, and the MyDimension parameter is passed by reference. See #Parameters below.\n### Return values (optional)\nA method can return data that can be then coded against. A return value is defined by a name (optional), data type, and optional length depending on the data type.\nFor example, if the return value is a Text data type, the text might have a length of 50, which is specified with a length parameter right after the data type, in the example `[50]`:\n```al\n    procedure MyMethod() ReturnValue: Text[50]\n        var result : Text[50];\n    begin\n        // do something important where result is calculated\n        ReturnValue := result;\n    end;\n```\n## Calling methods\nYou can run, or call, a built-in or a custom method by using its name in a method call statement. When a method is called the current application sequence is suspended and the code on the method is run. When the method code is completed, the application code sequence returns to where the method was called from. How the method is called determines what happens when it returns.\nA method can be used as part of an expression. For example, the following code uses a\nmethod named CalculatePrice as an expression:\n```al\nTotalCost := Quantity * CalculatePrice;\n```\nIn this case, the CalculatePrice method must return a value that's used in evaluating the expression. This return value is then multiplied by the Quantity variable and that result is assigned to the TotalCost variable.\nA method can also be run by using a method call statement. This statement only calls the method and doesn't return any value. The following is an example of calling a method named MyRunMethod:\n```al\nif Quantity > 5 then\nMyRunMethod;\n```\nThe MyRunMethod returns no data back to the calling code.\n###  Parameters\nThis section describes how to pass parameters to a method. Parameters are used to pass data into a method when it's called. The parameters are defined in the method declaration and can be mandatory or optional. First, there are a few general rules that apply to parameters:\nIn a method call, the parameters are separated by commas, and the optional parameters may be omitted starting from the right. For example, this means that if a method has three optional parameters, then you can't omit the second parameter without omitting the third parameter.\nWhen passing parameters there are two options; you can be passing by value, which is the default behavior, or passing by reference, in which case you must specify the var keyword.\n If a parameter is passed by value, then a copy of the variable is passed to the method. Any changes that the method makes to the value of the variable are local changes that affect only the copy, not the variable itself.\n If a parameter is passed by reference, then a reference to the variable is passed to the method. The method can change the value of the variable itself.\n## Example 1\nThe following shows the syntax for a method. The first example shows a method with two mandatory parameters.\n```al\nmethod(Parameter1, Parameter2)\n```\nSome built-in methods have optional parameters, the syntax is shown below. The optional parameters may be omitted starting from the right.\n```al\nmethod([Optional1] [, Optional2] [, Optional3])\n```\nThe method that uses the syntax above can be called by using the following code.\n```al\nmethod(Optional1, Optional2)\n```\n## Example 2\nAbs is an example of an AL method that has a fixed number of parameters (1).\n```al\nvar\n    Value: Integer;\n    PositiveValue: Integer;\nbegin\n    Value := -1033; //A negative integer value\n    PositiveValue := Abs(Value); //Calculate the positive value 1033\nend\n```\n## Example 3\nThe method DMY2Date is an example of a method that can be called by using a variable number of parameters.\n```al\nvar\n    NewDate: Date;\nbegin\n    NewDate := DMY2Date(5, 11, 1992); // Returns the date November 5, 1992\nend\n```\nDepending on the use of the DMY2Date method, one, two, or three parameters can be passed to the method because the second and third parameters are optional. When the second and third parameters aren't used, values from the system date are used as default values.\n## Example 4\nYou can assign the return value of a method to a variable.\n```al\nReturnVal := MyMethod(Param1);\n```\n## Example 5\nIn this example, MyMethod returns a Boolean value. You can use the return value in a conditional statement.\n```al\nif (MyMethod(Param1)) then\n  <Statement1>\nelse\n  <Statement2>\n```\n## Example 6\nThis example also illustrates how parameters can be passed by value or passed by reference. The following method declaration includes two parameters: MyCustomer and MyDimension:\n```al\nprocedure MyMethod(MyCustomer : Record Customer; var MyDimension : List of [Boolean])\n```\nThe MyCustomer parameter is passed by value, which is a copy of the variable, and the MyDimension parameter is passed by reference, which is a reference to the variable.\n## Related information\nDevelopment overview<devenv-dev-overview>\nAL methods<methods-auto/library>\ndevenv-al-simple-statements\ndevenv-al-control-statements"}