RSS

Category Archives: Introduction

Getting Familiar with X++

In this post, I will make you familiar with the X++ language which is used in Dynamics AX for development. As I have mentioned in my previous post that X++ is quite similar to C#, so all of you have experience of C# won’t have problem in understanding X++. The language is based on Object Oriented Programming principles. You can define access specifiers like Public, Private, & Protected for encapsulation. You can inherit objects, and define polymorphic behavior on methods. I will discuss further in my future post.

So, lets start with the data types that X++ supports. Following are the Primitive data types of X++,

• String (str)

• Integer (int)

• Real (real)

• Boolean (boolean)

• Date (date)

• Enum (enum)

• TimeOfDay (timeofday)

• UtcDateTime (utcdatetime)

• Anytype (anytype)

So these are the primitive data types with the keyword used for it. For example, if you want to declare a variable of type string, you can declare it like that,

str varString;

Need to know little more, Okie, lets make a very small program to understand. In the AOT, there is a Job node. You can create a Job for testing the code. A job yypically holds small X++ programs that are used to test new code. Just right click the Job node and Create new job.

Now write the following codes,

static void Datatypes_string1(Args _args)

{

str 7 fixedLengthString;

str dynamicLengthString;

;

fixedLengthString = “Welcome to Carz Inc”;

dynamicLengthString = “Welcome to Carz Inc”;

print fixedLengthString;

print dynamicLengthString;

pause;

}

strfmt function is used to get the formatted string. Following method is used to format a string and change any occurrences of %n with parameter n.

To illustrate this, the next Job will print 100: Welcome to Carz Inc

static void Datatypes_string_strmft(Args _args)

{

str name;

int a;

;

name = “Carz Inc”;

a = 100;

print strfmt(“%1: Welcome to %2”, a, name);

pause;

}

Notice that the strfmt function also converts any other data types into string.

Let me describe a little about “anytype” . The anytype data type can contain any of the other primitive data types. The type of the variable data is decided by the first value that is set for the variable.

If you expand “Data Dictionary” node you will see a node named “Extended Data Type”. All the extended data types are based on Primitive data type, however the extended data type has more flavor to the data type like stringsize, label and help text or the configuration key to make the data type specific to configuration settings.

Apart from primitive data types there are Composite data types. These are data types where each variable can consist of multiple other variables.

The different kind of composite data types are:

• Container

• Class

• Table

• Array

Each of the above will be discussed later.

Now, lets talk about the syntax of different statement that controls the flow of the program. I will not go much deep and will just mention the syntax of each statement.

For loop

for (initialization; condition; increment)

{

//statements that need repetition that will repeat until the condition is true

}

While loop

while (condition)

{

//statements that need repetition that will repeat until the condition is true

}

Do-while loop

do

{

//statements that need repetition that will repeat until the condition is true

} while (condition)

If, else if, else

if (condtion1)

{

//statements that will run if condition 1 is true.

}

else if (condition2)

{

//statements that will run if condition 2 is true.

}

else

{

//statements that will run if condition 1 and condtion2 is false.

}

switch

switch (variable to match any case)

{

Case 1 :

//statement if case 1

break;

case 2 :

//statement if case 2

break;

case 3 :

//statement if case 3

break;

default

//statement if none of the cases match

break;

}

Note : the case statement can be written string, enum, int etc depends upon the type of variable used in switch.

You can test all the statements by creating new job in AOT and observe how the statements behave and to be well aware of writing code in X++.

Advertisements
 
3 Comments

Posted by on March 23, 2010 in Introduction

 

Tags: , , , ,

Intro

Hello everyone,

This blog is dedicated to explore the Microsoft Business Solution DynamicsAX technically. Microsoft Dynamics AX  is a comprehensive business management solution, also called ERP-solution, for midsize and larger organizations that works like and with familiar Microsoft software. Microsoft Dynamics AX is built to make it easy to do business across locations and countries, by consolidating and standardizing processes, helping to improve productivity, providing visibility across your organization, and helping to simplify compliance. have a look at the following screen shot of DAX how it looks like.

Dynamics AX

The blog will cover “How to” series which will help the new developer to easily understand he development in AX. In-depth of knowledge of the features that DAX provide for developing and customizing the application will be posted time to time in this blog. Following are the few key things that you can implement in Dynamics AX,

1. Tables, Classes, Forms, SSRS Reports.

2. Workflow.

3. Enterprise Portal.

4. Web services using AIF.

To develop all this, Microsoft Dynamics AX provides its own Development Environment called MorphX. The programming language of Dynamics AX is “X++”. X++ uses object-oriented programming principles, such as encapsulation, inheritance, classes, objects, methods, and properties. The X++ syntax will be familiar to C# developers, and incorporates SQL data manipulation statements. For more information about X++, see this http://msdn.microsoft.com/en-us/library/aa676506.aspx

Here is the sample code written in X++.

static void Job_LoopsWhile(Args _args)
{
    int nLoops = 1;
    ;
    while (nLoops <= 88)
    {
        print nLoops;
        pause;
        if ((nLoops mod 4) == 0)
        {
            break;
        }
        ++ nLoops;
    }
    pause; // X++ keyword.
}

In MorphX, Application Object Tree (AOT) organize all the objects used to build Microsoft Dynamics AX, such as classes, tables, forms, and so on. Following is the screenshot of AOT.

Application Object Tree

Thats it for now. I hope this post introduces the basic information about the Dynamics AX. Keep in touch and wait for the next post.

 
Leave a comment

Posted by on February 28, 2010 in Introduction

 

Tags: , ,