Temporary Tables (AX 2012)
In Ax 2012, the Temporary property on tables was
replaced with a new property: TableType, which has three possible
values:
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:
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:
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
Open AOT/Data Dictonary/Tables
-
Create a New table, name it "TestTmp"
Create a New table, name it "TestTmp"
-
Expand it, create a new field of type string and name it "Id"
Expand it, create a new field of type string and name it "Id"
1)
InMemory:
InMemory:
- Set
the "TestTmp" table "TableType" property to
"InMemory", save
the "TestTmp" table "TableType" property to
"InMemory", save
- Create
and run following job:
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()));
type: " + enum2Str(tmp1.getTableType()));
info("tmp1
data begin: ");
data begin: ");
while
select tmp1
select tmp1
info(" Id " + tmp1.ID);
info("tmp1
data end.");
data end.");
info("tmp2
data begin: ");
data begin: ");
while
select tmp2
select tmp2
info(" Id " + tmp2.ID);
info("tmp2
data end.");
data end.");
}
2)
TempDB:
TempDB:
- Set
the "TestTmp" table "TableType” property to "TempDB",
save
the "TestTmp" table "TableType” property to "TempDB",
save
- Create
and run following job:
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()));
type: " + enum2Str(tmp1.getTableType()));
info("tmp1
data begin: ");
data begin: ");
while
select tmp1
select tmp1
info(" Id " + tmp1.ID);
info("tmp1
data end.");
data end.");
info("tmp2
data begin: ");
data begin: ");
while
select tmp2
select tmp2
info(" Id " + tmp2.ID);
info("tmp2
data end.");
data end.");
}
No comments:
Post a Comment