‎2008 Dec 04 5:19 AM
Hi,
I have a sorted table and want to read it in a sequence.
Say for example:
Table: sort by secondary key field2, non unique
Field1 Field2
10 100
20 100
30 100
Now, when i read the table with the secondray key, field2, I wnat that it should always return the data in same sequence i. e. 100, 200, 300
But currently when the sequence is not maintained liek it can be 100, 200, 300 or 200, 100, 300
Is it posisble that I get the same sequence every time.
Thanks & Regards,
Rupali Ray
‎2008 Dec 04 5:23 AM
If it is a sorted table, u will always get data in same sequence what ever is the state of ur program.
System will take care that sorting sequence is always maintained.
‎2008 Dec 04 5:23 AM
If it is a sorted table, u will always get data in same sequence what ever is the state of ur program.
System will take care that sorting sequence is always maintained.
‎2008 Dec 04 5:31 AM
If you want to sort according to field2 than change the columns position in your internal table than you will always get 100 200 300 all the time.
like field2 field1 .
‎2008 Dec 04 9:19 AM
Hi,
Correction in the question:
Say for example:
Table: sort by secondary key field2, non unique
Field1 Field2
10 100
20 100
30 100
Now, when i read the table with the secondray key, field2 as 100, I want that it should always return the data in same sequence i. e. 10, 20, 30
But currently the sequence is not maintained like it can be 10, 20, 30 or 20, 10, 30
Is it posisble that I get the same sequence every time.
‎2008 Dec 04 9:24 AM
Hi Rupali,
Take the help of KEY word STABLE SORT
for more info please go through the KEY word docu
Regards
Ramchander Rao.K
‎2008 Dec 04 10:09 AM
Hi,
you can then sort it by both the keys!!
first sort it by Field2 then field1 as
sort <int_tab> by field2 field1....
it will be in the desired seq.
Regards,
Neha
‎2008 Dec 04 10:23 AM
Hi,
stable sort is (in general) used for something different:
If you do a sort on a set of elements and some of these elements are equal regarding the sort function then the elements appear after the sort in the same order as before.
E.g.:
Set of tupels {(3,3), (3,1), (1,1), (2,2)}
Sort function: Sort tuples ascending regarding only the first element
Result (stable):
{(1,1), (2,2), (3,3), (3,1)}
Tupels (3,1) and (3,3) are equal regarding the first element.
In the case Rupali describes, there is no sort statement but a secondary key. I guess (I am not sure), that the secondary key index is not built with respect to a stable sort order based on the order of the primary key.
Regards,
Torsten
‎2008 Dec 04 10:30 AM
Hi,
i really didn't realize that, Thanks for reminding me the basics.
Regards
Ramchander Rao.K
‎2008 Dec 04 10:38 AM
‎2008 Dec 04 11:54 AM
Hi,
My issue is still not solved. The table is already sorted, so no point in using sort stable.
Can anyone please let me know how can the issue be solved.
Thanks & Regards,
Rupali Ray
‎2008 Dec 04 12:02 PM
Hi,
When you sort the table sort that table using the two fields that to in ascending order..
this will make the internal table records in sequence like
field1 field2
10 100
20 100
30 100
10 200
20 200
30 200
Now whilw reading the table using the key 2 as 100 or 200 the value of field1 will be in sequence as desired.
ie.... field1 field2
10 100
20 100
30 100
Hope this will help.
Regards,
Rohan.
Edited by: Rohan on Dec 4, 2008 1:02 PM
‎2008 Dec 04 12:18 PM
Hi,
The problem i am facing is that sequence of field1 is not same always:
field1 field2
10 100
20 100
30 100
10 200
20 200
30 200
Now while reading the table using the key 2 as 100 or 200 the value of field1 is not in sequence.
Its coming as 10, 20 , 30 or 20, 10, 30
i want a stable sequence.
Thanks & Regards,
Rupali Ray
‎2008 Dec 04 12:16 PM
Hi Rupali,
As suggested by Ramchander, try the following stmnt, it should work as u want.
SORT ITAB STABLE BY FIELD2.
Hope will solve your problem.
Regards,
Pankaj
‎2008 Dec 04 12:20 PM
Hi,
iTAB is already sorted. while creating the table, i had decalred it as sorted table.
Why should i sort again the sorted table?
Thanks & Regards,
Rupali Ray
‎2008 Dec 04 12:31 PM
Hi,
Ok then dont stick on the sorted table ...while declaring the table make that as standard table and then after filling up that table sort it,as i said earlier...this will solve ur problem.
Regards,
Rohan.
‎2008 Dec 04 12:37 PM
Then include the first column also in sort criterion while defining it as a sort table, e.g.
TYPES ITAB TYPE SORTED TABLE OF mara WITH KEY matnr ernam.
then it will also work for u.
Regards,
Pankaj
‎2008 Dec 04 12:36 PM
field1 field2
10 100
20 100
30 100
10 200
20 200
30 200
-
if possible move the itab to itab_temp
delete adjacent duplicates from itab_temp comparing field2.