cancel
Showing results for 
Search instead for 
Did you mean: 

HOw to download a file in background without user intervention?

Former Member
0 Kudos
447

Hello people,

A few hours ago I asked a couple of guys how to download a file to html. For that I am most thankful, and as mentioned this is a two part question, my other question is about how to proccess downloading the html in background and to automatically send it to a folder or other path. Without any user intervention.

Example, I run a long report to be downloaded in background. The lets say the next day, I can get the file in a folder. Thanks guys take care!

Accepted Solutions (1)

Accepted Solutions (1)

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

Here is the sample code.

data: ifields type table of w3fields with header line.

data: ihtml type table of w3html with header line.

data itab type standard table of pa0001.

select * into corresponding fields of table itab

from pa0001 up to 100 rows.

call function 'WWW_ITAB_TO_HTML'

EXPORTING

  • TABLE_ATTRIBUTES = 'BORDER=1'

  • TABLE_HEADER =

ALL_FIELDS = 'X'

tables

html = ihtml

fields = ifields

  • ROW_HEADER =

itable = itab

.

  • Local variable Declaration

DATA l_msg(60) TYPE c.

  • Opening the file for output in text mode

OPEN DATASET '/sapio/outbound/html.txt' FOR OUTPUT

IN TEXT MODE ENCODING DEFAULT MESSAGE l_msg.

IF sy-subrc NE 0.

MESSAGE s000 WITH 'Error in opening file for output'.

LEAVE LIST-PROCESSING.

ENDIF.

LOOP AT ihtml .

TRANSFER ihtml TO '/sapio/outbound/html.txt'.

ENDLOOP.

  • Closing the file

CLOSE DATASET '/sapio/outbound/html.txt'.

IF sy-subrc NE 0.

MESSAGE s000 with 'Error in closing file'.

LEAVE LIST-PROCESSING.

ENDIF.

Since you want to download in background,you cannot download in presentation server.SO you have to download in application server.

Kindly reward points if it helps.

Message was edited by: Jayanthi Jayaraman

Former Member
0 Kudos

HI,

Use

OPEN DATASET FOR OUPUT

&

CLOSE DATASET



here is the sample code for the same

OPEN DATASET P_PATH FOR OUTPUT IN TEXT MODE.



IF SY-SUBRC <> 0.
MESSAGE E039(ZK) WITH
'ƒ_ƒEƒ“ƒ[ƒh‚ŃGƒ‰[‚ª”­¶‚µ‚Ü‚µ‚½B'.
ENDIF.

LOOP AT PR_TBL.


PERFORM ZYIR070_TRANSFER_DATASET USING 'C'
P_PATH
PR_TBL SY-INDEX.

ENDLOOP.



CLOSE DATASET P_PATH.

Regards,

Santosh

Message was edited by: Santosh Kumar Patha

Answers (3)

Answers (3)

Former Member
0 Kudos

Hello guys thanks for your help so far. I have been off again on again with this task because its more for future purposes than anything.

So far I have searched the net and stuff and decided that I will use WWW_LIST_TO_HTML since I want to download it the way it is. I am also going to use open/close dataset as many of you have mentioned.

SO far Im just trying it out with a simple report program to see its funcitonalities. My code goes like this.

_______________________________________

<b>REPORT ZCCYT_COOL2 NO STANDARD PAGE HEADING LINE-COUNT 100 .

DATA: IFIELDS TYPE TABLE OF W3FIELDS WITH HEADER LINE.

*DATA: ihtml TYPE TABLE OF w3html WITH HEADER LINE.

DATA: IHTML TYPE TABLE OF W3_HTML WITH HEADER LINE.

DATA: BEGIN OF I_TAB OCCURS 0,

MATNR LIKE MAKT-MATNR,

MAKTX LIKE MAKT-MAKTX,

END OF I_TAB.

SELECT-OPTIONS: SO_MATNR FOR I_TAB-MATNR.

SELECT MATNR MAKTX

FROM MAKT

INTO TABLE I_TAB

WHERE MATNR IN SO_MATNR..

LOOP AT I_TAB.

WRITE: / I_TAB-MATNR,

I_TAB-MAKTX.

ENDLOOP.

.

CALL FUNCTION 'WWW_LIST_TO_HTML'

  • EXPORTING

  • list_index = sy-lsind

TABLES

HTML = IHTML.

DATA: FILE TYPE LOCALFILE.

FILE = '/usr/test.html'.

OPEN DATASET FILE FOR OUTPUT IN BINARY MODE.

LOOP AT IHTML.

TRANSFER IHTML TO FILE.

ENDLOOP.

CLOSE DATASET FILE.</b>

_____________________________________________

NOw the problem now though is that the file isnt downloading or saving at all. I cant seem to get what is wrong since the path does exist and the this seems the universal way to implement the program. Im guessing the problem lies in the file name, because everything seems to work fine. Hope to hear again soon sorry for not visiting this place sooner cuz I was buzy elsewhere.

vinod_gunaware2
Active Contributor
0 Kudos

Hi

Use below statement

*--- open file

open dataset nfile for output in text mode message w_msg.

if sy-subrc ne 0.

write: / 'Cannot open for writing:', nfile, w_msg.

exit.

endif.

*--- write file

loop at it_file.

transfer it_file to nfile.

endloop.

*--- close file

close dataset nfile.

regards

vinod

Former Member
0 Kudos

In background mode, files can only be downloaded in application server (not on presentation server).

For this use open dataset & close dataset statements