Create Temporary table with dynamic fields?
 
            
                
                    KeeperRU                
                
                    Member Posts: 58                
            
                        
            
                    Which is the best method to create your own virtual structures like tables?
I create physical tables with fields like: CodeField1 (Text 250), Codefield2 (Text 250)....., DecimalField1....
This works great, but code hard to maintain in a long-term. There are always not enough fields or keys.. because I have much tasks with Buffers.
For example:
Then:
Maybe XML, DotNet list, etc.? Need some link with best practices.
Method should be really fast, with sorting, filtering, etc.
                I create physical tables with fields like: CodeField1 (Text 250), Codefield2 (Text 250)....., DecimalField1....
This works great, but code hard to maintain in a long-term. There are always not enough fields or keys.. because I have much tasks with Buffers.
For example:
IF Item.FINDSET THEN
REPEAT
  IF NOT TempTable.GET(Item.Type, Item.Location) THEN BEGIN
    TempTable.CodeField1 := Item.Type; //KEY
    TempTable.CodeField2 := Item.Location; //KEY
    TempTable.INSERT
  END;
  
  TempTable.DecimalField1 += Item.GetLocationAmount();
  ...
  TempTable.DecimalField15 += Item.GetLocationQuantity();
  TempTable.MODIFY;	
UNTIL (Item.NEXT = 0);
Then:
TempTable.SETCURRENTKEY(DecimalField1); IF TempTable.FINDSET THEN REPEAT ExcelBuffer.AddCell(RowNo, ColNo, TempTable.DecimalField1); .. ExcelBuffer.AddCell(RowNo, ColNo+14, TempTable.DecimalField15); RowNo +=1; UNTIL (TempTable.NEXT = 0);
Maybe XML, DotNet list, etc.? Need some link with best practices.
Method should be really fast, with sorting, filtering, etc.
0                
            Best Answer
- 
            Hi,
 I think the better solution is temporary tables.
 With XML will be slowest and more difficult to sort.
 With .Net structures sort and filter will need more code.
 I use temporary tables with a little twist. My keys are Text(250).
 In your example my key should be
 TempTable.SETRANGE(TextKey1,
 '##!' + Item.Type + '!##!' + Item.Location + '!##');
 IF NOT TempTable.FINDFIRST THEN
 TempTable.TextKey1 :=
 '##!' + Item.Type + '!##!' + Item.Location + '!##';
 If the order should be Location,Type I change the order when writting TextKey1.
 To be a little more organized and readable I use a private function to get this key, like this:
 LOCAL GetFilter<YourMeaningText> (Record Item) : Text(250)
 MyFilter := '##!' ;
 IF Item.Type = '' THEN
 MyFilter += 'null'
 ELSE
 MyFilter += Item.Type;
 MyFilter += '!##!';
 ....
 EXIT(MyFilter);
 TempTable.SETRANGE(TextKey1, GetFilter<YourMeaningText>(Item));
 IF NOT TempTable.FINDFIRST THEN
 TempTable.TextKey1 := , GetFilter<YourMeaningText>(Item);
 Regards,
 parm5
Answers
- 
            Hi,
 I think the better solution is temporary tables.
 With XML will be slowest and more difficult to sort.
 With .Net structures sort and filter will need more code.
 I use temporary tables with a little twist. My keys are Text(250).
 In your example my key should be
 TempTable.SETRANGE(TextKey1,
 '##!' + Item.Type + '!##!' + Item.Location + '!##');
 IF NOT TempTable.FINDFIRST THEN
 TempTable.TextKey1 :=
 '##!' + Item.Type + '!##!' + Item.Location + '!##';
 If the order should be Location,Type I change the order when writting TextKey1.
 To be a little more organized and readable I use a private function to get this key, like this:
 LOCAL GetFilter<YourMeaningText> (Record Item) : Text(250)
 MyFilter := '##!' ;
 IF Item.Type = '' THEN
 MyFilter += 'null'
 ELSE
 MyFilter += Item.Type;
 MyFilter += '!##!';
 ....
 EXIT(MyFilter);
 TempTable.SETRANGE(TextKey1, GetFilter<YourMeaningText>(Item));
 IF NOT TempTable.FINDFIRST THEN
 TempTable.TextKey1 := , GetFilter<YourMeaningText>(Item);
 Regards,
 parm5
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 322 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
