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

Write data to Excel in background mode

Former Member
0 Likes
1,093

Hi Gurus,

Is it possible to write the data to Excel file when I run the report in background mode. Which function module should I use?

Sanju

Hi Gurus,

Is it possible to write the data to Excel file when I run the report in background mode. Which function module should I use?

Sanju

8 REPLIES 8
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,048

You can write it to the application server, but not the frontend. You must use the DATASET statements. Do F1 help on DATASET.

Regards,

Rich HEilman

Read only

Former Member
0 Likes
1,048

Hi,

try to download it to application server and then download it later.

you need to use open dataset and transfer , close data set. since frontend download is not possible in background.

Regards

Vijay

Read only

Former Member
0 Likes
1,048

Keep in mind to store the file in CSV format ...

Read only

0 Likes
1,048

I usually like to write as a comma delimited file, here is a sample program.



report zrich_0001.


parameters:
            d2 type localfile default '/usr/sap/TST/SYS/Data2.csv'.

data: it001 type table of t001 with header line.
data: iflat type table of string with header line.
field-symbols: <fs>.


start-of-selection.

* Get data
  select * into table it001 from t001.


* Put data into flat structure with comma delimit
  loop at it001.
    clear iflat.
    do.
      assign component sy-index of structure it001 to <fs>.
      if sy-subrc <> 0.
        exit.
      endif.
      if sy-index = 1.
        iflat = <fs>.
      else.
        concatenate iflat <fs> into iflat separated by ','.
      endif.
    enddo.
    append iflat.
  endloop.


* Download to app server
  open dataset d2 for output in text mode.
  loop at iflat.
    transfer iflat to d2.
  endloop.
  close dataset d2.

Regards,

Rich Heilman

Read only

0 Likes
1,048

Thanks guys,

I know I can write it to the server as a csv/flat file. Its an ALV report and if user runs it in foreground, it times out.

Was wondering if it can be written to Excel file. Sounds like it cannot be!

Thanks

Sanju

Read only

0 Likes
1,048

Csv File can be viewed in excel, is this not good enough?

Regards,

Rich Heilman

Read only

0 Likes
1,048

Yes it is. But you know how these user are, they do not want to take the pain to even format it while opening the file in Excel.

I awarded points for all your inputs.

Sanju

Read only

0 Likes
1,048

If you run the program above, and then double click on the file when its created, do you have to format it? I don't, looks like a regular excel file for me.

Regards,

RIch Heilman