AL Data Types and Methods

Overview of Microsoft Dynamics 365 Business Central

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 Types

Integer

The Integer data type stores whole numbers and is commonly used for counters, indexing, and control logic.

Example: Using Integer

AL

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

AL

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

AL

var
    LargeCounter: BigInteger;
    

This type is rarely used in functional business logic.

2. Text and Identifier Data Types

Text

Text is used for descriptions, comments, and free-form input.

Example: Using Text

AL

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

AL

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

AL

var
    Initial: Char;
begin
    Initial := 'A';
end;
    
3. Date and Time Data Types

Date

Stores calendar dates and is used heavily in posting, reporting, and period control.

Example: Using Date

AL

var
    PostingDate: Date;
begin
    PostingDate := Today();
end;
    

Time

Stores time values without a date component.

Example: Using Time

AL

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

AL

var
    CreatedAt: DateTime;
begin
    CreatedAt := CurrentDateTime();
end;
    

Duration

Represents time intervals and is used for performance measurement or scheduling.

Example: Using Duration

AL

var
    ProcessingTime: Duration;
    
4. ERP-Specific Complex Data Types

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

AL

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

AL

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

AL

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)

AL

OptionValue: Option Open,Released,Closed;
    

New development should always use Enums instead.

5. Object Reference Data Types

Page

Used to interact with or run pages programmatically.

Example: Using Page

AL

var
    CustomerPage: Page "Customer Card";
begin
    CustomerPage.Run();
end;
    

Codeunit

Used to call reusable business logic.

Example: Using Codeunit

AL

var
    PriceCalc: Codeunit "Sales Price Calc. Mgt.";
begin
    PriceCalc.Run();
end;
    

Report

Used to run reports or batch processes.

Example: Using Report

AL

Report.Run(Report::"Customer - List");
    

Query

Used for optimized data retrieval.

Example: Using Query

AL

var
    MyQuery: Query "Item Sales Query";
    
6. System and Utility Data Types

Boolean

Represents true or false values.

Example: Using Boolean

AL

var
    IsBlocked: Boolean;
begin
    IsBlocked := false;
end;
    

Guid

Used for unique identifiers, especially in integrations.

Example: Using Guid

AL

var
    UniqueId: Guid;
begin
    UniqueId := CreateGuid();
end;
    

JsonObject, JsonArray, JsonToken

Used for integrations and API communication.

Example: Using JsonObject, JsonArray, JsonToken

AL

var
    JsonObj: JsonObject;
begin
    JsonObj.Add('Status', 'Success');
end;
    

HttpClient, HttpRequestMessage, HttpResponseMessage

Used for calling external services.

Example: Using HttpClient, HttpRequestMessage, HttpResponseMessage

AL

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

AL

procedure CalculateTax(Amount: Decimal): Decimal
var
    Tax: Decimal;
begin
    Tax := Amount * 0.18;
    exit(Tax);
end;
    

Record Methods

AL

//Records expose built-in methods:

ItemRec.Validate("Unit Price", 200); ItemRec.Modify();

Validation ensures standard business rules are applied.

Why AL Methods Are Controlled

AL 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

Next Steps in Business Central