‎2007 Mar 01 5:31 AM
Hi all,
In SORT BY F1 F2 F3... statement although the sort is done using F1 field what is the use of F2 ,F3..?
‎2007 Mar 01 5:35 AM
It is not sorted by field F1 only, the table is sorted by sequence of fields F1, F2 and F3.
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3800358411d1829f0000e829fbfe/frameset.htm
‎2007 Mar 01 5:36 AM
Hi,
If you wants to do any operations on F2 and f3 using control break statments it will be useful
Example:
Sort itab by F1 F2 f3.
Loop at itab.
at new F1.
Do something and..Write something
at end of F1.
at new F2
Do something and..Write something
at end of F2.
at new F3.
Do something and..Write something
at end of F3.
endloop.
Hope you understood.
Regards,
Anji
‎2007 Mar 01 5:38 AM
Hi,
If u just specify
SORT itab by F1, it will sort based on F1 alone.
Say if u
SORT itab by serialno DATE.
It will sort first based on number then Date.
U can try this out using a sample code.
Reward if this helsp.
‎2007 Mar 01 5:38 AM
Hi
Here I will give you one example try to understand the scenario...
let us take you have an internal table with two fields. WERKS, for the site, and ERZET, for time counts were created. ERZET will either have a valid time or be blank (article wasn't counted). You need the earliest time brought to the top of the internal table for each site, but not the blank.
If You sort descending by WERKS ERZET You will get the latest ERZET by site. If You sort ascending by WERKS ERZET you will get the blank ERZET by site.
So based on the above scenario you r sorting based on two fields, even though you can sort with one filed the results would be different from the sorting with two fileds. First of all you will sort with one filed then sort with the second file and third field... So the out put will be different..
here is the piece of code for the above requirement
itab2[] = itab1[].
delete itab2 where ERZET is initial.
sort itab2 ascending by WERKS ERZET.
~~Guduri.
‎2007 Mar 01 5:40 AM
hi Prashanth,
suppose u hav an internal table with these three fields and you want to sort it using f1 f2 and f3.
this means that the internal table will be sorted first by F1 then F2 and then F3 but here f3 values are dependent on f2 values and f2 on f1. Sort itab by f1 f2 f3 will fetch the relevant values or the order of fields on the output list will be f1 f2 and f3.
regards,
shamim
‎2007 Mar 01 5:41 AM
Hi..
This statement determined the sort order f1, f2, fn (upto 250)..
It will sort according to this order , instead of the default tabke key.
Siddhi
‎2007 Mar 01 5:46 AM
Hi
Let us do it with an example.
We have a internal table itab consists of 3 fields - Name,Age, TotalIncome.
If we sort the the itab by Name Age Totalincome.
The data is first sorted by Name in alphabetic order and the age & Lastly by the Totalincome.
Suppose the data in itab is
sreejesh 30 320000
harsha 28 4500
vijay 45 8000
avinash 90 120000
After sorting
avinash 90 120000
harsha 28 4500
sreejesh 30 320000
vijay 45 8000
‎2007 Mar 01 5:51 AM
Prasanth,
EX :
F1 F2 F3
A 1 101
A 2 102
A 1 103
A 1 102
B 1 101
A 2 101
If you sort by F1 only records will be
F1 F2 F3
A 1 101
A 2 102
A 1 103
A 1 102
A 2 101
B 1 101
If you sort by F1 F2 F3 only records will be
F1 F2 F3
A 1 101
A 1 102
A 1 103
A 2 101
A 2 102
B 1 101
See the order .
Pls. mark if useful