Application Development and Automation 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: 
Read only

Data coming in different order from the data base

Former Member
0 Likes
779

Hi Experts,

MSEG contains data (se16) in the order 1 , 2, 3

but if i write select query on it is coming as 2 1 5 ...3 like that

Shortly ..data is coming in different order in the select query even thoug it is in sorted order in the data base.

Thanks in advacne

Hi Experts,

MSEG contains data (se16) in the order 1 , 2, 3

but if i write select query on it is coming as 2 1 5 ...3 like that

Shortly ..data is coming in different order in the select query even thoug it is in sorted order in the data base.

Thanks in advacne

6 REPLIES 6
Read only

Former Member
0 Likes
747

Hi Krishna,

Generally when a select query is executed, the selection depends on the WHERE condition and the INDEX on the database table. So, we cannot expect the select statement to retreive the values in the same order as we see in se16.

That is the reason, we use SORT statement generally, after selecting the values in to an internal table, as per our requirement.

Best Regards,

Ram.

Read only

Former Member
0 Likes
747

Use SORT statement after yur select query

Regards,

lakshman.

Read only

former_member222860
Active Contributor
0 Likes
747

Try with the addition of ORDER BY PRIMARY KEY with your SELECT statement

Check this:

tables: mseg.

data: begin of t_mseg occurs 0.
        include structure mseg.
data: end of t_mseg.

select * into table t_mseg up to 50 rows
from mseg order by primary key.

loop at t_mseg.
  write:/ t_mseg-mblnr, t_mseg-matnr.
endloop.

Read only

sivaprasad_ml
Participant
0 Likes
747

Hi,

Try with the addition of ORDER BY PRIMARY KEY with your SELECT statement

for eg select from mseg into table <itab> where <condition> order by mblnr.

Rgds

Siva

Read only

Former Member
0 Likes
747

Hi,

For sorting your data,

1. Use a SORT statement after your select statement

2. Use aORDER BY PRIMARY KEY along with the statement

3. Create a Primary Index/Secondary index in the database table.

Thanks,

harini

Read only

0 Likes
747

Thank you All,

For your reply. But i want to know how and why it is coming in different order.