03-05-2008 12:26 PM
Hi all,
I have a scenario wherein i have to sort the internal table without using the sort function( i.e sort syntax).Is there any logic.
Can nebody pls help me out.
Regards
Jak
03-05-2008 12:29 PM
What's so strange about the scenario that you can't use the standard SORT command?
You could implement a sort algorithm yourself, but most times, even if the sort order is a bit odd, you can still use the SORT command, if you arrange the data correctly.
What's the scenario?
matt
03-05-2008 12:30 PM
U can code as normal buble sort machanism (like in c or c++)
Reward if useful
03-05-2008 1:12 PM
Hi narendra
Thankx for ur reply. Can u pls code me the buble sort logic.
regards
jak
03-05-2008 1:28 PM
Hai,
To understand bubble sort, think of an air bubble rising in water
To sort N items, N passes are made through the data.
The result of the first pass is that the smallest item is in the last location of the array.
The result of the second pass is that the second smallest item is in the second last location of the array.
etc.
After N passes, the entire array is sorted.
The operation in each pass is as follows:
First, the values in the first two locations are compared. If necessary the values are exchanged, so that the smaller one is last.
Then, the values in the second and third locations are compared. If necessary the values are exchanged, so that again the smaller one is last.
This process repeats to the end of the array.
In effect, the smaller item bubbles its way towards the top. It keeps on going until either it reaches the top (and the pass ends), or it strikes a smaller item. In that case it stops itself, and gives that smaller item a nudge to start it on its way.
If a complete pass is made without any exchanges being made, the data must already be sorted. This is easily checked. Thus it might be possible to halt the algorithm without going through all N passes.
03-05-2008 12:31 PM
03-05-2008 12:31 PM
Declare the internal table as sorted.
Refer to the below link for syntax:
http://help.sap.com/erp2005_ehp_03/helpdata/EN/fc/eb35de358411d1829f0000e829fbfe/frameset.htm
03-05-2008 12:33 PM
i cant think of any scenarion in which you can NOT use the SORT statement.
but well you can program e.G. a bubblesort algorithm yourself. Just be aware that a bubblesort is quite slow.
03-05-2008 12:33 PM
Hi,
SORT for Internal Tables
Sorts internal tables.
Syntax
SORT <itab> [ASCENDING|DESCENDING] [AS TEXT] [STABLE]
... BY <fi> [ASCENDING|DESCENDING] [AS TEXT]...
Sorts the internal table <itab>. If you omit the BY addition, the table is sorted by its key. You can define a different sort key by using the BY addition. The other additions specify whether you want to sort in ascending or descending order, and whether strings should be sorted alphabetically.
Regards,
Priya.
03-05-2008 2:00 PM
Hi,
I will sugest 2 solutions for u.
1. Use ORDER BY clause (Obsolete) in ur select.
2. Declare the internal table as TYPE SORTED TABLE OF.
Thanks,
Vinod.