07-31-2007 1:20 PM
Hi experts,
Kindly help very very urgent if i give sort itab(internal table) without mentioning fields in what basis the internal table will get sorted please very urgent
(Also, tell me the case when the table from which it is fetched doesn't contain any key fields)
please help
07-31-2007 1:40 PM
Hi,
SORT itab.
The entries in the internal table are sorted in ascending order using the key from the table definition (DATA, TYPES).
Reward if helpful.
07-31-2007 1:51 PM
Hi Madhangi,
SAP does not appreciate sort by table without giving any field name specifically.
because main purpose of sorting is reading this table later in program using binary search. if you are not giving any field name; if you are selecting with key fields then it will sort by key fields otherwise it will choose arbitarly.
Hope it will help you.
Regards,
Krishnendu
07-31-2007 3:02 PM
From the help for SORT:
The sort order depends on the sequence of the standard key fields in the internal table. The default key is made up of the non-numeric fields of the table line in the order in which they occur.
Rob
07-31-2007 3:20 PM
Hi,
You can sort a standard or hashed table in a program. To sort a table by its key, use the statement
SORT <itab> [ASCENDING|DESCENDING] [AS TEXT] [STABLE].
The statement sorts the internal table <itab> in ascending order by its key. The statement always applies to the table itself, not to the header line. The sort order depends on the sequence of the standard key fields in the internal table. The default key is made up of the non-numeric fields of the table line in the order in which they occur.
You can specify the direction of the sort using the additions ASCENDING and DESCENDING. <b>The default is ascending.</b>
Regards
Sudheer
07-31-2007 3:50 PM
Hi..
Plz check the code below.
data: begin of itab occurs 0,
f1(10) type c,
f2(10) type c,
end of itab.
itab-f1 = '3'.
itab-f2 = 'S'.
append itab.
itab-f1 = '2'.
itab-f2 = 'T'.
append itab.
itab-f1 = '4'.
itab-f2 = 'S'.
append itab.
itab-f1 = '4'.
itab-f2 = 'P'.
append itab.
itab-f1 = '2'.
itab-f2 = 'S'.
append itab.
loop at itab.
write:/ itab-f1, itab-f2.
endloop.
sort itab.
skip.
write:/ 'Sorted'.
loop at itab.
write:/ itab-f1, itab-f2.
endloop.
You can get from the code that.. if u dont specify fields for sorting then SORT staement sort the itab by all the fields ranging from first field to last field.
Output of the above code is :
3 S
2 T
4 S
4 P
2 S
Sorted
2 S
2 T
3 S
4 P
4 S
Reward if useful
Regards
Prax
08-01-2007 8:24 AM
Your statement sorts the ITAB by all the fields in the internal table.
Regards,
Pavan
08-01-2007 8:32 AM