Wednesday 18 December 2013

Temporary Tables (AX 2012)

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 -128KB

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:

For InMemory
     Tables, by using the setTmpData() method
For TempDB
     Tables, the linkPhysicalTableInstance() method replaces the setTmpData() call.

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("Tabletype: " + enum2Str(tmp1.getTableType()));
    info("tmp1data begin: ");
    while select tmp1
        info("    Id " + tmp1.ID);
        info("tmp1data end.");
        info("tmp2data begin: ");
    while select tmp2
        info("Id " + tmp2.ID);
        info("tmp2data 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("Tabletype: " + enum2Str(tmp1.getTableType()));
    info("tmp1data begin: ");
    while select tmp1
        info("    Id " + tmp1.ID);
        info("tmp1data end.");
        info("tmp2data begin: ");
    while select tmp2
        info("Id " + tmp2.ID);
        info("tmp2data end.");
}

1 comment: