Hello, mates.
I want to import an Excel file and update the Purchase Line Prices of a Purchase Order. to do that I get three columns from an Excel file (I know I can do it via DIXF. but I have preferred to do it with the import of an excel file)
Then with the following listing I am updating the lines. The problem is weird. sometimes it does it very fast and fine. sometimes it is extremely slow. I tried to debug that and I found that for the first 20 records, it does it very fast. but suddenly it sticks and does the rest one by one. each of them takes about one minute to update.
The problem is weird. sometimes it does it very fast and fine. sometimes it is extremely slow. I tried to debug that and I found that for the first 20 or 30 records, it does it very fast. but suddenly it slows down and does the rest one by one. each of them takes about one minute to update.
public static void main(Args _args)
{
Dialog dialog;
Filename filename;
DialogField dialogFilename;
container conFilter = ["Microsoft Excel 97-2003 Worksheet (.xls)" ,"*.xlsx"];
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
int row = 1; //Excel File has Header
int doneCntr=0;
LineNumber lineNumber;
PurchId purchId;
PurchPrice purchPrice;
PurchLine purchLine;
dialog = new dialog();
dialog.caption("select a file");
dialogFilename = dialog.addField(extendedTypeStr(FilenameOpen));
//To filter the files while selecting
dialog.filenameLookupFilter(conFilter);
dialog.run();
if(dialog.closedOk())
{
filename = dialogFileName.value();
application = SysExcelApplication::construct();
workbooks = application.workbooks();
//specify the file path that you want to read
filename = filename;
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error("File cannot be opened.");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
do
{
row++;
lineNumber = cells.item(row, 1).value().double();
purchId = cells.item(row, 2).value().bStr();
purchPrice = cells.item(row, 3).value().double();
type = cells.item(row+1, 1).value().variantType();
select forUpdate purchLine
where purchLine.PurchId == purchId
&& purchLine.LineNumber == lineNumber;
if (purchLine)
{
purchLine.PurchPrice = purchPrice;
purchLine.LineAmount = purchLine.PurchPrice * purchLine.QtyOrdered;
purchLine.update();
doneCntr++;
info(strFmt("Line Number %1 updated",lineNumber));
}
}
while (type != COMVariantType::VT_EMPTY);
application.quit();
}
info(strFmt("%1 item(s) out of %2 updated",doneCntr,row-1));
}
*This post is locked for comments
I have the same question (0)