Arrays in Sage X3 4GL

By | September 30, 2025

Arrays in Sage X3 4GL provide a powerful and efficient way to store and manage multiple data elements under a single variable. They help streamline your code, improve readability, and reduce complexity when handling collections of related data.

Sage X3 supports both single-dimensional and multi-dimensional arrays, with up to four dimensions allowed, giving developers flexibility to structure data as needed.

In this blog, we’ll focus specifically on single-dimensional arrays—covering how to declare them, assign values, check their size, and iterate through them using For loops.

New Stuff: Automating RFQ (Request for Quotation) Creation in Sage X3

Declaring Single-Dimensional Arrays

In Sage X3 4GL, there are two primary ways to declare a single-dimensional array:

  1. Using the Number of Elements

You can define an array by specifying the total number of elements it should hold. The syntax differs slightly based on the data type.

Examples:
Local Integer Num(5) # Integer array with 5 elements
Local Char String(50)(5) # Character array with 50 characters per element and 5 elements

Notes:
For Integer, simply specify the number of elements in parentheses after the variable name.
For Char, first define the character size (e.g., 50), followed by the number of elements.

  1. Using a Start/End Index Range

You can also declare an array by defining a custom start and end index. This provides more control over how elements are indexed.

Examples:
Local Integer Num(0..4) # Array from index 0 to 4 (5 elements total)
Local Char String(50)(1..5) # Array from index 1 to 5 (5 elements total)

Notes:
This method lets you define both the start and end index explicitly.
If you specify only the start index, Sage X3 automatically sets the end index to the maximum allowed (32,767).

Local Integer BigArray(1..) # Starts at index 1, ends at 32,767

Checking Array Size with dim() Function

In Sage X3 4GL, you can determine the total number of elements in an array using the built-in dim() function. This is especially useful when working with loops or when the array size isn’t hardcoded.
Syntax:
dim(array_variable)

Example:
Local Integer Numbers(0..3)
Infbox(num$(dim(Numbers))) # Outputs: 4

Accessing and Concatenating Values

You can iterate through the array using a For loop along with the dim() function to retrieve or process each element.

Example:
Local Char Word(50) : Word = “”

For I = 1 To dim(Letters)
Word += Letters(I)
Next

Result:
The final value of Word will be:
“ABCDE”

Tips:
Always ensure your loop starts at the same index as your array’s defined start index (e.g., 1 in this example).
If your array starts at index 0, subtract 1 from the loop’s upper limit to avoid an “index not found” error:

Example for array with index 0:
Local Char Codes(1)(0..4) # Array starts at index 0

Local Char Result(50) : Result = “”

For I = 0 To dim(Codes) – 1
Result += Codes(I)
Next

About Us

Greytrix – a globally recognized and one of the oldest Sage Development Partners is a one-stop solution provider for Sage ERP and Sage CRM organizational needs. Being acknowledged and rewarded for multi-man years of experience and expertise, we bring complete end-to-end assistance for your technical consultations, product customizations, data migration, system integrations, third-party add-on development, and implementation competence.

Greytrix has some unique integration solutions developed for Sage CRM with Sage ERPs namely Sage X3Sage IntacctSage 100Sage 500, and Sage 300. We also offer best-in-class Sage ERP and Sage CRM customization and development services to Business Partners, End Users, and Sage PSG worldwide. Greytrix helps in the migration of Sage CRM from Salesforce | ACT! | SalesLogix | Goldmine | Sugar CRM | Maximizer. Our Sage CRM Product Suite includes addons like  Greytrix Business Manager, Sage CRM Project Manager, Sage CRM Resource Planner, Sage CRM Contract Manager, Sage CRM Event Manager, Sage CRM Budget Planner, Gmail Integration, Sage CRM Mobile Service Signature, Sage CRM CTI Framework.

Greytrix is a recognized Sage Champion Partner for GUMU™ Sage X3 – Sage CRM integration listed on Sage Marketplace and Sage CRM – Sage Intacct integration listed on Sage Intacct Marketplace. The GUMU™ Cloud framework by Greytrix forms the backbone of cloud integrations that are managed in real-time for the processing and execution of application programs at the click of a button.

For more information on our integration solutions, please contact us at sage@greytrix.com. We will be glad to assist you.