--- title: X++ syntax description: Learn about the syntax reference for X++, including a table that outlines descriptions for various reserved keywords. author: josaw1 ms.author: josaw ms.topic: article ms.date: 07/22/2019 ms.reviewer: johnmichalak audience: Developer ms.search.region: Global ms.search.validFrom: 2016-02-28 ms.dyn365.ops.version: AX 7.0.0 --- # X++ syntax [!include [banner](../includes/banner.md)] This article contains the syntax reference for X++. ## X++ Keywords The X++ keywords shown in the following table are reserved. These keywords cannot be used for any other purpose.
Reserved word | Description | More information |
---|---|---|
! | Not. | Relational Operators |
!= | Inequality operator (not equal to). | Relational Operators |
# | Prefix on macro names. | How to: Use #define and #if to Test a Macro |
& | Binary AND. | Arithmetic Operators |
&& | Logical AND. | Relational Operators |
( | Function call operator, which indicates the beginning of the function call. | |
) | Function call operator, which indicates the end of the function call. | |
* | Multiply. The asterisk (*) is also used in X++ SQL. One use is to signify all fields from the tables on a select statement. Another use is as a wildcard with the like operator, to signify 0 to many characters of any kind. The like operator also uses the ? character. |
Arithmetic Operators |
^ | Binary XOR. | Arithmetic Operators |
| | Binary OR. | Arithmetic Operators |
|| | Logical OR. | Relational Operators |
~ | Not. | Arithmetic Operators |
+ | Plus. | Arithmetic Operators |
++ | Increment. | Assignment Operators |
+= | Additive assignment. | Assignment Operators |
, | Comma operator. Expressions separated by commas are evaluated left-to-right. | |
- | Minus. | Arithmetic Operators |
-- | Decrement operator. | Assignment Operators |
-= | Subtractive assignment. | Assignment Operators |
. | Class member access operator, for example, formRun.run accesses the run method of an object of the class type FormRun . |
|
/ | Divide. | Arithmetic Operators |
</strong> | Escape in strings. Escapes extra quotation marks, and certain letters such as \t for tab. | |
@ | Escape of keywords. For example, str |
|
: | Field declaration or label specifier. The colon (:) character is also used on the switch statement. |
|
:: | Used to call static (class) methods: ClassName::methodName. | |
; | Terminates statements. Used in for loops or as a separator of statements. |
|
< | Less than. | Relational Operators |
<< | Left shift. | Arithmetic Operators |
<= | Less than or equal. | Arithmetic Operators |
= | Assignment operator. The argument to the left of "=" is set to the value of the argument to the right. | Assignment Operators |
== | Returns true if both expressions are equal. | Relational Operators |
> | Greater than. | Relational Operators |
>= | Greater than or equal. | Relational Operators |
>> | Right shift. | Arithmetic Operators |
? | Ternary operator. The question mark (?) character is also used by the like operator to signify exactly one character of any kind. The like operator also uses the character. |
Ternary Operator (?) |
[ | Array declarator, open. Must be used with "]". | |
] | Array declarator, close. Must be used with "[". | |
{ | Indicates the beginning of a number of statements. The last of these statements must be followed by a "}". | |
} | Indicates the end of a number of statements. A "{" must appear before the first of these statements. | |
abstract | Class and method modifier. An abstract class cannot be constructed with the new keyword. An abstract method cannot be called. A table can also be modified as abstract by setting its Abstract property to Yes in the AOT, or by using the DictTable class. The Abstract property defaults to No, and it cannot be set unless the table is extended by another table. Each row in an abstract table must have a dependent row in a derived table. This means that each row in an abstract table has a value greater than 0 (zero) in its InstanceRelationType property field. There are no other effects from marking a table as abstract. Informally, programmers often use the term concrete to describe a class that is non-abstract. |
Method Modifiers Table Inheritance Overview |
anytype | The method can return any data type. | Anytype |
as | Needed when you assign a base class variable to a derived class variable. For example, given a Derived class that extends a Base class, the statement myDerived = myBase as Derived; avoids a compiler error by using the as keyword. This keyword also applies when you assign a base table variable to a derived table variable. |
Expression Operators: Is and As for Inheritance |
asc | An option on the order by or group by clause in a select statement. The sorting is ascending. |
Select Statement Syntax |
at | Specifies the position of a print window. | Print Statements |
avg | Returns the average of the fields from the rows specified by the group by clause in a select statement. |
Select Statement Syntax |
break | Immediate exit from code block. | Break Statements |
breakpoint | Represents a breakpoint that is set for debugging purposes. To set a breakpoint in your code, write: breakpoint; |
|
by | Part of a reserved term, such as group by and order by. | |
byref | Specifies that the parameter being passed to the called method is being passed by reference (address), instead of by value. Byref is used in X++ when calling a .NET method that takes a parameter by reference (such as with the C# keywords out or ref). | How to: Use the byref Keyword for CLR Interop. |
case | Selection within a switch statement. |
Switch Statements |
catch | Used in exception handling. | Exception Handling with try and catch Keywords |
changeCompany | Changes database settings to another company. | Change Company Design Pattern |
class | Declares a class. | Classes in X++ |
client | Method modifier. | Method Modifiers |
container | Specifies a variable of type container . |
Containers |
continue | Forces the next iteration of a loop. | Continue Statements |
count | Returns the number of records from the rows specified by the group by clause in a select statement. |
Select Statement Syntax |
crossCompany | Causes a select statement to return data for all companies that the user is authorized to read from. |
Cross-Company X++ Code Basics |
date | Specifies a variable of type date . |
Dates |
default | Default case within switch statements. |
Switch Statements |
delegate | A class member that is able to store multiple references to methods in other classes, and to call all those methods when prompted to do so. A delegate can store references to various kinds of methods including the following:
|
Event Terminology and Keywords X++, C# Comparison: Event |
delete_from | Allows you to delete multiple records from the database at the same time. | delete_from |
desc | An option on the order by or group by clause in a select statement. The sorting is descending. |
Select Statement Syntax |
display | Method modifier. | Method Modifiers |
div | Integer division. | Arithmetic Operators |
do | Beginning of a do...while loop. |
Do...while Loops |
edit | Method modifier. | Method Modifiers |
else | Conditional execution (if...else ). |
if and if ... else Statements |
eventHandler | Must be used each time you either add or delete a method reference from a delegate by using the += or -= operator. For example: myDelegate += eventHandler(OtherClass::myStaticMethod); | Event Terminology and Keywords X++, C# Comparison: Event |
exists | Used with join clauses in select statements. |
Select Statement Syntax |
extends | A class or interface declaration clause. If your class does not explicitly extend another class, your class is considered to extend the Object class (as if you had written "extends Object"). |
Creating a Subclass |
false | Boolean literal. | Booleans |
final | Class and method modifier. | Method Modifiers |
firstFast | Used in select statements to speed up the fetch for the first row. |
Select Statement Syntax |
firstOnly | Used in select statements to fetch only the first record. The firstOnly keyword does not guarantee that a maximum of one record is retrieved by an X++ SQL select statement. If the AOS can use the EntireTable cache to satisfy the data demands of the select statement, the firstOnly keyword is ignored. |
Select Statement Syntax Set-based Caching |
firstOnly10 | Same as firstOnly, except returns 10 rows instead of one. | |
firstOnly100 | Same as firstOnly, except returns 100 rows instead of one. | |
firstOnly1000 | Same as firstOnly, except returns 1000 rows instead of one. | |
flush | Clears an entire table cache. Here is the syntax for the flush statement applied to the buffer of type YourTable :```xpp
``` |
Set-based Caching |
for | For loop iteration. | For Loops |
forceLiterals | Used in select statements to reveal actual values that are used in where clauses to the Microsoft SQL Server database at the time of optimization. |
Select Statement Syntax |
forceNestedLoop | Forces the SQL Server database to use a nested-loop algorithm to process a particular SQL statement containing a join . |
Select Statement Syntax |
forcePlaceholders | Used in select statements to instruct the kernel not to reveal the actual values used in where clauses to the Microsoft SQL Server database at the time of optimization. |
Select Statement Syntax |
forceSelectOrder | Forces the SQL Server database to access the tables in a join in the specified order. | Select Statement Syntax |
forUpdate | Selects records exclusively for update. The operation to be performed on the records that are fetched is an update. Depending on the underlying database, the records may be locked for other users. | Select Statement Syntax |
from | Part of a select statement. The from clause specifies the table in which the columns exists. |
Select Statement Syntax |
group | Part of the group by clause in a select statement. |
Select Statement Syntax |
if | Conditional execution. | if and if ... else Statements |
implements | Implements an interface. | Interfaces Overview |
insert_recordset | Copies data from one or more tables into one resulting destination table on a single server trip. | insert_recordset |
int | Specifies a variable of type integer (32-bit). |
Integers |
int64 | Specifies a variable of type integer (64-bit). |
Integers |
interface | Interface declaration. | Interfaces Overview |
is | Asks whether the object referenced by a class variable either inherits from the given class or is of the given class. For example, given a Derived class that extends a Base class, the expression (myDerived is Base) returns true. This keyword applies to class inheritance and table inheritance. |
Expression Operators: Is and As for Inheritance |
join | Tables are joined on columns common to both tables. You can generate a single result set based on multiple tables through the use of joins. | Select Statement Syntax |
like | Tests for matches by pattern, with wildcard symbols * and ?. The string on the right side of the like operator must use four backslash characters to represent one backslash. Examples follow:
|
Relational Operators |
maxof | Returns the maximum of the fields from the rows specified by the group by clause. |
Select Statement Syntax |
minof | Returns the minimum of the fields from the rows specified by the group by clause. |
Select Statement Syntax |
mod | Returns the integer remainder of the left expression1 divided by the right expression2. Informally this is sometimes called the modulo operator. ((12 mod 7) == 5) is true. |
|
new | Operator. Creates an instance of an anonymous class that is assignment-compatible with the named class/interface reference variables, or allocates memory for an array. | |
next | Fetches the next record in a table. | |
noFetch | Indicates that no records are to be fetched at present. | Select Statement Syntax |
notExists | Used with join clauses in select statements. |
Select Statement Syntax |
null | Symbolic constant. | |
optimisticLock | Forces a statement to run with optimistic concurrency control, even if a different value is set on the table. | Select Statement Syntax |
order | Part of the order by clause in a select statement. |
Select Statement Syntax |
outer | outer join. | Select Statement Syntax |
pause | Halts the execution of a job. The user is asked to state whether execution should continue. | Select Statements |
pessimisticLock | Forces a statement to run with pessimistic concurrency control, even if a different value is set on the table. | Select Statement Syntax |
Allows you to display output on the screen. | Print Statements | |
private | Method access modifier. | Method Access Control |
protected | Method access modifier. | Method Access Control |
public | Method access modifier. | Method Access Control |
real | Specifies a variable of type real . |
Reals |
repeatableRead | Specifies that no other transactions can modify data that has been read by logic inside the current transaction, until after the current transaction completes. An explicit transaction completes at either ttsAbort or at the outermost ttsCommit. For a stand-alone select statement, the transaction duration is the duration of the select command. However, the database sometimes enforces the equivalent of repeatableRead in individual select statements even without this keyword appearing in your X++ code (depending on how the database decides to scan the tables). | For more information, see the documentation for the underlying relational database product. |
retry | Used in exception handling. | Exception Handling with try and catch Keywords |
return | Exits from a method. | Declaration of Methods |
reverse | Records are returned in reverse order. | Select Statement Syntax |
select | The select clause designates which columns or views are shown in the result set. |
Select Statements |
server | Method modifier. | Method Modifiers |
setting | Used with the update_recordset command. | update_recordset |
static | Static methods may not refer to instance variables (only to static variables); may be invoked by using the class name rather than on an instance of the class ("MyClass.aStaticProcedure "). |
Method Modifiers |
str | Specifies a variable of type string . |
Strings |
sum | Returns the sum of the fields from the rows specified by the group by clause in a select statement. |
Select Statement Syntax |
super | Calls the method that was overridden by the current method. | Table Methods |
switch | Switch selection statement. | Switch Statements |
tableLock | Obsolete; tableLock is no longer available. | |
this | A reference to the current instance of the class. Used in X++ code inside a method of the class. Used to reference method members of the class, but not field members of the class.public str getFullName() { // Next statement fails to compile without 'this.'. return this.concatenateFirstAndLastNames(); } |
Loosely similar to the system variable that is named element . You use element in form control methods to reference the containing form. For more information, see Using Variables with Forms. |
throw | Used in exception handling. | Exception Handling with try and catch Keywords |
true | Boolean literal. | Booleans |
try | Used in exception handling. | Exception Handling with try and catch Keywords |
ttsAbort | Discards all changes in the current transaction. | Transaction Integrity |
ttsBegin | Marks the beginning of a transaction. | Transaction Integrity |
ttsCommit | Marks the end of a transaction. | Transaction Integrity |
update_recordset | Allows the manipulation of row sets within one operation. | update_recordset |
validTimeState | Filters rows that are retrieved from a valid time state table by an X++ SQL select statement. For example: select validTimeState(myDateEffective) * from xMyTable; ...or... select validTimeState(myDateFrom, myDateTo) * from xMyTable; |
Effects of Valid Time State Tables on Read and Write Operations |
void | Identifies a method that does not return a value. | Declaration of Methods |
where | Part of a select statement. The where clause specifies the conditions to be satisfied; that is, the rows that you want to include in the result. |
Select Statement Syntax |
while | Iteration statement. Executes a statement or block repeatedly when a test condition is true. | While Loops while select Statements |
window | Allows you to alter the size of the output window. | Print Statements |
Area | Syntax rule | Before Microsoft Dynamics AX 2012 | Starting with Microsoft Dynamics AX 2012 | ||
---|---|---|---|---|---|
Escape | The backslash character </span> is rejected by the compiler for unrecognized escapes | The compiler used to accept "31\12\2002", but during run time the literal string was interpreted as a different value. | Now the following X++ statement is rejected by the compiler: str myDateString = "31\12\2002"; The proper syntax is "31\12\2002". | ||
Exceptions | Retry is no longer allowed outside of a catch block | It was possible to write the retry keyword outside of a catch block. This caused the program to end when the retry was reached during runtime. | Now retry can occur only inside a catch block. For more information, see Exception Handling with try and catch Keywords. | ||
Exceptions | Now you can throw and catch only int values |
It was possible to throw scalar expressions like strings and dates, such as throw "hello world"; , and get no compile error. At runtime this was catch-able by a catch block that was not decorated with any specific value, such as catch {print("Catch worked.");}. |
Now the only expression you can put on the throw keyword is an int . Often the best thing to throw is Global::error("Explanation");. Often the best thing to catch is an element of the Exception enum. For more information, see Exception Handling with try and catch Keywords. |
||
Inheritance | Downcasting can now be explicit.
|
It was possible to assign a base object to a derived object with the simple assignment operator, which is the equals sign (= ). The compiler accepted these assignments, but during run time any misuse of an improper downcast assignment caused an error. |
Now all downcasts can be explicit. This is accomplished with the new as expression operator. Explicit downcasting with the as keyword is illustrated by the following code example, in which ThingClass extends Object : ThingClass myThing = new ThingClass(); Object myObject = myThing; myThing = myObject as ThingClass; // Explicit downcast, good. For more information, see Expression Operators: Is and As for Inheritance. |
||
Inheritance | Override of a base method cannot be less accessible than the base method | It was possible to have a base method be decorated with protected and yet have an override of that method be private. | Now when a base method is protected, the override method must be either protected or public, and the override method cannot be private. For more information, see Method Access Control. | ||
Inheritance | Override of a base method must have the exact same return type and parameter signature as the base method | Suppose a base class had a method that inputs a parameter of the Common table, which is the base of all tables. In a derived class it was possible to override the method to instead input MyTable . |
Now the parameter signatures of the base method and its override method must match exactly. Also, the return types must match exactly. For more information, see Overriding a Method. | ||
Interfaces | Implementation of an interface method must match the parameter signature exactly | Suppose an interface had a method that input a parameter of an int . In a class that implements the interface, it was possible to write the method with a parameter of a str . |
Now the parameter signatures of the method must exactly match between the interface and the implementation of the method on a class. Also, the return types must match exactly. For more information, see Interfaces Overview. | ||
Interfaces | A non-abstract base class that implements an interface cannot rely on a derived class for that implementation | When a base class implements an interface, it was possible for the class to not implement the methods of the interface if a derived class implemented the methods. The only limitation was that the new constructor method could not be called on the class. |
Now the compiler requires that every class that implements an interface must have or inherit a complete implementation of every method of the interface. For more information, see X++, C# Comparison: Object Oriented Programming. | ||
Modifiers | The static modifier should not be applied to an interface | It was possible to write static interface IMyInterface {}, but the static modifier had no effect because it makes no sense in this context. | Sometime after Dynamics AX 2009 the X++ compiler might stop allowing the static modifier on interface declarations. For more information, see Interfaces Overview. | ||
Modifiers | The static modifier must not be applied to the new constructor |
It was possible to apply the static modifier to the declaration of the new constructor method. This caused new MyClass(); to behave as a null operation. Instead, the statement MyClass::new(); would call the static new method, but that would not construct an object. |
Now the compiler issues an error when the static modifier is applied to the new method. For more information, see Constructors. |
||
Modifiers | Use an explicit access modifier on each method | In the past the menu item of AOT > Classes > MyClass > New Method created the method without any access modifier. This meant that the method was implicitly public, although some X++ developers might not have been fully aware of the default. This created extra work later when a developer needed to modify the code in the method, because the developer had to research everywhere that the method might be called from. | Now the New Method menu item explicitly includes the private keyword in its automatic declaration of the new method. The developer can type in a different modifier if appropriate. For more information, see Method Modifiers. | ||
Parameters | Parameters given in a call to a new constructor method must match the parameters on the new constructor method |
It was possible to pass in multiple parameters on call to a new constructor method even when the new method was declared to input no parameters. |
Now the call to the new method must exactly match the declared parameter signature of the new method. For more information, see Creating a Subclass. |
||
Parameters | Parameters with default values must come after all parameters that do not have default values | It was possible to declare a method that takes in two parameters, and have only the first parameter offer a default value. There was no purpose to this. There was no way to accept the default of the first parameter because the call must specify a value for the second parameter and cannot omit the first parameter. | Now in the declaration of a method, any parameter that offers a default value must come after all the parameters that do not. For more information, see the following topics:
|
||
Parameters | Override of a method must have the same default parameters as the overridden method | It was possible to declare a method as public void myMethod(int i=22){} and the override as public void myMethod(){}. But if the override method was called as derivedObject(333); an error occurred. |
Now the override method must list the same parameter types in the same sequence that they are declared in the overridden method. For more information, see Overriding a Method. | ||
Preprocessor | A TODO in a comment must be the first non-whitespace in the first line of the comment | The X++ preprocessor used to detect the TODO keyword in a multi-line /* ... */ task comment even when the TODO appeared after other text after the first comment line. | Now the X++ preprocessor detects the TODO keyword only if TODO appears on the first line of the comment, and as the first non-whitespace in the comment. For more information, see TODO Comments for X++ Developer Tasks. |