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

Selecting from a table based on row number

SreekanthKrishn
Contributor
0 Likes
1,976

Hi,

Is there any way to select rows from a table by specifying the starting position.

Like:

Select *

up to 10 rows

into table it_vbap

From vbap.

This will selet first 10 rows. Is there any way to select rows from 20 to 30??

Thanks,

Sreekanth

1 ACCEPTED SOLUTION
Read only

former_member222860
Active Contributor
0 Likes
1,390

Hi,

Though it's not possible to get in single Select statement, but you can do it with simple logic:

DATA: BEGIN OF ITAB OCCURS 0,
        VBELN LIKE VBAK-VBELN,
      END OF ITAB.

DATA: VAL TYPE STRING,
      N TYPE I.

SELECT VBELN FROM VBAK INTO TABLE ITAB UP TO 100 ROWS.

LOOP AT ITAB.                " First 100 records selected
  WRITE:/ ITAB-VBELN.
ENDLOOP.

DESCRIBE TABLE ITAB LINES N.

LOOP AT ITAB.
  IF SY-TFILL = N.
    VAL = ITAB-VBELN.
  ENDIF.
ENDLOOP.

CLEAR ITAB.

*WRITE:/ VAL.

SELECT VBELN FROM VBAK INTO TABLE ITAB UP TO 100 ROWS
             WHERE VBELN GT VAL.
                                     " Next 100 records selected
LOOP AT ITAB.
  WRITE:/ ITAB-VBELN.
ENDLOOP.

Hi,

Is there any way to select rows from a table by specifying the starting position.

Like:

Select *

up to 10 rows

into table it_vbap

From vbap.

This will selet first 10 rows. Is there any way to select rows from 20 to 30??

Thanks,

Sreekanth

4 REPLIES 4
Read only

Sandeep_Panghal
Product and Topic Expert
Product and Topic Expert
0 Likes
1,390

No.

Read only

Former Member
0 Likes
1,390

Hi..

No its not possible . but you can use some other key field from db table to retrive data or select all top 30 records and then delete first 10 records using sy-index .

regards,

Chintan.

Read only

Former Member
0 Likes
1,390

Hi Sreekanth,

inorder to meet ur reqmnt you have to select all the records based on the selection criterion loop in internal table delete the last 20 by index

thanks and regards

srikanth.p

Read only

former_member222860
Active Contributor
0 Likes
1,391

Hi,

Though it's not possible to get in single Select statement, but you can do it with simple logic:

DATA: BEGIN OF ITAB OCCURS 0,
        VBELN LIKE VBAK-VBELN,
      END OF ITAB.

DATA: VAL TYPE STRING,
      N TYPE I.

SELECT VBELN FROM VBAK INTO TABLE ITAB UP TO 100 ROWS.

LOOP AT ITAB.                " First 100 records selected
  WRITE:/ ITAB-VBELN.
ENDLOOP.

DESCRIBE TABLE ITAB LINES N.

LOOP AT ITAB.
  IF SY-TFILL = N.
    VAL = ITAB-VBELN.
  ENDIF.
ENDLOOP.

CLEAR ITAB.

*WRITE:/ VAL.

SELECT VBELN FROM VBAK INTO TABLE ITAB UP TO 100 ROWS
             WHERE VBELN GT VAL.
                                     " Next 100 records selected
LOOP AT ITAB.
  WRITE:/ ITAB-VBELN.
ENDLOOP.