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.
Showing results for 
Search instead for 
Did you mean: 

Select statment problem

Former Member
0 Kudos

Hi Experts, Data is selected from VBKPF table based on previous month posting date range.Here data not coming as primary key sorted, It is very urgent to know why its not coming as primary key sorted, i checked indexes but not found. SELECT * FROM vbkpf INTO TABLE it_vbkpf  WHERE budat IN s_budat


Active Participant
0 Kudos

This table not has the month as key and index. (In my SAP version)

The date available in the key is the year.

If you realy need to select this table using month, create a index (ask if possible to basis team and explain the reason). In your index you can use these fields:


0 Kudos

Hi Teixeira, Data is required as sorting form of primery keys ( Mandt ausbk bukrs belnr gjahr), it will automaticaly come because we selected from data base table(VBKPF) but here not coming automatically, that is the problem.

0 Kudos

Hi Prasad,

there's a way to get from selection the fields sorted regarding your specific requirement.

Declare a internal table using this:

DATA it_vbkpf TYPE SORTED TABLE OF vbkpf WITH UNIQUE KEY feld1 field2.


DATA it_vbkpf TYPE SORTED TABLE OF vbkpf WITH NON-UNIQUE KEY feld1 field2.

After this apply your selection into table it_vbkpf

0 Kudos

Hi Teixeira,

Thanks for you reply,

I know that one, They want reason why data coming as with out sorting of primary key fields.

Normally if we select data from database it will come primary key based sorted data,

In my case why its not  coming like that....

0 Kudos

Hello Prasad,

If you pass primary key field as where clause then you will get sorted order which is exist in DB sequence order.

If you pass non primary key as where clause then you wont get the exact primary key order.

In his case you can sort the internal table.


Vadamalai A.

0 Kudos


i always use key or index to select table, but i made a test code using your example (only budat in where condition and internal table TYPE TABLE OF) and works fine for me, the key fields are sorted after selection.

tables vbkpf.

select-options s_budat for vbkpf-budat.

data ti_vbkpf type table of vbkpf.

select * from vbkpf  into table ti_vbkpf where budat in s_budat.

Check the complete index fields values (sorted) and budat not:

Please, let me know if using this template you have the key fields sorted.

0 Kudos

Hi Prasad,

My take is you are not guaranteed an ordered set of results.

Just add an "ORDER BY ..."  to your select statement to assure order.

(See the SELECT help for details)


Active Contributor
0 Kudos

the fact that this are key fields dont mean they are sorted, isnt it? It just means they are unique. I guess that the sorting of lines in the table VBKPF is exactly what you get in your internal table after your selection.

did you check this?


Stefan Seeburger