Expressions Syntax

Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012

An expression in X++ is used in either a mathematical or logical way. Expressions are built on the data types of the language; that is, an expression returns a value of some type. This value can be used in calculations, assignments, conditional statements, and so on.

EBNF Description of Expressions in X++

Expression

=

Simple-expression [RelationalOperator Simple-expression ]

RelationalOperator

=

= | != | < | > | <= | >= | like

Simple-expression

=

Simple-expression [ + | - | | ] Term | Term

Term

=

Compfactor { Mult-operator CompFactor }

Mult-operator

=

* | / | div | mod | << | >> | & | ^ | |

CompFactor

=

[ ! ] [ - | ~ ] Factor

Factor

=

Literal | Enum | Variable | FunctionCall | ( If-expression ) | Select-expression

Enum

=

EnumName :: Literal

Variable

=

Identifier [ [ Expression ] ] [ . Expression ]

FunctionCall

=

[ Expression (. | ::) | this . ] FunctionName ( argumentlist )

If-expression

=

Expression ? Expression : Expression

Semantic restrictions apply on the preceding syntax. You cannot call any method using the :: operator. Similarly, you cannot use the this keyword without an active object; that is, if you are not within a method and so on.

Examples

Example of expression

Description

1

An integer literal.

NoYes::No

An enum-reference.

A

A variable-reference.

Debtor::Find("1")

A static method-call (returns a customer variable).

(A > 3 ? true : false)

An if-expression that returns true or false.

(select CustTable where CustTable.Account == "100").NameRef

A select-expression. Returns the nameref field in the customer table. This is a string.

A >= B

A logical expression. Returns true or false.

A + B

An arithmetic expression. Sums A and B.

A + B / C

Calculates B/C, and then adds this to A.

~A + this.Value()

Sums binary not A and the result of the method-call Value on the object in scope (this).

Debtor::Find("1").NameRef

Returns the NameRef field of the found customer record.

Debtor::Find("1").Balance()

A method call to Balance in the customer table (Debtor::Find returns a customer). Returns the balance of the customer with account number 1.

See also

X++ Syntax

Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.