Using a counting jurnal ..
Use some code from here
.....................................................................................
void run()
{
SysOperationProgress progress = new SysOperationProgress();
counter counter = 0;
LineNum lineNum = 0;
counter progressCounter = 0;
boolean found = false;
str Prod_cd;
int End_Inv;
InventJournalTable inventjournalTable;
InventJournalTrans inventjournalTrans;
InventJournalName inventjournalName;
InventDim inventDim;
InventTableModule inventtableModule;
InventDimCombination inventdimCombination;
InventTable inventTable;
InventJournalVoucherSeqId voucherSeq;
Voucher voucher;
NumberSeq numberSeq;
JournalFormTrans journalformTrans;
Filename fileName;
container files,inRecord;
ItemID itemid;
InventJournalId journalid;
CommaIO commaIO;
Dialog _dialog;
DialogField _dialogFieldFileName;
DialogField _dialogFieldJournal;
DialogField _dialogFieldInventDate;
DialogField _dialogFieldPlant;
InventLocationId plant;
TransDate InventDate;
DialogField _dialogSkipFirstLine;
;
_dialog = new Dialog('Upload I');
_dialogFieldInventDate = _dialog.addField(typeId(TransDate),
'Transaction date');
_dialogFieldPlant = _dialog.addField(typeId(InventLocationId),
'Plant');
_dialogFieldFileName = _dialog.addField(typeId(FileNameOpen), 'File
name', 'Filename containing input data');
_dialogSkipFirstLine = _dialog.addField(typeId(boolean), 'Skip First
Line', 'SkipFirstLine');
_dialogFieldFileName.lookupButton(2);
_dialogFieldInventDate.value(Today());
_dialogSkipFirstLine.value(true);
if (_dialog.run())
{
fileName = _dialogFieldFileName.value();
inventDate = _dialogFieldInventDate.value();
plant = _dialogFieldPlant.value();
if(fileName == '' || inventDate == dateNull() || plant == '' )
{
info(strfmt('Select a file name, date and plant'));
return;
}
commaIO = new CommaIO(fileName, 'r');
inRecord = commaIO.read();
progress.setCaption("Loading");
progress.setAnimation(#AviUpdate);
journalid = inventjournalTable.JournalId;
lineNum = inventjournalTrans::lastLineNum(journalid);
voucherSeq = inventjournalTable.VoucherSeqId;
numberSeq = NumberSeq::newGetVoucherFromCode(voucherSeq,
true);
voucher = numberSeq.voucher();
ttsbegin;
while (!commaIO.status())
{
counter++;
lineNum++;
if (counter==1)
{
inRecord = commaIO.read();
continue;
}
itemid =
strlrtrim(strrem(conPeek(inRecord, 1), "\""));
inventjournalTrans.TransDate = inventDate;
inventjournalTrans.JournalId = inventjournalTable.JournalId;
inventjournalTrans.LineNum = lineNum;
inventjournalTrans.Counted =str2num(strrem(conPeek(inRecord,
18), "\""));
inventjournalTrans.Qty = str2num(strrem(conPeek(inRecord, 18),
"\""));
inventjournalTrans.ItemId = itemid;
if(inventtable::exist(itemid) == 0)
{
info(strfmt('%1 does not exist in product table', itemid));
inventjournalTrans.clear();
inventDim.clear();
inventtableModule.clear();
inRecord = commaIO.read();
progressCounter++;
progress.setCount(progressCounter);
continue;
}
inventjournalTrans.Dimension[1]='01';
inventjournalTrans.Dimension[2]='150';
inventjournalTrans.PriceUnit = 1.0;
inventjournalTrans.Voucher = voucher;
inventDim.InventLocationId = plant;
inventDim.WMSLocationId=strrem(conPeek(inRecord, 22), "\"");
inventDim = inventDim::findOrCreate(inventDim);
inventjournalTrans.InventDimId = inventDim.inventDimId;
inventtableModule.ItemId = itemid;
inventtableModule.ModuleType = ModuleInventPurchSales::Invent;
inventjournalTrans.setCostPrice(inventjournalTrans.InventDimId,
inventDim, inventtableModule, inventdimcombination);
inventjournalTrans.LedgerAccountIdOffset =
inventjournalTable.LedgerAccountIdOffset;
inventjournalTrans.insert();
inventjournalTrans.clear();
inventDim.clear();
inventtableModule.clear();
inRecord = commaIO.read();
progressCounter++;
progress.setCount(progressCounter);
}
ttscommit;
}
}
"Hugo" <Hugo@discussions.microsoft.com> wrote in message
news:374FF121-DB49-4101-9E3A-B3C678241C6F@microsoft.com...
|