Temporary Tables (AX 2012)
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 from 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 either the setTmpData() method
- For TempDB tables, the linkPhysicalTableInstance() method replaces the setTmpData() call.
Code Examples:
– Open AOT/Data Dictonaries/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. “);
}
1) 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. “);
}