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;
Answers
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.
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-al
I don't really understand how to use temporary instance of integer table?Could you ,please ,provide sample code?
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.
Thanks for providing the sample code.