Is there any way to sort Integer Dimensions?

vinceliu666
Member Posts: 51
I use an Integer Dimensions and I want to sort dimensions value from small to big. Is there any way to do ? Just like ArrayList.Sort() in C#.
0
Best Answers
-
Depends on where exactly you want to achieve what exactly.
Basically, the answer is: You need to add an integer field to the table and a sort key on that field; or else you need to create a list somewhere, sort that list and then retrieve the dimension records based on that list.5 -
You can do something like
VAR DimensionValue : Record 349; PROCEDURE ProcessDimSorted(); VAR IntegerTemp : TEMPORARY Record 2000000026; BEGIN IF DimensionValue.FINDSET THEN REPEAT EVALUATE(IntegerTemp.Number,DimensionValue.Code); IF IntegerTemp.INSERT THEN; UNTIL DimensionValue.NEXT = 0; IntegerTemp.FINDSET; REPEAT DimensionValue.SETRANGE(Code,FORMAT(IntegerTemp,0,9)); // type 9 to avoid thousands separators DimensionValue.FINDSET; REPEAT // Process(DimensionValue); UNTIL DimensionValue.NEXT = 0; UNTIL IntegerTemp.NEXT = 0; IntegerTemp.DELETALL; END;
The first REPEAT loop populates the temporary integer table, the second retrieves entries from the table in sorted order.
EVALUATE and FORMAT are used to convert between Integer and Code in both directions.
This solution depends on the codes not having leading zeros. Also empty codes are not supported.5
Answers
-
Depends on where exactly you want to achieve what exactly.
Basically, the answer is: You need to add an integer field to the table and a sort key on that field; or else you need to create a list somewhere, sort that list and then retrieve the dimension records based on that list.5 -
Hi Vaprog:
Thanks for your relpy. Finally, I found an article to solve it by using bubble sort.
https://community.dynamics.com/nav/b/technicalfindingsindynamicsnav/posts/bubble-sort-in-c-al0 -
Why don't you use a temporary instance of Integer table? This avoids having to decide on an arbitrarily sized array, you do not have to implement a sorting algorithm, and it is probably faster anyway.0
-
Hi vaprog:
I don't really understand how to use temporary instance of integer table?Could you ,please ,provide sample code?0 -
You can do something like
VAR DimensionValue : Record 349; PROCEDURE ProcessDimSorted(); VAR IntegerTemp : TEMPORARY Record 2000000026; BEGIN IF DimensionValue.FINDSET THEN REPEAT EVALUATE(IntegerTemp.Number,DimensionValue.Code); IF IntegerTemp.INSERT THEN; UNTIL DimensionValue.NEXT = 0; IntegerTemp.FINDSET; REPEAT DimensionValue.SETRANGE(Code,FORMAT(IntegerTemp,0,9)); // type 9 to avoid thousands separators DimensionValue.FINDSET; REPEAT // Process(DimensionValue); UNTIL DimensionValue.NEXT = 0; UNTIL IntegerTemp.NEXT = 0; IntegerTemp.DELETALL; END;
The first REPEAT loop populates the temporary integer table, the second retrieves entries from the table in sorted order.
EVALUATE and FORMAT are used to convert between Integer and Code in both directions.
This solution depends on the codes not having leading zeros. Also empty codes are not supported.5 -
Hi vaprog :
Thanks for providing the sample code.0
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
- 320 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