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 in ws_download while executing in background

Former Member
0 Likes
901

Hi,

I am downloading an excel file.

I have written a code like this.

If it is in foreground, it will display in ALV and download the data in an excel file in C:/ drive. IF i run in foreground i am getting the output and also the file is created in C:/ with the data.

If i run that program in background the file is not created. I am not able to see the file in C:/.

How to download a file in background..??

Kindly help meout plz..

Kumar

9 REPLIES 9
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
806

You can not download from background process. The background process does not know what "C:\" on your computer is. You can only download to the application server in background.

Regards,

Rich Heilman

Read only

0 Likes
806

So, is there any solution for this issue. I need to do it as i do not have any other option.

Kumar

Read only

0 Likes
806

There is a way to download to PC from background, but you really have to jump thru some hoops and there is some stuff to be done on the PC itself. Really its not worth it.

There are a couple ways to work around this, but it depends on the real requirement. For example, say you have a long running report and the user wants to have the report in excel. So you need to run in background, you can run your report in backgroun and update a custom table with the data(or just write to the application server as a file), then the user can run a transaction after the job is completed to download the data to the PC, either from the custom db, or the application server.

Here is a short program which shows how to download a file from the application server to the frontend PC.

report zrich_0001.

parameters: p_file type localfile
           default '/usr/sap/trans/data/R903289.TST'.

data: begin of idata occurs 0,
      rec type string,
      end of idata.
data: xdata type string.

data: stripped type rlgrap-filename.
data: file_path type rlgrap-filename.
data: fe_path type string.

start-of-selection.

* Download Data Files
  open dataset p_file for input in text mode.
  if sy-subrc = 0.
    do.
      read dataset p_file into xdata.
      if sy-subrc <> 0.
        exit.
      endif.
      idata-rec = xdata.
      append idata.
    enddo.
  endif.

  call function 'SO_SPLIT_FILE_AND_PATH'
       exporting
            full_name     = p_file
       importing
            stripped_name = stripped
            file_path     = file_path.

  concatenate 'C:' stripped into fe_path.

  call function 'GUI_DOWNLOAD'
       exporting
            filename = fe_path
       tables
            data_tab = idata
       exceptions
            others   = 22.

Regards,

Rich Heilman

Read only

0 Likes
806

Thankyou all,

Anyway my problem is not solved, but got some reasons to put to my boss.. :-(..

Thankyou all...

Kumar

Read only

0 Likes
806

Please remember to award points for any helpful answers. Thanks.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
806

Hi ,

You cannot use WS_DOWNLOAD in background.

you can not use your presentation server links.that means that you will also not be able to use gui_download also.

Why dont you write your file to the application server and then download it using transaction CG3Y.

Read only

Former Member
0 Likes
806

Hi Rich,

"There is a way to download to PC from background, but you really have to jump thru some hoops and there is some stuff to be done on the PC itself"

Please let me know the way to download to PC from background..Just to learn a new thing..

Thanks,

Naren

Read only

0 Likes
806

Hi Naren, here is the doc which lays it all out. Yes, it is possible(anything is with time and money) but is it a good idea?, maybe for an extreme case, but I think that we should still operate under the understanding that you can not download/upload using the standard SAP function modules from the background.

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/abap/communication...

Regards,

Rich Heilman

Read only

Former Member
0 Likes
806

Thanks a lot Rich..

Regards

Naren