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 using GUI_download

Former Member
0 Kudos

Hi all,

i am trying to download the internal table which have 10 field, into the EXCEL file,

at the same time i wanted into the downloaded file

field name also appear....how can we do that,,

while downloading its appearing in a one column,

i want to shift the every field in different column,

Any idea about that how i will acheive this

Thanks for your help..

Manish

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi manish,

1. For the same purpose

i have developed an INDEPENDENT SUBROUTINE/FORM

in which we pass just two things :

a) itab

b) file name with full path

2. It then downloads the file

(ALONG WITH THE FIELD NAMES AT THE TOP)

(We have to use GUI_DOWNLOAD two times,

once for downloading data,

and once for downloading the field names separated

by tab)

3. Just copy paste in new program.

report abc.

*----


data : itab like table of t001 with header line.

*----


select * from t001 into table itab.

perform mydownload tables itab using 'D:\t001.txt'.

*----


  • INDEPENDENT FORM

*----


form mydownload tables ptab using filename.

*----


DAta

DATA : components LIKE rstrucinfo OCCURS 0 WITH HEADER LINE.

DATA : allfields(300) TYPE c.

DATA : fld(100) TYPE c.

data : begin of htab occurs 0,

allfields(300) type c,

end of htab.

*----


Get component list

CALL FUNCTION 'GET_COMPONENT_LIST'

EXPORTING

program = sy-repid

fieldname = 'ITAB'

TABLES

components = components.

*----


construct

LOOP AT components.

CONCATENATE components-compname

CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB INTO fld.

CONCATENATE allfields fld INTO allfields .

ENDLOOP.

htab-allfields = allfields.

append htab.

*----


download first field list

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

FILENAME = 'D:\t001.txt'

WRITE_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = htab

.

*----


then download file data

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

FILENAME = filename

APPEND = 'X'

WRITE_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = ptab

.

endform.

regards,

amit m.

8 REPLIES 8

Former Member
0 Kudos

Hai Manish

DATA: D_FILENAME TYPE STRING,

D_FILEPATH TYPE STRING,

D_FULLPATH TYPE STRING,

L_FILETYPE TYPE CHAR10.

IF L_FILETYPE = 'ASC'.

L_FILETYPE = 'ASC'.

ELSE.

L_FILETYPE = 'DAT'.

ENDIF.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG

CHANGING

FILENAME = D_FILENAME

PATH = D_FILEPATH

FULLPATH = D_FULLPATH

EXCEPTIONS

CNTL_ERROR = 1

ERROR_NO_GUI = 2

NOT_SUPPORTED_BY_GUI = 3

others = 4

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

IF NOT D_FULLPATH IS INITIAL.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = D_FULLPATH

FILETYPE = L_FILETYPE

TABLES

DATA_TAB = T_DOWNLOAD.

Thanks & regards

Sreeni

Former Member
0 Kudos

Hi,

While downloading file, we wont get the header part, we have to append the header part before the data. Then we pass the final output table with header to the function module.

So that it will read the first line that will be header and then remaning data.

We can create an internal table.

TYPES: begin of ty_itab ,

name(4) TYPE c,

age(3) Type c,

end of ty_itab.

DATA: i_itab type standard table of ty_itab,

w_itab type ty_itab.

Then do as below.

w_itab-name = 'NAME'.

w_itab-age = 'AGE'.

APPEND w_itab to i_output_final.

i_output[] = i_output_final.

APPEND i_output_final.

Pass this final table to the functionmodule, which is now with header.

Hope that solves your problem.

Chek this link for an example code:

Also chek out http://www.sapdevelopment.co.uk/file/file_updown.htm for more info on download and upload.

Regards,

Anjali

Former Member
0 Kudos

Hi manish,

1. For the same purpose

i have developed an INDEPENDENT SUBROUTINE/FORM

in which we pass just two things :

a) itab

b) file name with full path

2. It then downloads the file

(ALONG WITH THE FIELD NAMES AT THE TOP)

(We have to use GUI_DOWNLOAD two times,

once for downloading data,

and once for downloading the field names separated

by tab)

3. Just copy paste in new program.

report abc.

*----


data : itab like table of t001 with header line.

*----


select * from t001 into table itab.

perform mydownload tables itab using 'D:\t001.txt'.

*----


  • INDEPENDENT FORM

*----


form mydownload tables ptab using filename.

*----


DAta

DATA : components LIKE rstrucinfo OCCURS 0 WITH HEADER LINE.

DATA : allfields(300) TYPE c.

DATA : fld(100) TYPE c.

data : begin of htab occurs 0,

allfields(300) type c,

end of htab.

*----


Get component list

CALL FUNCTION 'GET_COMPONENT_LIST'

EXPORTING

program = sy-repid

fieldname = 'ITAB'

TABLES

components = components.

*----


construct

LOOP AT components.

CONCATENATE components-compname

CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB INTO fld.

CONCATENATE allfields fld INTO allfields .

ENDLOOP.

htab-allfields = allfields.

append htab.

*----


download first field list

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

FILENAME = 'D:\t001.txt'

WRITE_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = htab

.

*----


then download file data

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

FILENAME = filename

APPEND = 'X'

WRITE_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = ptab

.

endform.

regards,

amit m.

Former Member
0 Kudos

Hi Manish

You can use 'DOWNLOAD' function instead of 'GUI_DOWNLOAD'.

here you can pass field names in fieldname parameter

CALL FUNCTION 'DOWNLOAD'

EXPORTING

FILENAME = 'c:\download.xls'

FILETYPE = 'DBF'

FILETYPE_NO_SHOW = 'X'

TABLES

DATA_TAB = it_download

FIELDNAMES = IT_FIELDNAMES

  • EXCEPTIONS

  • INVALID_FILESIZE = 1

  • INVALID_TABLE_WIDTH = 2

  • INVALID_TYPE = 3

  • NO_BATCH = 4

  • UNKNOWN_ERROR = 5

  • GUI_REFUSE_FILETRANSFER = 6

  • CUSTOMER_ERROR = 7

  • OTHERS = 8

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

Best Regards

Naresh

Former Member
0 Kudos

HI

As you mention the example that is for just downloading..

but out put is in excel,

so all the field is appearing in 1 column,

how i will seprated in differnt column....

0 Kudos

Hi again,

1. Since the data is stored

using TAB delimiter,

2. we have to open the file

using excel and choose

the option of TAB Delimited.

3. Then it will come in all different columns.

regards,

amit m.

Former Member
0 Kudos

one simple way way is to call GUI_DOWNLOAD 2 times.

first call the GUI_DOWNLOAD function module with tables = it_fieldnames.

data : begin of it_fieldnames occurs 0,

col_text(100) type c,

end of it_fieldnames.

*-now populate text to this it_fieldnames.

it_fieldnames-col_text = 'column1'.

append it_fieldnames.

it_fieldnames-col_text = 'column2'.

append it_fieldnames.

*--and so on...

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = 'c:\err_file.xls'

FILETYPE = 'ASC'

WRITE_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = it_fieldnames

EXCEPTIONS

FILE_WRITE_ERROR = 1

*--

second again call GUI_DOWNLOAD with

filename = 'c:\err_file.xls' (give same file name)

APPEND = 'X'

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

FILENAME = <GIVE samefile anme as above'

FILETYPE = 'ASC'

<b> append = 'X'</b> WRITE_FIELD_SEPARATOR = 'X'

  • IMPORTING

  • FILELENGTH =

TABLES

DATA_TAB = it_final

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

now you can see both column headings with data.

regards

srikanth

Former Member
0 Kudos

Here is the program i created with will download mara details with Column headings in columnar format

check this out.

regards

srikanth

REPORT ZSRIM_TEMP1.

data : begin of it_fieldnames occurs 0,

col_text(100) type c,

end of it_fieldnames.

*-now populate text to this it_fieldnames.

data : begin of itab occurs 0,

matnr type mara-matnr,

ersda type mara-ersda,

end of itab.

select matnr

ersda

into table itab

up to 10 rows

from mara

where matnr <> space.

it_fieldnames-col_text = 'column1'.

append it_fieldnames.

it_fieldnames-col_text = 'column2'.

append it_fieldnames.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = 'C:\fil1.xls'

FILETYPE = 'ASC'

WRITE_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = ITAB

FIELDNAMES = IT_FIELDNAMES

.

IF SY-SUBRC <> 0.

ENDIF.

removed unwanted parameters in Function module call

Message was edited by: Srikanth Kidambi