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

Using Cursors

Former Member
0 Kudos

Hello,

Can anyone tell me how to use cursors. I have a table with 1 million records,

I need to process 100000 records each time my select statement executes, process those records ,and get the next 100000.

Thanks, points are awarded

1 ACCEPTED SOLUTION

Former Member
0 Kudos

DATA: lv_cursor TYPE cursor.

OPEN CURSOR WITH HOLD lv_cursor

FOR SELECT * FROM <table>

WHERE ...

DO.

FETCH NEXT CURSOR lv_cursor

INTO TABLE itab

PACKAGE SIZE 100000.

IF sy-subrc <> 0.

CLOSE CURSOR lv_cursor.

EXIT.

ENDIF.

...

ENDDO.

2 REPLIES 2

Former Member
0 Kudos

Use the "package size" addition to limit how many records you want to process at one time in the select.

eg.

SELECT *

FROM vbak

INTO TABLE lt_vbak PACKAGE SIZE 100000.

    • do your processing of the 100000 records contained in li_vbak.

ENDSELECT.

Former Member
0 Kudos

DATA: lv_cursor TYPE cursor.

OPEN CURSOR WITH HOLD lv_cursor

FOR SELECT * FROM <table>

WHERE ...

DO.

FETCH NEXT CURSOR lv_cursor

INTO TABLE itab

PACKAGE SIZE 100000.

IF sy-subrc <> 0.

CLOSE CURSOR lv_cursor.

EXIT.

ENDIF.

...

ENDDO.