AL Data Types and Methods
This document explains all commonly used data types and methods in AL and how they are used in real Business Central development. While earlier AL documents focused on architecture and objects, this page focuses on how data is represented and manipulated inside AL code.
The intention is not to turn this into a memorization guide, but to help learners understand:
• Why AL has so many data types
• How those data types map to ERP concepts
• How methods work within Business Central’s controlled execution model
A correct understanding of data types and methods is essential for writing safe, predictable, and upgrade-friendly AL code.
Why Data Types Are Critical in AL
AL is a strongly typed ERP language. Every variable, parameter, and field must have a clearly defined data type. This is not a technical limitation—it is a business safeguard.
In Business Central, data types protect:
• Financial accuracy
• Inventory precision
• Posting correctness
• Auditability
Choosing the wrong data type is not just a coding error; it is a business risk.
Classification of AL Data Types
AL data types can be grouped into six major categories:
1. Numeric data types
2. Text and identifier data types
3. Date and time data types
4. ERP-specific complex data types
5. Object reference data types
6. System and utility data types
Each category serves a distinct role in ERP development.
1. Numeric Data TypesInteger
The Integer data type stores whole numbers and is commonly used for counters, indexing, and control logic.
Example: Using Integer
var
LineNo: Integer;
begin
LineNo := 10000;
end;
Integers should not be used for monetary or quantity values.
Decimal
The Decimal data type is used for amounts, prices, quantities, and costs. It supports precision and rounding logic required in ERP systems.
Example: Using Decimal
var
UnitCost: Decimal;
Quantity: Decimal;
TotalCost: Decimal;
begin
UnitCost := 45.75;
Quantity := 10;
TotalCost := UnitCost * Quantity;
end;
In Business Central, almost all financial and inventory calculations use Decimal.
BigInteger
BigInteger is used when values exceed the range of a standard Integer, such as large counters or technical identifiers.
Example: Using BigInteger
var
LargeCounter: BigInteger;
This type is rarely used in functional business logic.
2. Text and Identifier Data TypesText
Text is used for descriptions, comments, and free-form input.
Example: Using Text
var
CommentText: Text[250];
begin
CommentText := 'Production order completed successfully';
end;
Text fields have a fixed maximum length.
Code
Code is used for identifiers such as customer numbers, item numbers, and document numbers.
Example: Using Code
var
ItemNo: Code[20];
begin
ItemNo := 'ITEM-1001';
end;
Although similar to Text, Code is optimized for indexing and searching and should always be used for keys and identifiers.
Char
Char stores a single character and is rarely used in business logic.
Example: Using Char
var
Initial: Char;
begin
Initial := 'A';
end;
Date
Stores calendar dates and is used heavily in posting, reporting, and period control.
Example: Using Date
var
PostingDate: Date;
begin
PostingDate := Today();
end;
Time
Stores time values without a date component.
Example: Using Time
var
StartTime: Time;
begin
StartTime := Time();
end;
DateTime
Combines date and time and is typically used for logging, integration, and background processing.
Example: Using DateTime
var
CreatedAt: DateTime;
begin
CreatedAt := CurrentDateTime();
end;
Duration
Represents time intervals and is used for performance measurement or scheduling.
Example: Using Duration
var
ProcessingTime: Duration;
These data types make AL ERP-aware.
Record
The Record data type represents a table and allows interaction with stored business data.
Example: Using Record
var
CustomerRec: Record Customer;
begin
CustomerRec.Get('CUST-1000');
end;
Records are the most important data type in AL development.
RecordRef and FieldRef
These are dynamic record and field references used for generic logic, utilities, or frameworks.
Example: Using RecordRef and FieldRef
var
RecRef: RecordRef;
FldRef: FieldRef;
They are powerful but should be used carefully.
Enum
Enums represent predefined, controlled values such as statuses or types.
Example: Using Enum
var
Status: Enum "Sales Document Status";
begin
Status := Status::Released;
end;
Enums prevent invalid values and improve readability.
Option (Legacy)
Options are an older construct replaced by Enums. They exist mainly in legacy code.
Example: Using Option (Legacy)
OptionValue: Option Open,Released,Closed;
New development should always use Enums instead.
5. Object Reference Data TypesPage
Used to interact with or run pages programmatically.
Example: Using Page
var
CustomerPage: Page "Customer Card";
begin
CustomerPage.Run();
end;
Codeunit
Used to call reusable business logic.
Example: Using Codeunit
var
PriceCalc: Codeunit "Sales Price Calc. Mgt.";
begin
PriceCalc.Run();
end;
Report
Used to run reports or batch processes.
Example: Using Report
Report.Run(Report::"Customer - List");
Query
Used for optimized data retrieval.
Example: Using Query
var
MyQuery: Query "Item Sales Query";
Boolean
Represents true or false values.
Example: Using Boolean
var
IsBlocked: Boolean;
begin
IsBlocked := false;
end;
Guid
Used for unique identifiers, especially in integrations.
Example: Using Guid
var
UniqueId: Guid;
begin
UniqueId := CreateGuid();
end;
JsonObject, JsonArray, JsonToken
Used for integrations and API communication.
Example: Using JsonObject, JsonArray, JsonToken
var
JsonObj: JsonObject;
begin
JsonObj.Add('Status', 'Success');
end;
HttpClient, HttpRequestMessage, HttpResponseMessage
Used for calling external services.
Example: Using HttpClient, HttpRequestMessage, HttpResponseMessage
var
Client: HttpClient;
Response: HttpResponseMessage;
Methods in AL
Methods in AL are procedures and functions that execute logic. They can:
• Accept parameters
• Return values
• Operate on records
• Trigger validations
Simple Procedure Example
procedure CalculateTax(Amount: Decimal): Decimal
var
Tax: Decimal;
begin
Tax := Amount * 0.18;
exit(Tax);
end;
Record Methods
//Records expose built-in methods:
ItemRec.Validate("Unit Price", 200);
ItemRec.Modify();
Validation ensures standard business rules are applied.
Why AL Methods Are ControlledAL does not allow unrestricted execution. All methods run within Business Central’s framework, ensuring:
• Data integrity
• Posting accuracy
• Upgrade safety
Developers extend behavior; they do not bypass it.
Common Beginner Mistakes
• Using Text instead of Code
• Using Integer for amounts
• Skipping Validate
• Overusing RecordRef
• Mixing UI and business logic
Avoiding these mistakes early leads to stable extensions.
Summary
Data types define what kind of business data AL handles, and methods define how that data is processed. Together, they form the foundation of all AL development in Business Central.
A deep understanding of data types and methods is essential for writing correct, maintainable, and ERP-aligned AL code.
Hot Topics in Business Central