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: 

DownloadingSAP table into Multiple Files in Application Server?

Former Member
0 Kudos

Hi Guys,

Can anybody tell me me how to download the data into Application Server in Multiple Files by dividing the data into 300k records for every file?

Thanks,

Gopi.

1 ACCEPTED SOLUTION

former_member194669
Active Contributor
0 Kudos

Hi,

Check this code, (300k size you need to find out the number of records taht have size 300k)


loop at itab.
  move-corresponding itab to itab1.
  append itab1.
  v_no = v_no + 1.
  if v_no eq 500.
   v_index = v_index + 1,
   concatenate 'usrtmpfile' v_index into d1.
   open dataset d1 for output in text mode.
   loop at itab1.
    concatenate itab1-field1 itab1-field2 itab1-field2 into str
                  separated by con_tab.
    transfer str to d1.
   endloop.
   refresh itab1.
   clear v_no.
   close dataset d1.
  endif.
endloop.
* write last file
  if v_no ge 1.
   v_index = v_index + 1,
   concatenate 'usrtmpfile' v_index into d1.
   open dataset d1 for output in text mode.
   loop at itab1.
    concatenate itab1-field1 itab1-field2 itab1-field2 into str
                  separated by con_tab.
    transfer str to d1.
   endloop.
   refresh itab1.
   clear v_no.
   close dataset d1.
  endif.

aRs

2 REPLIES 2

former_member194669
Active Contributor
0 Kudos

Hi,

Check this code, (300k size you need to find out the number of records taht have size 300k)


loop at itab.
  move-corresponding itab to itab1.
  append itab1.
  v_no = v_no + 1.
  if v_no eq 500.
   v_index = v_index + 1,
   concatenate 'usrtmpfile' v_index into d1.
   open dataset d1 for output in text mode.
   loop at itab1.
    concatenate itab1-field1 itab1-field2 itab1-field2 into str
                  separated by con_tab.
    transfer str to d1.
   endloop.
   refresh itab1.
   clear v_no.
   close dataset d1.
  endif.
endloop.
* write last file
  if v_no ge 1.
   v_index = v_index + 1,
   concatenate 'usrtmpfile' v_index into d1.
   open dataset d1 for output in text mode.
   loop at itab1.
    concatenate itab1-field1 itab1-field2 itab1-field2 into str
                  separated by con_tab.
    transfer str to d1.
   endloop.
   refresh itab1.
   clear v_no.
   close dataset d1.
  endif.

aRs

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Sure, just use the PACKAGE SIZE extension of the SELECT statement, See this example, notice the package size, each time, it will retrieve 100 records and write out a new file to the application server.




report zrich_0001.

constants: con_tab type x value '09'.
constants: filepath type localfile value '/usr/sap/TST/SYS/'.

data: str type string.
data: counter(5) type c.
data: imara type table of mara with header line.
data: d1 type localfile.


select * into table imara from mara package size 100.

* Just to come out of the loop for testing purpose.
  if counter = 10.
    exit.
  endif.

  counter = counter + 1.
  concatenate filepath 'Test' counter '.txt' into d1.
  condense d1 no-gaps.

  open dataset d1 for output in text mode.
  loop at imara.
    concatenate imara-matnr imara-mtart imara-matkl into str
                  separated by con_tab.
    transfer str to d1.
  endloop.
  close dataset d1.

endselect.

Regards

Rich Heilman