{"title":"AL operators","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/devenv-al-operators/","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-operators, 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-operators","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":"Describes the operators you can use in AL for Business Central.","date":"2026-11-11","meta":{"topic":"concept-article"},"outline":[{"level":2,"title":"AL operators and meaning","slug":"al-operators-and-meaning","at":162,"chars":5470},{"level":3,"title":"General operators","slug":"general-operators","at":354,"chars":384},{"level":3,"title":"Arithmetic operators","slug":"arithmetic-operators","at":738,"chars":304},{"level":3,"title":"Comparison operators","slug":"comparison-operators","at":1042,"chars":299},{"level":3,"title":"Logical operators","slug":"logical-operators","at":1341,"chars":206},{"level":3,"title":"Conditional operators","slug":"conditional-operators","at":1547,"chars":276},{"level":3,"title":"Compound operators","slug":"compound-operators","at":1823,"chars":561},{"level":3,"title":"Example 1","slug":"example-1","at":2384,"chars":173},{"level":3,"title":"Example 2","slug":"example-2","at":2557,"chars":187},{"level":3,"title":"Example 3","slug":"example-3","at":2744,"chars":109},{"level":3,"title":"Example 4","slug":"example-4","at":2853,"chars":455},{"level":3,"title":"Result type and implicit conversion","slug":"result-type-and-implicit-conversion","at":3308,"chars":2324},{"level":2,"title":"Operator hierarchy","slug":"operator-hierarchy","at":5632,"chars":586},{"level":3,"title":"Example 1","slug":"example-1-1","at":6086,"chars":65},{"level":3,"title":"Example 2","slug":"example-2-1","at":6151,"chars":67},{"level":2,"title":"Related information","slug":"related-information","at":6218,"chars":152}],"text":"Operators can be used in expressions to combine, investigate, and adjust values and data elements. This article describes the operators that are supported in AL.\n## AL operators and meaning\nThe following table shows the valid operators in AL.\nThese operators are used to perform various operations such as arithmetic, comparison, and logical operations.\n### General operators\nAL general operator|Meaning\n`.`|Fields in records, controls on pages, and reports\n`:=`|Assigns a value to a variable. Assigns the value on the right side of the operator to the variable on the left side.\n`()`|Parentheses\n`[ ]`|Indexing\n`::`|Scope. Returns the IF of an object. Examples: `Report::myReport` or `Query::\"My Query\"`.\n`..`|Range\n`@`|Case-insensitive\n### Arithmetic operators\nArithmetic operators are used to perform arithmetic operations on numeric operands. The result of an arithmetic operation is a numeric value.\nAL arithmetic operator|Meaning\n`+`|Addition\n`-`|Subtraction or negation\n`*`|Multiplication\n`/`|Division\ndiv|Integer division\nmod|Modulus\n### Comparison operators\nComparison operators are used to compare two values. The result of a comparison is a Boolean value, that is, true or false.\nAL comparison operator|Meaning\n`>`|Greater than\n`>=`|Greater than or equal to\n`<`|Less than\n`<=`|Less than or equal to\n`=`|Equal to\n`<>`|Not equal to\n### Logical operators\nThe logical operators are used on Boolean expressions\nAL logical operator|Meaning\nand|Logical conjunction\nor|Logical disjunction\nnot|Logical negation\nxor|Exclusive logical disjunction\n### Conditional operators\nConditional operators can be used to test if a condition is met.\n> APPLIES TO: Business Central 2024 release wave 2 and later.\nAL conditional operator|Meaning\n`? :`|Assign one of two values to a variable, depending on the condition of an expression.\n### Compound operators\nCompound assignment operators perform an arithmetic operation and assign the result to the same variable.\nAL compound assignment operator|Meaning\n`+=`|Addition\n`-=`|Subtraction\n`*=`|Multiplication\n`/=`|Division\nThe `+` and the `-` operators can be used both as unary and binary operators. The not operator can only be used as a unary operator. All the other operators are binary.\nMost of the operators can be used on different data types. The action of these operators may depend on the data type of the expression that they are used on.\n### Example 1\nIn this example, the `+` operator is used as a binary operator.\n```\nnumber + number\n```\nThis returns the sum of the numbers, that is, a result of type number.\n### Example 2\nIn this example, the `+` operator is used as a binary operator.\n```\nstring + string\n```\nThis returns the concatenation of the strings, that is, a result of the type string.\n### Example 3\nIn this example, the `+` operator is used as a unary operator to indicate sign.\n```\n+34545\n```\n### Example 4\n> APPLIES TO: Business Central 2024 release wave 2 and later.\nIn this example, the `? :` operator is used to replace a if-then-else clause.\n```al\ncodeunit 50122 TernaryOperator\n{\n    procedure Example()\n    var\n        myExpression: Boolean;\n        myVar: Text;\n    begin\n\n        if myExpression then\n            myVar := 'True';\n        else\n            myVar := 'False';\n\n        myVar := myExpression ? 'True' : 'False';\n    end;\n}\n```\n### Result type and implicit conversion\nThe data type of a ternary expression (`Condition ? TrueExpression : FalseExpression`) is determined by the true expression, even when the condition is false.\nIf the false expression has a different data type, its value is implicitly converted to the type of the true expression when the false expression is selected. This conversion takes place before the result of the ternary expression is assigned to its destination. Consequently, the type of the destination doesn't affect the type of the ternary expression.\nThe false expression must have a type that can be implicitly converted to the type of the true expression. Otherwise, a compiler error occurs. Even when the types are convertible, a runtime error occurs if the selected value can't be converted.\nFor example:\n```al\nvar\n    Condition: Boolean;\n    CodeValue: Code[20];\n    TextValue: Text[100];\n    Result: Text[250];\nbegin\n    Condition := false;\n    TextValue := 'This value is longer than 20 characters.';\n    Result := Condition ? CodeValue : TextValue;\nend;\n```\nIn this example, the type of the ternary expression is `Code[20]`, because CodeValue is the true expression. If TextValue is selected, its value is converted to `Code[20]` before the result is assigned to Result. A value longer than 20 characters can therefore cause a runtime conversion error even though Result is `Text[250]`.\nThe same behavior applies to other data types. For example:\n```al\nvar\n    UseDefault: Boolean;\n    OriginalQuantity: Decimal;\n    Quantity: Decimal;\nbegin\n    UseDefault := false;\n    OriginalQuantity := 0.25;\n    Quantity := UseDefault ? 1 : OriginalQuantity;\nend;\n```\nBecause `1` is an Integer, the ternary expression has the type Integer. If OriginalQuantity is selected, its value must first be converted to Integer, even though Quantity is a Decimal. In this example, `0.25` can't be converted to Integer, so a runtime conversion error occurs. The value isn't silently truncated.\nWhen the true and false expressions have different types, explicitly convert them to the intended common type or use an if-then-else statement to assign each value directly to the destination. For example, the following code preserves the decimal value:\n```al\nif UseDefault then\n    Quantity := 1\nelse\n    Quantity := OriginalQuantity;\n```\n## Operator hierarchy\nOperators are organized in a hierarchy that determines the order in which the operands in a given expression are evaluated. The following list shows the order of precedence of the AL operators:\n1. `.`(fields in records), `[ ]` (indexing), `()` (parentheses), `::` (scope), `@` (case-insensitive)\n2. not, `-` (unary), `+` (unary)\n3. `*`, `/`, div, mod, and, xor\n4. `+`, `-`, or\n5. `>`, `>=`, `<`, `<=`, `=`, `<>`, in\n6. `..` (range)\n### Example 1\n```\n2 + 3 * 4\n```\nThis expression evaluates to 14.\n### Example 2\n```\n(2 + 3) * 4\n```\nThis expression evaluates to 20.\n## Related information\ndevenv-al-arithmetic-operators\ndevenv-al-boolean-operators\ndevenv-al-relational-operators\nGet started with AL<devenv-get-started>"}