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

Select Statement behaviour?

Former Member
0 Likes
1,151

Hi,

When i did a select stetement with limited fields on MSEG, records are coming in to a internal table but the order of these records in internal table is strange. I want to know what would be the basis?. when i see the records in SE16 the order is based on Item number. but in internal table records are in different order.

Please let me know why it is.

Thanks in advance....

Mohan

7 REPLIES 7
Read only

nikhil_chitre
Active Participant
0 Likes
1,051

after your select... sort internal number on item number

Regards,

Nikhil

Read only

Former Member
0 Likes
1,051

Hi,

If you are not using all the key fields in where condition this does happen...also you need to use the fields in same order while selecting them in select query...

else you need to define the internal table as SORTED table..

Regards

Shiva

Read only

Former Member
0 Likes
1,051

Hi Jagan,

After ur select query try to use sort query as shown

select * from MSEG into table itab.

sort itab by mblnr.

Here i am sorting with the field MBLNR, if u want you can sort with your required field

but if you sort with primary key field it gives good performance.

Cheers!!

VEnk@

Read only

0 Likes
1,051

Hi,

I don't want to do any sorting after selecting because of some other issues. This program is working fine from last several days and we got this issue now only.. so please let me know how to select statement behavious.

Thanks a lot in advance...

Read only

0 Likes
1,051

"I don't want to do any sorting after selecting because of some other issues" share your reasons.

And you can do one more thing like modify your select query using Order BY clause for your example

see the below link

http://help.sap.com/saphelp_nw04/helpdata/en/62/10a423384746e8bf5f15ccdd36e8b1/content.htm

and in tht link u can see at the last ORDER by clause.

Or else put a breakpoint and debug from where and how the data is been populating so tht u can get an idea on

the issue.

Cheers!!

VEnk@

Read only

matt
Active Contributor
0 Likes
1,051

You have a relational database. In a relational database, there is no concept of order of records. You are getting in your internal table, the actual order of the records in the database. SE16 presumably sorts by key.

matt

Read only

Former Member
0 Likes
1,051

Issue solved