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 ALV to Desktop

Former Member
0 Kudos

Hi All!

I have a Dialogue Program.In that I want to introduce a download button.Clicking on that button should allow me to download the ALV report to desktop in a excel sheet.

Secondly output in excel sheet should contain fields of ALV as well as 2 extra field form some other internal table.

Kindly suggest me a way how could I achieve it.

Help would be appreciated.

Regards

Sourabh

8 REPLIES 8

Former Member
0 Kudos

Hi,

use At user-command... and assign func code for ur download button.

to download use ws_download func module.

declare internal table with all the fields as in ALV + 3 extra fields as u requested. pass this internal table to ws_download.

Plz mark useful answers.

Regards

Divakar

anversha_s
Active Contributor
0 Kudos

hi sourabh,

it simple.

1.any way u r passing an internal table to ALV.

2.also 2 extra fields are there.

create an internal table with above two.

pass this internal table, when SY_UCOMM = 'DOWNLOAD'.

how to dnload.

chk this sample pgm

************************

REPORT ZSRIM_GUI_DOWNLOAD_TO_EXCEL.

data : itab type mara occurs 0 with header line.

select * into itab

from mara

up to 10 rows.

append itab.

endselect.

data : begin of itab1 occurs 0,

line(50) type c,

end of itab1.

itab1-line = 'field1 description'.

append itab1.

itab1-line = 'field2 desc'.

append itab1.

itab1-line = 'field3 desc'.

append itab1.

*--and so on you have to add up the records in itab1.

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE = ' '

  • CODEPAGE = ' '

FILENAME = 'C:\ABCD.XLS '

FILETYPE = 'DAT'

  • MODE = ' '

  • WK1_N_FORMAT = ' '

  • WK1_N_SIZE = ' '

  • WK1_T_FORMAT = ' '

  • WK1_T_SIZE = ' '

  • COL_SELECT = ' '

  • COL_SELECTMASK = ' '

  • NO_AUTH_CHECK = ' '

  • IMPORTING

  • FILELENGTH = FILELENGTH

TABLES

DATA_TAB = ITAB "ur new itab

FIELDNAMES = ITAB1

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_WRITE_ERROR = 2

INVALID_FILESIZE = 3

INVALID_TYPE = 4

NO_BATCH = 5

UNKNOWN_ERROR = 6

INVALID_TABLE_WIDTH = 7

GUI_REFUSE_FILETRANSFER = 8

CUSTOMER_ERROR = 9

NO_AUTHORITY = 10

OTHERS = 11

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

rgds

anver

if hlped mark points

0 Kudos

Hi Anversha!

your solution is indeed very helpful.But I have one more doubt.In the present solution the download path is hardcoded.I want to browse through the location where i can download my file.

Regards

sourabh

0 Kudos

hi saurabh,

do this.

PARAMETERS: p_flname(150) TYPE c OBLIGATORY. "file name

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_flname.

PERFORM f_getfile.

DATA : wf_filename LIKE rlgrap-filename.

FORM f_getfile .

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

def_filename = ' '

def_path = ' '

mask = ' '

mode = ' '

title = ' '

IMPORTING

filename = p_flname

EXCEPTIONS

inv_winsys = 1

no_batch = 2

selection_cancel = 3

selection_error = 4

OTHERS = 5.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM. " f_getfile

wf_filename = p_flname.

rgds

anver

if hlped mark points

Message was edited by: Anversha s

Former Member
0 Kudos

Hello,

Go for object oriented ALV, download option will be there by default.

Or, use the function module GUI_DOWNLOAD. Handle the sy-ucomm in PAI event and use that function module.

Regs,

Venkat Ramanan N

former_member223537
Active Contributor
0 Kudos

Hi,

1. Downloading to desktop is possible. ALV would be displayed with a standard toolbar. There is an EXPORT button. Click on the button, select SPREADSHEET, provide the path and it would be downloaded.

2. Inorder to add 2 more fields, better create you own button in PF-STATUS and when user clicks that button use GUI_DOWNLOAD button and pass the required internal table data to this FM. It will download on the specified path as an Excel file.

Check link :

Best regards,

Prashant

0 Kudos

You can use the Option in ALV menu bar to download into Desktop.

By default ALV provides this option, there is no need of special codind. Also you can download in notepad if the file size is very large.

regards

Vivek

reward points for useful answers

Former Member
0 Kudos

Hi

U can Use As Follows.

DATA : BEGIN OF IT_FIL_HEADINGS OCCURS 0,

COL(40) TYPE C,

END OF IT_FIL_HEADINGS.

Case ok_code.

WHEN 'DWND'.

PERFORM CREATE_DOWN_LOAD_FILE.

endcase.

FORM CREATE_DOWN_LOAD_FILE .

CLEAR IT_FIL_HEADINGS.

IT_FIL_HEADINGS-COL = 'Sales Ord. Num.'.

APPEND IT_FIL_HEADINGS.

CLEAR IT_FIL_HEADINGS.

IT_FIL_HEADINGS-COL = 'Item Lev. Num.'.

APPEND IT_FIL_HEADINGS.

CLEAR IT_FIL_HEADINGS.

IT_FIL_HEADINGS-COL = 'Product'.

APPEND IT_FIL_HEADINGS.

CLEAR IT_FIL_HEADINGS.

IT_FIL_HEADINGS-COL = 'Location'.

APPEND IT_FIL_HEADINGS.

CLEAR IT_FIL_HEADINGS.

IT_FIL_HEADINGS-COL = 'Delivery Date'.

APPEND IT_FIL_HEADINGS.

CLEAR IT_FIL_HEADINGS.

IT_FIL_HEADINGS-COL = 'Customer Ord. Num.'.

APPEND IT_FIL_HEADINGS.

CLEAR IT_FIL_HEADINGS.

IT_FIL_HEADINGS-COL = 'Commits'.

APPEND IT_FIL_HEADINGS.

CLEAR IT_FIL_HEADINGS.

IT_FIL_HEADINGS-COL = 'Actuals'.

APPEND IT_FIL_HEADINGS.

CLEAR IT_FIL_HEADINGS.

IT_FIL_HEADINGS-COL = 'Remarks'.

APPEND IT_FIL_HEADINGS.

CLEAR IT_TCL.

CLEAR FILE_NAME.

CONCATENATE 'C:\' 'Germany MTO Front End' '.XLS' INTO FILE_NAME.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = FILE_NAME

FILETYPE = 'ASC'

WRITE_FIELD_SEPARATOR = 'X'

  • DAT_MODE = 'X'

TABLES

DATA_TAB = IT_TCL

FIELDNAMES = IT_FIL_HEADINGS

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.

ENDFORM. " CREATE_UPLOAD_FILE

If u want Two Additional columns Then Ur Internal Table Should Contain those columns also

Regards

Ahasan