‎2008 Mar 22 5:02 PM
hi friends,
Could u plz tell me what is the purpose of using SORT statement before the loop statement??????
thanks in advance.
regards,
Priya.S
‎2008 Mar 22 5:16 PM
Dear Priya,
Sorting before looping is important ....take for eg that u will be sorting u r internal table by VBELN..
Now in u r internal table all u r VBELN will be one below the other..
Suppose inside the loop u use AT END OF VBELN event...
and if u have not sorted it then this event will get trigggered even though it should not as u wont desire it..
This is just an eg.
c if this helps you
‎2008 Mar 22 6:01 PM
Hi,
By using sort statement, accessing the data from the internal will be fast, by this performance will be improved.
Thanks,
Sriram Ponna.
‎2008 Mar 22 6:57 PM
Hi Priya
in ABAP editor, on statement SORT, you may press F1.
Remaining questions to be posted here.
Regards,
Clemens
‎2008 Mar 22 8:47 PM
Hi Priya,
Mainly sort statement is used to increase the performance of the program.
It is must if we are going to use the Read statement with binary search.
It shole be used whenever we use control break statements like AT FIRST , AT LAST etc.
Regards,
Viveks
‎2008 Mar 23 4:53 AM
Hi Priya,
When ever we select data from data base table to internal table it may/maynot come in sorted order by primary keys of the table. Same SELECT Query may return different order of records for different executions.To ensure that our records in internal table are in proper order before using them we will use the statement SORT. Also if u want to arrange the records of the internal table based on non primary keys or combination of primary and nonprimary keys then we will use sort statement.
Take an example. U have been given a bunch of papers
having page numbers on each paper and u need to find some
page having page number 123. IF ur bunch is not arranged as
per the page number then it will be very difficult for u to find
out where page 123 will be. But if it is sorted by page number
and given then u can easily locate the page by searching the
pages in between 100-150.
SORT plays an important role when u are using
READ TABLE WITH BINARY SEARCH. Never Read an internal table with out binary search if ur table has more than 100 records. It will degrade the performance a lot. And it is mandatory to sort the internal table by the same fields which are used in READ TABLE WITH KEY addition. Also BINARY SEARCH Will not work if u sort the table by descending order.
Coming to sorting table before loop, If u are using any AT events in the loop like AT NEW, AT END OF etc then it is mandatory to sort the internal table by the field used in the AT EVENT.
Hope this clarified ur doubts.
Thanks,
Vinod.
‎2008 Mar 23 7:49 AM
Hi,
By using sort before going to loop the internal table is
it uses BINARY SEARCH instead of linear search for accessing the data.
if ur internal table having 16 records without sorting it takes around 16 searches to find ur need.
if ur internal table is sorted it uses 4 searches to find ur need.
it raises the performance of ur access to internal tables.
Edited by: Angi Reddy Somala on Mar 23, 2008 8:49 AM
‎2008 Mar 23 10:42 AM
Hi,
sort with key is a must for the read table with key binary search statement.
and also for control break statements to get the correct results sort above the loop is a must.
sort is a must for the loop at where clause.
and also if you use sort the performance will be better.
Reward.