Temporary table applied in Dynamics AX 2009

Flexible application of the temporary table in Dynamics AX 2009

Such as applied to Query ,Reports , Form ,Analyzed and fetch data and so on.

Wrote by Jimmy on April 27th 2011

static void Jimmy_TempTableAppy(Args _args)
{
Query q
= new Query();
QueryRun qr;
QueryBuildDataSource qbds;
Temp_ProdOrderConsumpSummaryReport temprecords;

Temp_ProdOrderConsumpSummaryReport tmpTableRec()
{
InventTable InventTable;
Temp_ProdOrderConsumpSummaryReport tmpTable;
int i;
;

while select InventTable
{
i
++;
tmpTable.ItemId
= InventTable.ItemId;
tmpTable.insert();
if(i > 10)
break;
}
return tmpTable;

}
;
qbds
= q.addDataSource(tableNum(Temp_ProdOrderConsumpSummaryReport));
qbds.addRange(FieldNum(Temp_ProdOrderConsumpSummaryReport,ItemId)).value(
"10-1000");
qr
= new QueryRun(q);
qr.setRecord(tmpTableRec());
//this statement is the key
//qr.setCursor(tmpTableRec());//setCursor or setCursor method
while(qr.next())
{
temprecords
= qr.getNo(1);
info(temprecords.ItemId);
..............
}

/**------------------------------
*/

//1,将已经有的表临时化 Table.setTmp()

InventTable inventTable;
InventTable inventTableTmp;
;
inventTableTmp.setTmp();
while select inventTable
{
inventTableTmp.data(inventTable.data());
inventTableTmp.doInsert();
}

//2,用临时表做FORM的Datasouce,重载该Datasource的init();

public void init()
{
super();

TempTable.setTmpData(tmpTableClass::populateTmpData());
}

//3,临时表 与 Query,例如在报表中做DataSource

this.queryRun().setRecord(tmpTable);

}
posted @ 2011-04-27 14:53  Fandy Xie  Views(950)  Comments(0Edit  收藏  举报