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: 

How to Download data into Chunks?

Former Member
0 Kudos
261

Hi Guys,

Can anybody tell me How to download the data into chunks for ex consider BSEG table for this table ?how can we download the data into chunks from SAP Database?

Can anybody tell me how to use Open Cursor and what is meant by Open Cursor?

Thanks,

Gopi.

11 REPLIES 11

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
116

You mean from db into your program using SELECT statement?

Regards,

RIch Heilman

0 Kudos
116

If with a SELECT statement, use the package size extension.



data: ibseg type table of bseg with header line.

select * into table ibseg from bseg package size 1000.
  append ibseg.
endselect.

Regards,

Rich Heilman

0 Kudos
116

Hi Rich,

Thanks for your repsonse.i have to download the data from BSEG table.Can u tell me how to do?Becoz for BSEg table i was not able to download all the records from database to my Internal table.I can download only upto 400,000 rows.so i how to download chunks of 400,000 rows into my internal table and transferring it to Application Server that to based on BKPF-BELNR?

Plzzzzzzzzz respond with whatever idea or experince u have

Thanks,

Gopi.

0 Kudos
116

Looks like you can do something like this.



report zrich_0001.

data: tmp_bseg type table of bseg with header line.
data: ibseg type table of bseg with header line.

select * into corresponding fields of table tmp_bseg
         from bseg
                 package size 500
                    where bukrs = '0010'.


* Add these 500 lines at a time to the internal table
  append lines of tmp_bseg to ibseg.

endselect.

REgards,

RIch Heilman

0 Kudos
116

Hey,

I hope following code solves your problem.


DATA : it_bseg    TYPE TABLE OF bseg,
       v_size     TYPE i VALUE '300000',
       v_filename TYPE string VALUE give application server path + file name.
 
SELECT *
  FROM bseg
  APPENDING TABLE it_bseg PACKAGE SIZE v_size
  WHERE condition.
ENDSELECT.

OPEN DATASET v_filename FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
SORT IT_BSEG BY BELNR.
LOOP AT it_bseg INTO x_bseg
  TRANSFER x_bseg TO  v_filename. 
ENDLOOP.
CLOSE DATASET v_filename.

Reward points if the answer is helpful.

Thankx,

Mukul

Message was edited by:

Mukul R. Kulkarni

0 Kudos
116

Hi Mukul,

I have to get 6 million records out of your logic .I think still some changes are required i think.Can u make those changes and send to me?

Thanks,

Gopi.

0 Kudos
116

Hi Gopi,

The only change that you have to do is vary the PACKAGE SIZE according to your need. Instead of 300,000 which is set right now, give the PACKAGE SIZE as 1,000,000. But that all depends upon your requirement.

Now, I think your limit is 350,000. If that is the case, then give PACKAGE SIZE 350,000 and instead of writing open dataset outside SELECT, put in before ENDSELECT.

i.e.


DATA : it_bseg    TYPE TABLE OF bseg,
       v_size     TYPE i VALUE '350000',
       v_filename TYPE string VALUE give application server path + file name.

SELECT *
  FROM bseg
  INTO TABLE it_bseg PACKAGE SIZE v_size
  WHERE condition.

IF it_bseg[] IS NOT INITIAL.
  OPEN DATASET v_filename FOR APPENDING IN TEXT MODE ENCODING DEFAULT.
  SORT IT_BSEG BY BELNR.
  LOOP AT it_bseg INTO x_bseg
    TRANSFER x_bseg TO  v_filename. 
  ENDLOOP.
  CLOSE DATASET v_filename.
ENDIF.

ENDSELECT.

Reward points if the answer is helpful.

Thankx,

Mukul

0 Kudos
116

Hi Gopi,

If your Internal Table has limits, use can also use EXTRACTS.

Reward points if the answer is helpful.

Thankx,

Mukul

0 Kudos
116

Hi Mukul,

I understood what u told.for example consider.First time when select statement gets executed u get 1st 350,000 rows from database table.after first time select endelect gets executed .next time again select staement gets executed.here i am having doubt for 2nd time when records getting downloaded from BSEG table does we get the next 350,000 rows if so can u explain me clearly the inside process how it works or we will get the same 350,000 rows which we already got ?

Thanks,

Gopi.

0 Kudos
116

Hi Gopi,

Every time a new set of data will be fetched.

Normally when u write SELECT *, it fetches all records in one shot. Now, if because of some limitation, it is not possible to fetch whole data in one shot, then we have to specify the package size. Lets say package size as v_size. So, every time, v_size no of new lines will be fetched from database. So if v_size = 1000 then in the first round, first 1000 records will be fetched. Then in the second round, next 1000 i.e. from 1001 to 2000 will be fetched. So, in this way you will get whole data not in one shot but part by part.

Does this answer your question ?

Reward points if the answer is helpful.

Thankx,

Mukul

0 Kudos
116

Hi Mukul,

I think the logic is correct but i dont know until i check.can i use For all entries inthe above select statement wich u wrote becoz i have to download he BSEG table based on BKPF-BELNR.?

Thanks,

Gopi.