Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

Using temporary tables for report speedup

Posted on by 5
Hello,

I am currently working on a complex report that processes a large amount of data (the report traverses the VAT Entry table), and I want to speed it up. For every data item in the report, I have to perform calculations that depend on data from a setup table. This "setup table" has multiple records (for each combination of VAT identifiers) but no more than about 100. My idea is to copy this setup table to a temporary table in the OnPreReport trigger and retrieve records from this temporary table, instead of reading from the database every time. Is this a good idea?

trigger OnPreReport()
var
    _VATReportView: Record VatReportView;
begin
    _VATReportView.SetRange(Type, TempVatReportView.Type::Sales);
    if _VATReportView.FindSet() then
        repeat
            TempVatReportView.Init();
            TempVatReportView.TransferFields(_VATReportView);
            TempVatReportView.Insert(false);
        until _VATReportView.Next() = 0;
end;
 
Other thing that is bothering me is what would be the best practice for reading data form temporary table multiple times (for each data item)? Does FindSet works as expected?
 
trigger OnAfterGetRecord()
begin
    // Should I Use TempVatReportView.Reset here?
    TempVatReportView.SetRange(FieldA, Dataitem.ColumnA);
    if TempVatReportView.FindSet() then
        repeat
            // ....
        untill TempVatReportView.Next() = 0;
end
  • Suggested answer
    Yi Yong Profile Picture
    Yi Yong 1,390 Super User 2024 Season 2 on at
    Using temporary tables for report speedup
    Hello,
     
    Does this setup table have frequent changes or does the calculation change from time to time?
    If not, it might be better off to calculate and insert the calculated value into the VAT Entry table when posting.
     
     
    From the MS Learn, you should use FindSet when using Repeat.
     
    If you are not modifying the record, then it is better to use FindSet(false).

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans