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 to Excel

Former Member
0 Kudos

I need a function to download a internal table to excel. I am using the function 'WS_DOWNLOAD', but it downloads all the dats in a unique column.

How can I do it in several columns??

Thanks

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Try using the FM " SAP_CONVERT_TO_XLS_FORMAT"

Example:

PARAMETERS: p_file LIKE rlgrap-filename DEFAULT 'H:\TESTSAP.xls'.

CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'

EXPORTING

i_filename = p_file

TABLES

i_tab_sap_data = tab_etab.

Here the Tab_etab contains the data to be displayed in escel.

Also try FM " ALSM_EXCEL_TO_INTERNAL_TABLE "

Hope it helps u.

Thanks,

Ruthra

6 REPLIES 6

Former Member
0 Kudos

Hi,

You can use

CALL FUNCTION 'DOWNLOAD'
    EXPORTING
*   BIN_FILESIZE                  = ' '
*   CODEPAGE                      = ' '
      filename                      = pcfile
      filetype                      = 'DAT'
*   ITEM                          = ' '
*   MODE                          = ' '
*   WK1_N_FORMAT                  = ' '
*   WK1_N_SIZE                    = ' '
*   WK1_T_FORMAT                  = ' '
*   WK1_T_SIZE                    = ' '
      filemask_mask                 = '*.XLS'
      filemask_text                 = 'Excel_Files'
*   FILETYPE_NO_CHANGE            = ' '
*   FILEMASK_ALL                  = ' '
*   FILETYPE_NO_SHOW              = ' '
*   SILENT                        = 'S'
*   COL_SELECT                    = ' '
*   COL_SELECTMASK                = ' '
*   NO_AUTH_CHECK                 = ' '
* IMPORTING
*   ACT_FILENAME                  =
*   ACT_FILETYPE                  =
*   FILESIZE                      =
*   CANCEL                        =
    TABLES
      data_tab                      = tab
      fieldnames                    = fields
   EXCEPTIONS
     invalid_filesize              = 1
     invalid_table_width           = 2
     invalid_type                  = 3
     no_batch                      = 4
     unknown_error                 = 5
     gui_refuse_filetransfer       = 6
     OTHERS                        = 7.

Where pcfile is the file name.

and tab is the internal table which contains data.

fields is internal table which contains column headers.

Hope this helps.

Cheers,

Tatvagna.

Former Member
0 Kudos

use FM ALSM_to_EXCEL_internal_table.

if doesnot exist, search in SE37 with "alsmexcel".

regards,

naveen

former_member70391
Contributor
0 Kudos

Hi Oscar,

Just an information,

Function Module WS_DOWNLOAD is obsolete. Please use GUI_DOWNLOAD instead.

Thanks & Regards,

Nagaraj Kalbavi

Former Member
0 Kudos

Hi,

Try using the FM " SAP_CONVERT_TO_XLS_FORMAT"

Example:

PARAMETERS: p_file LIKE rlgrap-filename DEFAULT 'H:\TESTSAP.xls'.

CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'

EXPORTING

i_filename = p_file

TABLES

i_tab_sap_data = tab_etab.

Here the Tab_etab contains the data to be displayed in escel.

Also try FM " ALSM_EXCEL_TO_INTERNAL_TABLE "

Hope it helps u.

Thanks,

Ruthra

naveen_inuganti2
Active Contributor
0 Kudos

Hi..,,

Try this code..,

> p_file = file name .xls'.

>

> CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG

> EXPORTING

> DEFAULT_FILE_NAME = p_file

> CHANGING

> FILENAME = p_path

> PATH = p_path

> FULLPATH = p_file

> 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 p_file is initial.

> Message 'File name and path not found' type 'E'.

> endif.

>

> CALL FUNCTION 'GUI_DOWNLOAD'

> EXPORTING

>* BIN_FILESIZE =

> FILENAME = p_file

> FILETYPE = 'DAT'

>* APPEND = ' '

> WRITE_FIELD_SEPARATOR = 'X'

>* 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 = itab

> FIELDNAMES = titles

> 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 ne 0.

> message 'Error Downloading data to excel' type 'E'.

> endif.

> endif.

Fill the title internal table and itab with required input....

Thanks,

Naveen.I

RoySayak
Active Participant
0 Kudos

Hi,

Try with this two FM's:

> SAP_CONVERT_TO_XLS_FORMAT

> ALSM_EXCEL_TO_INTERNAL_TABLE

Best Regards,

Sayak...

"Giving points for helpful answer is always appreciating"