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

problem with FETCH NEXT CURSOR

Former Member
0 Likes
4,459

Hi expert,
could someone tell me why the below FETCH NEXT CURSOR keep getting the data from the database table although it has just 400000 records?
the statement keep going till I receive a dump with

no more storage space available for extending an internal table


OPEN CURSOR WITH HOLD lv_cursor FOR 
SELECT artkl_id FROM ZZ_artk.
DO. 
CLEAR lt_artk . 
FETCH NEXT CURSOR lv_cursor INTO CORRESPONDING FIELDS OF TABLE lt_artkl_data PACKAGE 
SIZE 10000. 
APPEND LINES OF lt_artk_data TO lt_artk_all.
IF sy-subrc <> 0 . 
CLOSE CURSOR lv_cursor_artkl_id.
EXIT.
ENDIF.
ENDDO.

Best regards

Jenie

9 REPLIES 9
Read only

Tomas_Buryanek
Product and Topic Expert
Product and Topic Expert
2,925

You should check sy-subrc after FETCH. Not after APPEND command.

-- Tomas --
Read only

0 Likes
2,925

I did this but in vain the problem is that sy-subrc is is always = 0, in this case the data will be called again and again

Read only

0 Likes
2,925

jennifer1988 it is just illogical to do it your way (and sometimes dangerous, hopefully APPEND does not alter SY-SUBRC). Instead, write it like this, it's just more logical:

FETCH NEXT CURSOR lv_cursor INTO CORRESPONDING FIELDS OF TABLE lt_artkl_data 
       PACKAGE SIZE 10000.
IF sy-subrc <> 0 . 
CLOSE CURSOR lv_cursor_artkl_id.
EXIT.
ENDIF.
APPEND LINES OF lt_artk_data TO lt_artk_all.
Read only

0 Likes
2,925

jennifer1988 : if it keep going mean it still fetchable, its very clear in F1 help about that.

Read only

Sandra_Rossi
Active Contributor
2,925

The interest of using FETCH is to keep in memory a limited number of lines, not the whole table. So why do you append all the lines to an internal table? (your code is exactly like doing SELECT artkl_id FROM zz_artkl INTO TABLE lt_artk_all).

Read only

0 Likes
2,925

Hi Sandra,

I am using append just to control and stand on how many records has been called and this appended Table will not be used further...

Read only

0 Likes
2,925

jennifer1988 you ran into a memory problem, so 400.000 lines was too much in your situation, so either you troubleshoot the memory problem which is not related to your ABAP code (cf my other answer), or you reduce the memory consumption and you don't load all the lines of the table (if it's just to count the lines, then just use SELECT COUNT( * )).

Read only

Sandra_Rossi
Active Contributor
2,925

In your short dump, you should see the number of lines of the internal table, the memory used, etc. If needed, use the debugger to list the data objects sorted by the amount of memory used.

Read only

matt
Active Contributor
0 Likes
2,925

If you run in debug you should be able to solve by yourself.