Variables, types, and operators
Variables, data type conversion, and operators in the AL language for Business Central. It answers questions about declaring and scoping variables, system-defined variables such as Rec and CurrPage, operator types and precedence, and how AL converts types in expressions.
Path: Development > The AL programming language > Variables, types, and operators · tier official · system development · narrative unreviewed (model text not yet checked)
Overview
This section covers the building blocks of AL expressions: variables and operators. The variable pages explain user-defined and system-defined variables, naming rules, automatic initialization, and the protected keyword, which lets table, page and report extensions access variables of the base object.
The operator pages start with an overview of all AL operators (arithmetic, comparison, logical, conditional, compound assignment) and their hierarchy. Separate pages then detail arithmetic operators, relational operators, and boolean operators (not, and, or, xor), including valid data type combinations and resulting types.
The type conversion page explains how the compiler automatically promotes values to more general types when operands are mixed or assigned. Start with AL variables and AL operators, then use the detailed operator pages and the type conversion page when you need exact behavior for specific data types.
Key points
- AL variables can be user-defined or system-defined, with naming rules and automatic initialization.
- System-defined variables include Rec, xRec, CurrPage, CurrReport, RequestOptionsPage, and CurrFieldNo, giving access to current records, pages, and reports.
- Protected variables use the protected keyword to share variables between tables and table extensions, pages and page extensions, and reports and report extensions.
- AL operators cover arithmetic, comparison, logical, conditional, and compound assignment types, with a defined operator hierarchy.
- Arithmetic operators (+, -, *, /, DIV, MOD) have type conversion rules for unary and binary use, with notes on overflow and concatenation.
- Relational operators return boolean values and include an in-range operator, with rules for comparing different data types.
- Boolean operators are not, and, or, and xor, working on boolean expressions and returning booleans.
- The compiler automatically converts types in expressions, using numeric and string type hierarchies to promote to the more general type.
Learn pages
- AL operators: Describes the operators you can use in AL for Business Central.
- AL type conversion in expressions: Description of how AL types can be converted.
- AL variables: Description of AL user-defined and system-defined variables.
- Arithmetic operators: Description of the arithmetic operators in AL for Business Central.
- Boolean operators: Description of the Boolean operators in AL for Business Central.
- Protected variables: The protected keyword can be used to make variables accessible between tables and table extensions, pages and page extensions and report and report extensions.
- Relational operators: Description of the relational operators in AL and how they are used to compare expressions, as well as valid uses of relational operators.
- System-defined variables: Describes the system-defined variables that are automatically declared and initialized in AL for Business Central.
Source: Microsoft Learn (CC BY 4.0). Descriptions are Learn’s own.