Data Types in X++ Programming Language

Rumman Ansari   Software Engineer   2023-09-19   10263 Share
☰ Table of Contents

Table of Content:


What is data types?

A data type in the X++ language is an attribute associated with a piece of data that tells a computer system how to interpret its value. The data type specifies the size, precision, and range of values that the data can take on. It also determines the set of mathematical, relational, and logical operations that can be performed on the data.

Data Types
Figure:



Data types examples

Serial No Data Types
1 Primitive Data Types
2 Composite Data Types
3 Extended Data Types (EDTs)
1 Conversion of Data Types
2 Null Values for Data Types

This unit explains the different data types and operators that are used in X++.

Primitive Data types

Primitive data types are the most common data types that you will encounter. The primitive data types are: anytypebooleandateenumguidintint64realstr,timeOfday, and utcdatetime.

  • Date - This data type contains the day, month, and year. You can write out the date as literals by using the format day\month\year. The year must be entered as four digits. The dates that are used must be within the January 1, 1900 and December 31, 2154 range. The default value for a date data type is 1/1/1900. We recommend that you use utcDateTime instead of Date because it combines datetimeOfDay, and time zone information into a single data type.
  • Enumerations (enums) - Are a named list of literals. For example, there is an enum called NoYes, with a list of literals No and Yes. Each literal can also be represented by a number. The first literal has the number 0, the next literal has the number 1, and so on. You can also provide your own values in the enum metadata. To reference an enum value, you would use the enum name followed by two colons and the name of the literal. Considering the NoYes enum again, to reference the Yes literal, you would write NoYes::Yes.
  • GUID - This data type is a globally unique identifier (GUID) value. A GUID number is unique across all computers and networks.
  • Int - These values are 32-bit wide integer signed numbers that do not include a decimal place. There is no support for unsigned integer types.
  • Int64 - A larger, signed integer data type that works the same as the int data type, except that it is 64 bits wide compared to 32 bits. This gives the int64 type a greater range for larger numbers.
  • Real - These data types hold number values with decimals.
  • Str - This data type contains values that are a string of characters. The str value must be wrapped in double quotation marks ("text") or single quotation marks ('text').
  • TimeOfday - This data type is an integer value that represents the number of seconds that passed since midnight.
  • Utcdatetime - This data type is a combination of the date type and the timeOfday data type. The format is yyyy-mm-ddThh:mm:ss with the default value being 1900-01-01T00:00:00.

Composite data types

Along with primitive data types, there are composite data types. Composite data types include arrays, containers, classes, delegates, and tables.

  • Arrays - Contain a list of items that have the same data type. You can retrieve an element in the array with an integer index. You can use arrays in different ways. Dynamic arrays are open and fixed-length arrays specify a certain length. Partly on disk arrays can be dynamic or fixed, with an option to determine how many items are held in memory.
  • Containers - Are dynamic collections of primitive items or other containers. Containers can be useful to pass different types of values, but they are not ideal when used in processes that frequently change the size or contents.
  • Classes - Can be used as a data type to declare an instance of a class within a method.
  • Delegates - Can be defined on a method, table, form, or query. When a delegate is called, it will also call their subscriber methods. Delegates never return a value and have a default value of “no handlers added,” which means nothing is called when you call them.
  • Tables - Can be used to declare an instance of a table. Once a table instance is declared, you can manipulate the data within the table. We recommend that the table variable has the same name as the table, but you should use camel casing. For example, the table EcoResProduct would be declared by using camel casing as ecoResProduct.

User-defined data types

Extended data types (EDT) are user-defined types that are based on the boolean, intint64realstrdate, and container data types. EDTs can be used on variables, method parameters and field declarations, and they provide several benefits. First, they make code easier to read because the EDT name can be defined by the user. Therefore, instead of using just str, you could use an EDT called Color, which would be a more meaningful name. You can also set certain properties on the EDT that all instances of that type use. Additionally, you can create hierarchies for EDTs so an EDT can inherit the properties of a parent.


Importance of data types

When working with data types, it's important to choose the appropriate data type for your variables and constants, based on the kind of data that they will be storing and the operations that you will be performing on that data.

For example, when working with numbers, you can use the int data type for whole numbers, and the real data type for decimal numbers. When working with text, you can use the string data type. And when working with Boolean values, you can use the boolean data type.

It's also important to keep in mind that, the X++ data types are similar but not the same as the data types in C# or other languages, and they may have some different behaviors or limitations.

When you're working with data types, it's also important to consider the performance and memory usage of your code, especially when working with large data sets or when performing complex operations.