while select with if 语句语法 - if 语句的目的是什么?
While select with if statement syntax - what is the purpose of the if statement?
我遇到了一种我以前在 x++ 中从未见过的奇怪语法,但它可以编译并工作(据我所知)。我很好奇是否有人以前看过或使用过它并且可以解释:一段时间内 if 语句的目的是什么 select?
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;
当你做 while select
时,通常你用 {}
来包装你的代码,但你也可以做与 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
,但在较新的代码中,我相信如果缓冲区是 returned 某些数据,它会计算为真。然而,在 while select
中,它将始终 return 为真,因为 select 仅在 return 为真时记录。
你 could/should 只需按字面删除 if (inventTrans)
行并保留括号,它将成为 readable/normal 代码。
我遇到了一种我以前在 x++ 中从未见过的奇怪语法,但它可以编译并工作(据我所知)。我很好奇是否有人以前看过或使用过它并且可以解释:一段时间内 if 语句的目的是什么 select?
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;
当你做 while select
时,通常你用 {}
来包装你的代码,但你也可以做与 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
,但在较新的代码中,我相信如果缓冲区是 returned 某些数据,它会计算为真。然而,在 while select
中,它将始终 return 为真,因为 select 仅在 return 为真时记录。
你 could/should 只需按字面删除 if (inventTrans)
行并保留括号,它将成为 readable/normal 代码。