10-07-2007 12:39 AM
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
10-07-2007 2:15 AM
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.
10-07-2007 12:54 AM
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.
10-07-2007 2:15 AM
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.