Axapta 使用if语句语法选择时-if语句的用途是什么?
我遇到了一种奇怪的语法,这是我以前在x++中从未见过的,但它可以编译并工作(据我所知)。我很好奇是否有人以前见过或使用过它,并且可以解释:在whileselect的上下文中,if语句的目的是什么Axapta 使用if语句语法选择时-if语句的用途是什么?,axapta,x++,dynamics-365-operations,Axapta,X++,Dynamics 365 Operations,我遇到了一种奇怪的语法,这是我以前在x++中从未见过的,但它可以编译并工作(据我所知)。我很好奇是否有人以前见过或使用过它,并且可以解释:在whileselect的上下文中,if语句的目的是什么 InventBatch inventBatch; InventTrans inventTrans; InventTransOrigin inventTransOrigin; InventDim inventDim; ttsBegin; while select Qty, DatePhysical f
InventBatch inventBatch;
InventTrans inventTrans;
InventTransOrigin inventTransOrigin;
InventDim inventDim;
ttsBegin;
while select Qty, DatePhysical from inventTrans
where inventTrans.StatusReceipt == StatusReceipt::Arrived
join inventTransOrigin
where inventTransOrigin.RecId == inventTrans.InventTransOrigin
&& inventTransOrigin.InventTransId == "SomeIdFromSomewhere"
join inventDim
where inventDim.inventDimId == inventTrans.inventDimId
&& inventDim.inventBatchId
if (inventTrans)
{
inventBatch = InventBatch::find(inventDim.inventBatchId, inventTrans.ItemId, true);
inventBatch.Field1 = inventTrans.Qty;
inventBatch.Field2 = inventTrans.DatePhysical;
inventBatch.update();
}
ttsCommit;
当您在选择的同时执行一个
时,通常您会放置{}
来包装您的代码,但是如果您省略了{}
语句,并且为每个循环执行立即进行的行,您也可以执行与if
语句相同的操作
if (true)
info("Hello World");
if (true)
{
info("Hello World");
}
while select SalesTable
info(SalesTable.SalesId);
while select SalesTable
{
info(SalesTable.SalesId);
}
关于上面键入的代码,这是愚蠢的。在AX中,在旧版本的代码中,if(common)
通常只计算common.RecId!=0
,但在后面的例子中,我相信如果缓冲区返回一些数据,它将计算为true。但是,在while select中,它将始终返回true,因为select仅在为true时返回记录
您可以/应该只删除if(inventTrans)
行,并保留括号,这样它将是可读的/普通的代码。当我遇到代码时,我的直觉是“这似乎很愚蠢”,所以我很高兴看到我的直觉并不遥远:)