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: 

DOWNLOAD

Former Member
0 Kudos

Hi Guru's

I want to Download a file into my Presentation server, without specifying the file path

But it should ask me the filepath while execution

I think it is done by GUI_DOWNLOAD but any sample code will help me..

Regards,

PAVAN

17 REPLIES 17

Former Member
0 Kudos

TRY just DOWNLOAD with normal options,This triggers the File name pop up while execution...

Former Member
0 Kudos

Hi,

use this below code.This will prompt for the file name while execution only.

data: lv_filename type string,

lv_fname type string,

lv_path type string,

lv_fpath type string.

lv_filename = pc_path.

call method cl_gui_frontend_services=>file_save_dialog

EXPORTING

  • WINDOW_TITLE =

  • DEFAULT_EXTENSION =

DEFAULT_FILE_NAME = lv_filename

  • WITH_ENCODING =

  • FILE_FILTER =

  • INITIAL_DIRECTORY =

  • PROMPT_ON_OVERWRITE = 'X'

changing

filename = lv_fname

path = lv_path

fullpath = lv_fpath

  • USER_ACTION =

  • FILE_ENCODING =

EXCEPTIONS

CNTL_ERROR = 1

ERROR_NO_GUI = 2

NOT_SUPPORTED_BY_GUI = 3

others = 4.

if not lv_fpath is initial.

lv_filename = lv_fpath.

call function 'GUI_DOWNLOAD'

exporting

filename = lv_filename

  • FILETYPE = 'ASC'

  • HAS_FIELD_SEPARATOR = ' '

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • VIRUS_SCAN_PROFILE =

  • IMPORTING

  • FILELENGTH =

  • HEADER =

tables

data_tab = t_zfeld

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17.

endif.

Regards,

savitha

Message was edited by: savitha m

0 Kudos

I can use that but what is

lv_filename = pc_path.

pc_path .

Regards,

PAVAN.

0 Kudos

Hello Savitha ,

Can U Plz explain me what is that

lv_filename = pc_path.

here what is pc_path .

will it work if I use it directly ,

Plz help me .

Regards,

PAVAN .

0 Kudos

Hi Pavan,

pc_path is for fetching the filename from the presentation layer which will take the path given in the popup window and yes you can use it with out specifying the path details in the code....

Regards,

Santosh P

0 Kudos

Hi Savitha ,

Thanks for Ur Valuable suggestion .

But, while dowloading it into any Excel file iam getting all my fields only into one tab ie A in Excel .

How to resolve this

Regards,

PAVAN .

Former Member
0 Kudos

Hi

Why don't you want to specify the path? How will you save your file?

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = 'C:\MY_FILE.TXT'

TABLES

DATA_TAB = T_file.

If you want to have the chance to select the path from your presentation server, use the event AT SELECTION-SCREEN ON VALUE REQUEST.

Here you can use the method FILE_SAVE_DIALOG of CL_GUI_FRONTEND_SERVICES or fm WS_FILENAME_GET.

PARAMETERS: P_FILE(100).

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

DEF_FILENAME = P_FILE

MASK = ',. ,..'

IMPORTING

filename = p_file

......

Max

Message was edited by: max bianchi

Former Member
0 Kudos

Hi

u need to use this code.

selection-screen begin of block b1 with frame .

PARAMETER : FILE(100) lower case.

selection-screen end of block b1.

DATA: BEGIN OF TI_RECORD OCCURS 1,

LINE(200),

END OF TI_RECORD.

itab-line = 'agfgfhkf'.

append itab.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR FILE.

<b>CALL FUNCTION 'WS_FILENAME_GET'</b>

<b>*This will ask rhe file path.</b>

EXPORTING

  • DEF_FILENAME = ' '

DEF_PATH = '.'

  • MASK = ' '

  • MODE = ' '

  • TITLE = ' '

IMPORTING

FILENAME = FILE

  • RC =

.

End-of-selection.

data: TXT_FILE1 TYPE STRING .

txt_file1 = file.

<b> CALL FUNCTION 'GUI_DOWNLOAD'</b>

  • this will take the content of itab to the file path

EXPORTING

FILENAME = txt_file1

FILETYPE = 'ASC'

TABLES

DATA_TAB = ti_record.

<b>0r</b>

use this to get ur file path.

PARAMETERS:P_FILE LIKE RLGRAP-FILENAME.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = SYST-CPROG

DYNPRO_NUMBER = SYST-DYNNR

IMPORTING

FILE_NAME = P_FILE.

regards,

vijay

get back for help.

Former Member
0 Kudos

Hi Pavan,

The function module 'DOWNLOAD' is obselete anyways and can be deleted any time hence I suggest that you call the file save dialog which had been suggested above and then use a GUI_DOWNLOAD.

Regards,

Srikanth

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

The following is taken from function module documentation.You need to call CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG before calling the GUI_DOWNLOAD.Kindly reward points by clicking the star on the left of reply,if it helps.

Data transmission of an internal table from the server to a file on the PC. The module Gui_Download replaces the obsolete modules Ws_Download and Download. The file dialog for the download module is available in the class Cl_Gui_Frontend_Services.

Further Information

TYPE-POOLS: ABAP.

  • Binary download table

DATA: BEGIN OF line_bin,

data(1024) TYPE X,

END OF line_bin.

DATA: data_tab_bin LIKE STANDARD TABLE OF line_bin.

  • Ascii download table

DATA: BEGIN OF line_asc,

text(1024) TYPE C,

END OF line_asc.

DATA: data_tab_asc LIKE STANDARD TABLE OF line_asc.

  • DAT download table

DATA: BEGIN OF line_dat,

Packed TYPE P, Text(10) TYPE C,

Number TYPE I,

Date TYPE D,

Time TYPE T,

Float TYPE F,

Hex(3) TYPE X,

String TYPE String,

END OF line_dat.

DATA: data_tab_dat LIKE STANDARD TABLE OF line_dat.

  • Get filename

DATA: fullpath TYPE String,

filename TYPE String,

path TYPE String,

user_action TYPE I,

encoding TYPE ABAP_ENCODING.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG

EXPORTING

WINDOW_TITLE = 'Gui_Download Demo'

WITH_ENCODING = 'X'

INITIAL_DIRECTORY = 'C:\'

CHANGING

FILENAME = filename

PATH = path

FULLPATH = fullpath

USER_ACTION = user_action

FILE_ENCODING = encoding

EXCEPTIONS

CNTL_ERROR = 1

ERROR_NO_GUI = 2

NOT_SUPPORTED_BY_GUI = 3

others = 4.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

IF user_action <> CL_GUI_FRONTEND_SERVICES=>ACTION_OK.

EXIT.

ENDIF.

  • Download variables

DATA: length TYPE I.

  • Binary download

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = fullpath

FILETYPE = 'BIN'

IMPORTING

FILELENGTH = length

TABLES

DATA_TAB = data_tab_bin

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6

HEADER_NOT_ALLOWED = 7

SEPARATOR_NOT_ALLOWED = 8

FILESIZE_NOT_ALLOWED = 9

HEADER_TOO_LONG = 10

DP_ERROR_CREATE = 11

DP_ERROR_SEND = 12

DP_ERROR_WRITE = 13

UNKNOWN_DP_ERROR = 14

ACCESS_DENIED = 15

DP_OUT_OF_MEMORY = 16

DISK_FULL = 17

DP_TIMEOUT = 18

FILE_NOT_FOUND = 19

DATAPROVIDER_EXCEPTION = 20

CONTROL_FLUSH_ERROR = 21

OTHERS = 22.

  • Ascii download

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = fullpath

FILETYPE = 'ASC'

IMPORTING

FILELENGTH = length

TABLES

DATA_TAB = data_tab_asc

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6

HEADER_NOT_ALLOWED = 7

SEPARATOR_NOT_ALLOWED = 8

FILESIZE_NOT_ALLOWED = 9

HEADER_TOO_LONG = 10

DP_ERROR_CREATE = 11

DP_ERROR_SEND = 12

DP_ERROR_WRITE = 13

UNKNOWN_DP_ERROR = 14

ACCESS_DENIED = 15

DP_OUT_OF_MEMORY = 16

DISK_FULL = 17

DP_TIMEOUT = 18

FILE_NOT_FOUND = 19

DATAPROVIDER_EXCEPTION = 20

CONTROL_FLUSH_ERROR = 21

OTHERS = 22.

  • DAT download

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = fullpath

FILETYPE = 'DAT'

IMPORTING

FILELENGTH = length

TABLES

DATA_TAB = data_tab_dat

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6

HEADER_NOT_ALLOWED = 7

SEPARATOR_NOT_ALLOWED = 8

FILESIZE_NOT_ALLOWED = 9

HEADER_TOO_LONG = 10

DP_ERROR_CREATE = 11

DP_ERROR_SEND = 12

DP_ERROR_WRITE = 13

UNKNOWN_DP_ERROR = 14

ACCESS_DENIED = 15

DP_OUT_OF_MEMORY = 16

DISK_FULL = 17

DP_TIMEOUT = 18

FILE_NOT_FOUND = 19

DATAPROVIDER_EXCEPTION = 20

CONTROL_FLUSH_ERROR = 21

OTHERS = 22.

Former Member
0 Kudos

Hi pavan,

1. its better to use a parameter

on selection screen

where the user can SELECT file

or type the file name.

2. try this code (just copy paste in new program)

REPORT yhrb_bdc_pb40 .

*----


  • DATA

*----


DATA : file_name TYPE string.

DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.

*----


  • INITIALIZATION

*----


INITIALIZATION.

*----


  • SELECTION SCREEN

*----


SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

PARAMETERS : p_file LIKE rlgrap-filename

OBLIGATORY.

SELECTION-SCREEN END OF BLOCK b1.

*----


  • AT SELECTION SCREEN

*----


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CLEAR p_file.

CALL FUNCTION 'F4_FILENAME'

IMPORTING

file_name = p_file.

file_name = p_file.

*----


  • START OF SELECTION

*----


START-OF-SELECTION.

select * from t001 into table t001.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

filename = file_name

  • FILETYPE = 'ASC'

  • APPEND = ' '

  • WRITE_FIELD_SEPARATOR = ' '

  • HEADER = '00'

  • TRUNC_TRAILING_BLANKS = ' '

  • WRITE_LF = 'X'

  • COL_SELECT = ' '

  • COL_SELECT_MASK = ' '

  • DAT_MODE = ' '

  • CONFIRM_OVERWRITE = ' '

  • NO_AUTH_CHECK = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • WRITE_BOM = ' '

  • TRUNC_TRAILING_BLANKS_EOL = 'X'

  • WK1_N_FORMAT = ' '

  • WK1_N_SIZE = ' '

  • WK1_T_FORMAT = ' '

  • WK1_T_SIZE = ' '

  • IMPORTING

  • FILELENGTH =

TABLES

data_tab = t001

  • FIELDNAMES =

  • EXCEPTIONS

  • FILE_WRITE_ERROR = 1

  • NO_BATCH = 2

  • GUI_REFUSE_FILETRANSFER = 3

  • INVALID_TYPE = 4

  • NO_AUTHORITY = 5

  • UNKNOWN_ERROR = 6

  • HEADER_NOT_ALLOWED = 7

  • SEPARATOR_NOT_ALLOWED = 8

  • FILESIZE_NOT_ALLOWED = 9

  • HEADER_TOO_LONG = 10

  • DP_ERROR_CREATE = 11

  • DP_ERROR_SEND = 12

  • DP_ERROR_WRITE = 13

  • UNKNOWN_DP_ERROR = 14

  • ACCESS_DENIED = 15

  • DP_OUT_OF_MEMORY = 16

  • DISK_FULL = 17

  • DP_TIMEOUT = 18

  • FILE_NOT_FOUND = 19

  • DATAPROVIDER_EXCEPTION = 20

  • CONTROL_FLUSH_ERROR = 21

  • OTHERS = 22

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

regards,

amit m.

Former Member
0 Kudos

Thanks for Ur Replys

Actually Iam having 10 internal tables and I want to download data from IT 2 when ever I feel I require

Means I can't give it as Parameter, why Bcoz If I don't want to dowload I should not do , Iam providing a Button on application Tool bar for whenever I wish to Dowload the data then I'll .

Plz help me

Regards,

PAVAN .

0 Kudos

Hi pavan,

U dont have to declare any parameter.Inside the button code just put the above mentioned code . populate ur internal table into T_zfeld and pass that internal table.

Hope this helps.

Regards,

Savitha

0 Kudos

hi Pavan

In that case try using check boxes for multiple Internal table data selection else the Radio Buttons for a Single Internal Table data selection ..

Hope this helps..

Regards,

Santosh P

0 Kudos

Hi Pavan

The other way is check for the SY-UCOMi.i.e, if SY-UCOM = 'X' and then fetch the data into IT2.

Hope this helps,

Regards,

Santosh P

0 Kudos

Declare pc_path as below

DATA: pc_path LIKE rlgrap-filename."File Name

u dont have to pass any value to pc_path.

just assign pc_path with blank value to lv_filename

lv_filename = pc_path.

Message was edited by: savitha m

0 Kudos

Pavan,

pc_path could just be a default value.

pc_path type string value 'C:/test.txt'.

lv_filename = pc_path.

Regards,

Suresh Datti