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

Former Member
0 Likes
1,103

Hi,

I have a select statement to get the records based on some condition. I got say 1000 records. Now i need this selection for only first 250 records. Can we restict the select statement to get only the first 250 records. If so pls let me know the code how to write the select statement.

Also i don't want the code between select and endselect.

Regards,

Ramesh

10 REPLIES 10
Read only

Former Member
0 Likes
1,081

You can say SELECT.....

..... UP TO n ROWS

Read only

Former Member
0 Likes
1,081

Hello,

SELECT * FROM MARA

UP TO 250 rows

.

This will select only frist 250 rows.

VAsanth

Read only

0 Likes
1,081

Hi,

The thing is if i give up to N rows its checking the table for the first 250 records only. But i have my data in around 1000th record in the table. Here its not getting this field for my condition given.

For example if i got some around 1000 records for the select condition, i need only firat 250 records of this.

Regards,

Ramesh

Read only

0 Likes
1,081

hi Ramesh,

did u check my reply?? ..

Regards,

Santosh

Read only

0 Likes
1,081
SELECT * FROM MARA 
               INTO itab               
               UP TO 250 rows
               WHERE xxxxxxxx

DATA itab TYPE SCUSTOM. 

SELECT * FROM SCUSTOM INTO TABLE itab 
            UP TO 3 ROWS 
          WHERE CUSTTYPE = 'B' 
         ORDER BY DISCOUNT DESCENDING. 
  WRITE: / WA_SCUSTOM-ID, WA_SCUSTOM-NAME, WA_SCUSTOM-DISCOUNT. 
ENDSELECT.

Use <b>order by field</b>, hope this solves.

Read only

Former Member
0 Likes
1,081

Hi

Select... Upto 250 rows solves your purpose.

Regards,

Read only

Former Member
0 Likes
1,081

YOu have to use select * from <table> up to 250 rows into wa where..

endselect.

If you want to restrict the number or records you have to use the endselect.

Other wise, you have to move the data that is selected into another internal table.

loop at itab from 1 to 250.

move-corresponding itab to itab_new.

append itab_new.

endloop.

Regards,

Ravi

Read only

Former Member
0 Likes
1,081

hi ramesh,

do this way ..

select * from mara into table it_mara where <conditions>.

if sy-subrc = 0.
  loop at it_mara.
     lv_tabix = sy-tabix.
       if lv_tabix  >  '250'.
         delete it_mara index sy-tabix.  
       endif. 
  endloop.
endif.

Regards,

santosh

Message was edited by:

Santosh Kumar Patha

Read only

Former Member
0 Likes
1,081

Hi

Use select upto clause.

Regards,

Prasanth

Read only

Former Member
0 Likes
1,081

Hi,

SELECT  *  FROM VBAK
                  INTO IT_TAB           
                  UP TO 250 ROWS

.

reward if useful.