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

Using Cursors

Former Member
0 Likes
426

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
Read only

Former Member
0 Likes
396

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
Read only

Former Member
0 Likes
396

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.

Read only

Former Member
0 Likes
397

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.