Hi
I have a run() method that populates a custom table which is used to populate a "cached" entity upon data management export. However, the class is running extremely slow (we have an immense amount of data), but I wanted to see if any of you guys have any ideas to improve performance of this method below. Any help is appreciated!
public void run()
{
ProjectAccountingDistribution projectAccountDistribution;
ReasonTableRef reasonTableRef;
VendTrans vendTrans;
VendSettlement vendSettlement,vendSettlementAmount;
ProjTable projTable;
LedgerJournalTrans ledgerJournalTrans;
VendInvoiceInfoTable vendInvoiceInfoTable;
GeneralJournalEntry generalJournalEntry;
GeneralJournalAccountEntry generalJournalAccountEntry;
CH_VendorInvoiceEntityCache vendorInvoiceEntityCache;
VendInvoiceJour vendInvoiceJour;
VendInvoiceTrans vendInvoiceTrans;
SourceDocumentLine sourceDocumentLine;
AccountingDistribution accountingDistribution;
PurchTable purchTable;
PurchAgreementHeader purchAgreementHeader;
delete_from vendorInvoiceEntityCache;
while select vendInvoiceJour
outer join vendInvoiceTrans
where vendInvoiceTrans.PurchID == vendInvoiceJour.PurchId
&& vendInvoiceTrans.InvoiceId == vendInvoiceJour.InvoiceId
&& vendInvoiceTrans.InvoiceDate == vendInvoiceJour.InvoiceDate
&& vendInvoiceTrans.numberSequenceGroup == vendInvoiceJour.numberSequenceGroup
&& vendInvoiceTrans.InternalInvoiceId == vendInvoiceJour.InternalInvoiceId
{
vendorInvoiceEntityCache.PurchId = vendInvoiceJour.PurchId;
vendorInvoiceEntityCache.InvoiceId = vendInvoiceJour.InvoiceId;
vendorInvoiceEntityCache.InvoiceAccount = vendInvoiceJour.InvoiceAccount;
vendorInvoiceEntityCache.InvoiceDate = vendInvoiceJour.InvoiceDate;
vendorInvoiceEntityCache.InvoiceAmount = vendInvoiceJour.InvoiceAmount;
vendorInvoiceEntityCache.CurrencyCode = vendInvoiceJour.CurrencyCode;
vendorInvoiceEntityCache.DueDate = vendInvoiceJour.DueDate;
vendorInvoiceEntityCache.LedgerVoucher = vendInvoiceJour.LedgerVoucher;
vendorInvoiceEntityCache.SumTax = vendInvoiceJour.SumTax;
select firstonly purchTable
where purchTable.PurchId == vendInvoiceJour.PurchId;
vendorInvoiceEntityCache.PurchAgreementId = (select PurchNumberSequence from purchAgreementHeader where purchAgreementHeader.RecId == purchTable.MatchingAgreement).PurchNumberSequence;
if(vendInvoiceJour.InvoiceAccount)
{
vendorInvoiceEntityCache.VendorName = VendTable::find(vendInvoiceJour.InvoiceAccount).name();
}
vendorInvoiceEntityCache.LineNum = vendInvoiceTrans.LineNum;
vendorInvoiceEntityCache.ItemId = vendInvoiceTrans.ItemId;
vendorInvoiceEntityCache.Qty = vendInvoiceTrans.Qty;
vendorInvoiceEntityCache.PurchPrice = vendInvoiceTrans.PurchPrice;
vendorInvoiceEntityCache.PurchUnit = vendInvoiceTrans.PurchUnit;
vendorInvoiceEntityCache.Name = vendInvoiceTrans.Name;
vendorInvoiceEntityCache.Tax1099Amount = vendInvoiceTrans.Tax1099Amount;
vendorInvoiceEntityCache.Tax1099State = vendInvoiceTrans.Tax1099State;
vendorInvoiceEntityCache.Tax1099StateAmount = vendInvoiceTrans.Tax1099StateAmount;
vendorInvoiceEntityCache.ProcuremetnCategoryName = EcoResCategory::find(vendInvoiceTrans.ProcurementCategory).Name;
reasonTableRef = ReasonTableRef::find(vendInvoiceTrans.ReasonTableRef);
vendorInvoiceEntityCache.ReasonCode = reasonTableRef.Reason;
vendorInvoiceEntityCache.ReasonComment = reasonTableRef.ReasonComment;
select firstonly sourceDocumentLine
where sourceDocumentLine.RecId == vendInvoiceTrans.SourceDocumentLine
join accountingDistribution
where accountingDistribution.SourceDocumentLine == sourceDocumentLine.RecId;
vendorInvoiceEntityCache.Number = accountingDistribution.Number;
if(accountingDistribution.LedgerDimension)
{
vendorInvoiceEntityCache.LedgerAccount = LedgerDimensionFacade::getDisplayValueForLedgerDimension(accountingDistribution.LedgerDimension);
}
else
{
select firstonly RecId,SubledgerVoucher from generalJournalEntry
join GeneralJournalEntry,LedgerDimension,PostingType from generalJournalAccountEntry
where generalJournalEntry.SubledgerVoucher == vendInvoiceJour.LedgerVoucher
&& generalJournalAccountEntry.GeneralJournalEntry == generalJournalEntry.RecId
&& generalJournalAccountEntry.PostingType == LedgerPostingType::LedgerJournal;
if(generalJournalEntry)
{
vendorInvoiceEntityCache.LedgerAccount = LedgerDimensionFacade::getDisplayValueForLedgerDimension(generalJournalAccountEntry.LedgerDimension);
}
}
select firstonly vendInvoiceInfoTable
where vendInvoiceInfoTable.Num == vendInvoiceJour.InvoiceId &&
vendInvoiceInfoTable.PurchId == vendInvoiceJour.PurchId &&
vendInvoiceInfoTable.ParmId == vendInvoiceJour.ParmId;
select firstonly Voucher,AccountNum,TransDate,PaymReference,RecId,DataAreaId from vendTrans
where vendTrans.Voucher == vendInvoiceJour.LedgerVoucher
&& vendTrans.AccountNum == vendInvoiceJour.InvoiceAccount
&& vendTrans.TransDate == vendInvoiceJour.InvoiceDate;
if(vendTrans)
{
vendorInvoiceEntityCache.PaymReference = vendTrans.PaymReference;
vendorInvoiceEntityCache.PaymentVoucher = vendTrans.Voucher;
select Txt from ledgerJournalTrans
where ledgerJournalTrans.VendTransId == vendTrans.RecId;
if(ledgerJournalTrans)
{
vendorInvoiceEntityCache.InvoiceDescription = ledgerJournalTrans.Txt;
vendorInvoiceEntityCache.LineAmount = vendInvoiceJour.InvoiceAmount;
}
else
{
vendorInvoiceEntityCache.InvoiceDescription = vendInvoiceInfoTable.Description;
vendorInvoiceEntityCache.LineAmount = vendInvoiceTrans.LineAmount;
}
}
else
{
vendorInvoiceEntityCache.InvoiceDescription = vendInvoiceInfoTable.Description;
vendorInvoiceEntityCache.LineAmount = vendInvoiceTrans.LineAmount;
}
select firstonly TransDate,TransCompany,TransRecId,AccountNum from vendSettlement
where vendSettlement.TransCompany == vendTrans.DataAreaId
&& vendSettlement.TransRecId == vendTrans.RecId
&& vendSettlement.AccountNum == vendTrans.AccountNum;
if(vendSettlement)
{
vendorInvoiceEntityCache.PaymentDate = vendSettlement.TransDate;
}
select firstonly vendSettlementAmount where vendSettlementAmount.OffsetTransVoucher == vendorInvoiceEntityCache.PaymentVoucher;
if(vendSettlementAmount)
{
vendorInvoiceEntityCache.SettleAmount = abs(vendSettlementAmount.SettleAmountCur);
}
select firstonly AccountingDistribution,TransactionCurrencyPrice,TransactionCurrencyAmount,ProjFundingSource from projectAccountDistribution where projectAccountDistribution.AccountingDistribution == accountingDistribution.RecId;
if(projectAccountDistribution)
{
select ProjId,RecId from projTable where projTable.RecId == projectAccountDistribution.ProjTable;
vendorInvoiceEntityCache.ProjectId = projTable.ProjId;
vendorInvoiceEntityCache.Category = ProjCategory::findRecId(projectAccountDistribution.ProjCategory).CategoryId;
vendorInvoiceEntityCache.FundingSouceId = ProjFundingSource::find(projectAccountDistribution.ProjFundingSource).FundingSourceId;
}
if(accountingDistribution.RecId)
{
vendorInvoiceEntityCache.TransactionCurrencyAmount = accountingDistribution.TransactionCurrencyAmount;
}
else
{
vendorInvoiceEntityCache.TransactionCurrencyAmount = vendInvoiceJour.InvoiceAmount;
}
vendorInvoiceEntityCache.insert();
}
}