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: 

Fetch Next Cursor Short Dumps

Former Member
0 Kudos

Hello All,

I have the following code which short dumps after losing its cursor position.

OPEN CURSOR WITH HOLD dbcur FOR
      select * from ekpo where bukrs in s_bukrs2.

      do.
          FETCH NEXT CURSOR dbcur INTO table iekpo package size pkgsize.

          if sy-subrc <> 0.
             close cursor dbcur.
             exit.
          else.
              perform ouput_to_text_file.
              refresh: iekpo.
           endif.
      enddo.

I have millions of records to be extracted and simple select to an internal table causes memory problems. Thus I need to extract a chunk of records write them to a text file, then get the next chunk.

Any suggestions?

Thank you,

Jerry

1 ACCEPTED SOLUTION

ThomasZloch
Active Contributor
0 Kudos

What's going on in "ouput_to_text_file"? Whatever it is that loses the cursor, maybe it can be replaced with something that does not lose it. e.g. COMMIT WORK can be replaced by a call to function DB_COMMIT. Subject to your analysis.

Another approach would be to SELECT UP TO x ROWS, remember the last primary key (EBELN + EBELP) and continue reading from that key onwards in each loop.

Thomas

4 REPLIES 4

ThomasZloch
Active Contributor
0 Kudos

What's going on in "ouput_to_text_file"? Whatever it is that loses the cursor, maybe it can be replaced with something that does not lose it. e.g. COMMIT WORK can be replaced by a call to function DB_COMMIT. Subject to your analysis.

Another approach would be to SELECT UP TO x ROWS, remember the last primary key (EBELN + EBELP) and continue reading from that key onwards in each loop.

Thomas

0 Kudos

Thank you Thomas,

In the output to text file form I am using GUI Download to export data to a text file (or if in the background using dataset and transfer to write to the text file).

Your suggestion for reading up to x rows, how would that work exactly? Do you have an example you can share, specifically keeping track of what you've already selected and selecting the next records?

Thank you,

Jerry

0 Kudos

GUI Download probably causes problem, writing to a dataset on app server might not cause the problem, maybe you want to try.

Regarding the select, here is some pseudo code outlining what I mean:


clear wa_ekpo.
do.
  select * from ekpo into table lt_ekpo up to 10,000 rows 
      where ebeln > wa_ekpo-ebeln or ( ebeln = wa_ekpo-ebeln and ebelp > wa_ekpo-ebelp )
      order by primary key.
  if sy-subrc ne 0.
    exit.
  endif.
  download lt_ekpo (appending to existing file)
  l_lines = lines( lt_ekpo ).
  read table lt_ekpo into wa_ekpo index l_lines.
enddo.

Will run for a while, but should not dump out

Thomas

0 Kudos

That looks like it does the trick.

Thank you very much!

Points have been awarded!

Jerry