Variables, types, and operators
Variables, types, and operators in AL covers user-defined and system-defined variables, protected variables, automatic type conversion, and the operator families (arithmetic, relational, boolean, conditional, compound). It answers questions about syntax, evaluation order, and resulting data types.
Path: Development > The AL programming language > Variables, types, and operators · tier official · system development · narrative reviewed (checked by Opus)
Overview
This section describes the building blocks of AL expressions. The variable pages explain how to declare and name variables, how they are initialized, and how system-defined variables such as Rec, xRec, CurrPage, CurrReport, RequestOptionsPage, and CurrFieldNo give access to the current record, page, or report. Protected variables let tables and table extensions, pages and page extensions, and reports and report extensions share variables.
The operator pages begin with an overview of all AL operator types and their precedence. Separate pages then detail arithmetic operators, relational operators, and Boolean operators. A type conversion page explains how the compiler converts mixed operands automatically.
Start with AL variables for declaration and naming, then AL operators for the full list and evaluation order. Use the specific operator pages and the type conversion page when you need the result type of a mixed-type expression.
Key points
- AL variables page covers naming rules, initialization, user-defined and system-defined variables, and type conversion in assignments.
- System-defined variables include Rec, xRec, CurrPage, CurrReport, RequestOptionsPage, and CurrFieldNo.
- The protected keyword allows variable access between tables and table extensions, pages and page extensions, and reports and report extensions.
- AL operators reference lists general, arithmetic, comparison, logical, conditional, and compound assignment operators with precedence.
- Arithmetic operators page covers unary and binary operations on numeric, date, time, text, and code types, including overflow handling.
- Relational operators return boolean values, including the in range operator, with valid data type combinations.
- Boolean operators are not, and, or, and xor, operating on boolean expressions.
- Type conversion promotes values to more general types following numeric and string type hierarchies.
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.