2016-07-25 46 views
1

我創造,我的數據導出到CSV文件的方法,我創建了下面的代碼:雙記錄導出數據時,以CSV

public void export() 
{ 

    permission = new FileIOPermission(fileNameValue, #io_WRITE); 
    permission.assert(); 

    inFile = new CommaTextIo(fileNameValue, #io_WRITE); 
    inFile.inFieldDelimiter(";"); 
    inFile.inRecordDelimiter("\n"); 

    while (inFile.status() == IO_Status::Ok) 

    while select inventTrans 
    where inventTrans.StatusIssue == StatusIssue::ReservPhysical 
    join inventDim 
    where inventDim.InventLocationId == inventLocationId 
    join inventTransOrg 
    where inventTransOrg.RecId == inventTrans.InventTransOrg 

    { 

    con = conNull(); 

     con = conIns(con, 1, inventTransOrg.inventTransId); 
     con = conIns(con, 2, inventLocationId); 
     con = conIns(con, 3, inventTrans.Qty); 

     inFile.writeExp(con); 
} 
} 

這將創建一個CSV 3列文件,但很多的雙記錄(接近100)實際數據不包含100條雙記錄。任何建議如何我可以重建出口,以避免雙記錄?

+0

你想出口什麼? while選擇看起來像您對某個庫存位置的物理保留感興趣,這是否正確?你能否告訴我們Dynamics AX的版本?並且請包含變量定義使其成爲[mcve]。第一個while循環看起來很可疑,不會導致無限循環嗎?一些額外的縮進也會使代碼更易於閱讀。 –

回答

1

錯誤在於您沒有將Inventdim表與其他表加入。所以它會導致交叉連接。所以改變你的while語句以包含它。我的建議是添加字段列表,因爲InventTrans將有很多字段並且具有更好的性能,所以建議有選擇語句的字段列表。 您也可以嘗試使用以下語句。

While select inventTransId from inventTransOrg join Qty from inventTrans where inventTrans.InventTransOrg = inventTransOrg.RecId join inventLocationId from inventDim where inventDim.InventDimId == inventTrans.InventDimId && inventDim.InventLocationId == inventLocationId

4

您的連接會產生「重複」,例如,你加入inventDim通過inventLocationId結果可能在多個記錄中,因此你的inventTrans對於每個記錄都是「重複」的。
重新評估您的查詢以解決您的問題;您可能想要更改的一件事是通過InventDimId鏈接到InventDim

您的問題與CSV導出代碼無關,因爲您可以很輕鬆地看到是否將輸出的CSV文件操作替換爲infolog