Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Sort statement behaviour

Former Member
0 Kudos

I am working on a performance tuning of an extract that runs for 7 hrs. Well, I got it down to 1 hour but noticing the data differences (Telephone numbers). And when I debugged the old and new, noticed the sort statement behaves differently. Both programs use the same sort statement.

SORT t_adr2 BY addrnumber date_from.

One sorts in the order

tel1

tel2

tel3

and other sorts

tel3

tel2

tel1

The program reads the first telephone number that it gets after sorting.

Read itab index 1.

Because the sort order is different I am getting different values from old and new programs. Any feedback will be appeciated.

P.S - When I run both the programs for just one customer, I don't run into this issue. Both the programs return me the same values. But they are different when I run the program wide open.

Thanks

Anu

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi check one thing ..

1 .sort is used to get the details at the asending order or in the descending order ..

check this for ascending order..

sort itab by field1 ascending

---means here the field1 values are stored in the table in the ascending order ...like 1 2 3 4 ....

sort itab by field1 desceding

---means here the field1 values are stored in the table in the descending order ...6 5 4 3 2 1

with this sort you can get the recent record with in the no of records...

read statemet is used for reading one record which met the condtion ..for fast action bynary search is used..

check this for more information..

http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/sort.htm

regards,

venkat

9 REPLIES 9

Former Member
0 Kudos

Why don't u sort it using ascending or descending.

Hope it helps.

Former Member
0 Kudos

hi check one thing ..

1 .sort is used to get the details at the asending order or in the descending order ..

check this for ascending order..

sort itab by field1 ascending

---means here the field1 values are stored in the table in the ascending order ...like 1 2 3 4 ....

sort itab by field1 desceding

---means here the field1 values are stored in the table in the descending order ...6 5 4 3 2 1

with this sort you can get the recent record with in the no of records...

read statemet is used for reading one record which met the condtion ..for fast action bynary search is used..

check this for more information..

http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/sort.htm

regards,

venkat

0 Kudos

I appreciate your quick turn around. But my objective here is to match the data with the old program. The old program do not use any ascending and descending addition. Neither I see the use of it. If you notice the help on SORT statement, you will see some notes on addition 'STABLE' the exact situation I am running into. But I am dealing with 2 different program so I can't make use of it.

I just want to know why the system sorts the tables differently even though the sort criteria is same and is there anything I can do to make sure they match.

Thanks

Anu

Former Member
0 Kudos

Is the combination "addrnumber date_from" unique when you run it wide open?

Former Member
0 Kudos

hi under stand one thing...

suppose i had a field at the third column of the field ...with this field i am reading the another table...if u dont use the sort command then it will checks the first field and checks the second field...and then third field which is not good for performance....if u use the sort then the table sorts data with the specified field to the first position so it will hit the condition in the first attempt only..so the performance will incrases..

if you got the answer award the good answer and close the thread..please..

regards,

venkat

0 Kudos

Venkat,

I realise what you are trying to say, but I am not concerned with performance anymore ( I got it down to 1 hr from 7 hrs). Its just the order of the data. I will keep this open to see someone else might help me. But I truely appreciate your response.

Aparna,

The addrnumber and date_from combination is not unique which is the reason I am running into the situation.

Thanks

Anu

0 Kudos

Cant you find any other combination of fields which will be unique and then change the sort statement?

0 Kudos

All,

The functional team made a decision to go with the standard telephone number instead of the first telephone number that I get in the internal table for a customer.

That would still not match the old one, but something consistent data going on. I appreciate all your responses.

Thanks

Anu

0 Kudos

Closing this thread .

Thanks

Anu