Set/Link Data on
Temporary Tables (AX 2012)

 In Ax 2012, the Temporary property on tables was
replaced with a new property: TableType, which has three possible
values:

  • Regular - a standard
         physical table
  • InMemory - the type
         of temporary table which existed in the previous versions of Dynamics Ax.
         Such tables are held in memory and written to a local disk file once they
         grow beyond a certain point
  • TempDB - a new
         option in Ax 2012. They are "physical" temporary tables held in
         the SQL Server database.

The new TempDB tables operate in a similar manner to InMemory
tables but support more features of standard physical tables:

  • More powerful
         joins with physical tables are possible, and are properly supported by the
         database
  • Can be
         per-company or global
  • Support for
         normal tts transactions

To create
a new instance link (populating data/copying reference) from one table instance
variable to the other with Temporary type tables:

Code Examples:

-
Open AOT/Data Dictonary/Tables

-
Create a New table, name it "TestTmp"

-
Expand it, create a new field of type string and name it "Id"

1)
InMemory:

- Set
the "TestTmp" table "TableType" property to
"InMemory", save

- Create
and run following job:

static void TestTmpInMemory(Args _args)

{

    TestTmp tmp1, tmp2;

    ;

    tmp1.Id = "1000";

    tmp1.insert();

 

    tmp2.setTmpData(tmp1);

 

    info("Table
type: " + enum2Str(tmp1.getTableType()));

 

    info("tmp1
data begin: ");

 

    while
select tmp1

        info("    Id " + tmp1.ID);

 

    info("tmp1
data end.");

    

    info("tmp2
data begin: ");

 

    while
select tmp2

        info("    Id " + tmp2.ID);

 

    info("tmp2
data end.");

}

 

2)
TempDB:

- Set
the "TestTmp" table "TableType” property to "TempDB",
save

- Create
and run following job:

static void TestTmpTempDB(Args _args)

{

    TestTmp tmp1, tmp2;

    ;

    tmp1.Id = "1000";

    tmp1.insert();

 

    tmp2.linkPhysicalTableInstance(tmp1);

 

    info("Table
type: " + enum2Str(tmp1.getTableType()));

 

    info("tmp1
data begin: ");

 

    while
select tmp1

        info("    Id " + tmp1.ID);

 

    info("tmp1
data end.");

   

    info("tmp2
data begin: ");

 

    while
select tmp2

        info("    Id " + tmp2.ID);

 

    info("tmp2
data end.");

}

 

Author: Mansour Yahya Mohammad

Date: 9/8-2012