2016-07-25 66 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