Operators and Expressions

Use arithmetic, logical, and comparison operators to build expressions in AL code.

20 minBeginner

Learning Objectives

  • Apply arithmetic operators for calculations
  • Use logical and comparison operators in conditions
  • Build complex expressions for assignments and validations

Arithmetic Operators

OperatorOperationExample
+AdditionTotal := A + B
-SubtractionBalance := Debit - Credit
*MultiplicationLineAmount := Qty * Price
/DivisionUnitCost := TotalCost / Qty
ArithmeticExample.al
var
    Total: Decimal;
    Quantity: Integer;
    Price: Decimal;
begin
    Quantity := 10;
    Price := 15.5;
    Total := Quantity * Price; // Total = 155.0
end;

Logical Operators

OperatorMeaning
andBoth conditions must be true
orAt least one condition must be true
notNegates the condition

Comparison Operators

OperatorMeaning
=Equal to
<>Not equal to
<Less than
>Greater than
<=Less than or equal
>=Greater than or equal
LogicalExample.al
var
    IsActive: Boolean;
    Count: Integer;
begin
    IsActive := true;
    Count := 5;
    if IsActive and (Count > 0) then
        Message('Record is active with count %1', Count);
end;

Working with Expressions

Expressions combine operators and values for assignments and conditions:

DiscountCalculation.al
var
    DiscountRate: Decimal;
    Price: Decimal;
    FinalPrice: Decimal;
begin
    DiscountRate := 0.1;
    Price := 100;
    FinalPrice := Price * (1 - DiscountRate); // FinalPrice = 90
end;

Division Warning

Integer division truncates decimals. Use Decimal variables when fractional results matter.

Key Revision Points (MB-820)

  • AL uses and, or, not (lowercase) for logical operations
  • Comparison operators work on all comparable types
  • Expressions are used in assignments, conditions, and procedure parameters
Open Source

Help improve this platform

NAVBC Learning is open source. Report issues, suggest improvements, or join discussions on GitHub.