我正在安装AX 2009。工作是更新WMSOrderTrans表。这是我到目前为止所得到的:
WMSOrderTrans wmsOrderTrans;
;
while select wmsOrderTrans
{
if (wmsOrderTrans.BBBpackingSlipExists())
{
ttsBegin;
wmsOrderTrans.selectForUpdate(true);
wmsOrderTrans.BBBPackingSlipExists = NoYes::Yes;
wmsOrderTrans.doUpdate();
ttsCommit;
}
}
这项工作大约需要一个小时才能完成测试系统。这让我担心生产系统上的性能。
目前代码编写的这一点具有最小的锁定问题(如果应该更新并且立即提交,则为每一行执行selectForUpdate)。原因是,当作业运行时,用户将在系统上工作。
我的问题是,如果有合理的方式以较少的交易开销实现这项工作。
while select forUpdate ...
...似乎不是一个选项,因为它会锁定表,直到作业完成。
赞赏任何意见。
这是BBBPackingSlipExists方法的代码:
display boolean BBBpackingSlipExists()
{
InventDim inventDimCur;
InventDim inventDimPackSlip;
InventTrans inventTransPackSlip;
;
select firstonly RecId from inventTransPackSlip
where inventTransPackSlip.InventTransId == this.inventTransId
&& (inventTransPackSlip.StatusIssue == StatusIssue::Deducted
|| inventTransPackSlip.StatusIssue == StatusIssue::Sold)
&& !inventTransPackSlip.PackingSlipReturned
exists join inventDimCur
where inventDimCur.inventDimId == this.inventDimId
exists join inventDimPackSlip
where inventDimPackSlip.inventDimId == inventTransPackSlip.inventDimId
&& inventDimCur.inventSerialId == inventDimPackSlip.inventSerialId
;
if (inventTransPackSlip.RecId != 0 && this.isReserved)
{
return true;
}
return false;
}
答案 0 :(得分:12)
这看起来像是转换为set based logic的主要候选人,我会选择这样的东西。请注意,由于我没有2009环境(这甚至不能在2012年编译),因此该作业根本没有经过测试,因此如果您需要更改代码,请随意将其编辑到我的答案中。
请注意,isreserved check是内置在查询中的,以及packingslipexists方法中的exists连接
static void Job250(Args _args)
{
WMSOrderTrans wmsOrderTrans;
InventDim inventDimCur;
InventDim inventDimPackSlip;
InventTrans inventTransPackSlip;
;
wmsOrderTrans.skipDatabaseLog(true);
wmsOrderTrans.skipDataMethods(true);
wmsOrderTrans.skipEvents(true);
update_recordset wmsOrderTrans setting BBBPackingSlipExists = NoYes::Yes
where wmsOrderTrans.isReserved
exists join inventTransPackSlip
where inventTransPackSlip.InventTransId == wmsOrderTrans.inventTransId
&& (inventTransPackSlip.StatusIssue == StatusIssue::Deducted
|| inventTransPackSlip.StatusIssue == StatusIssue::Sold)
&& !inventTransPackSlip.PackingSlipReturned
exists join inventDimCur
where inventDimCur.inventDimId == wmsOrderTrans.inventDimId
exists join inventDimPackSlip
where inventDimPackSlip.inventDimId == inventTransPackSlip.inventDimId
&& inventDimCur.inventSerialId == inventDimPackSlip.inventSerialId;
}
的原因