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

Hi experts,

I am downloading the internal table values to excel sheet using the

FM 'WS_DOWNLOAD'.

The issue is after downloading in the excel sheet I am getting the value field like below

PRICE

151.00

200.00

235

67

89.00

In internal table all the Price values has two decimal places, after downloading

some of the price is showing with decimal places some of them not

Can anybody show me why this is happening and hoe to slove

Thanks in advance

karthik

9 REPLIES 9

former_member386202
Active Contributor
0 Kudos

Hi,

Try FM

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

filename = p_path

filetype = 'ASC'

  • 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 = it_final

  • 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,

Prashant

Former Member
0 Kudos

Hi Karthik,

For these problems use FM 'GUI_DOWNLOAD'.Below is simple code for it.You will easily understand.

Plz do reward if useful.

Thankx.

report zhdownload.

data : begin of itab occurs 100,

f_matnr type matnr,

f_ersda type ersda,

f_ernam type ernam,

end of itab.

select matnr ersda ernam into table itab from mara up to 10 rows.

append itab.

data : begin of itab1 occurs 0,

line(50) type c,

end of itab1.

itab1-line = 'MATERIAL NUMBER'.

append itab1.

itab1-line = 'DATE'.

append itab1.

itab1-line = 'NAME'.

append itab1.

call function 'GUI_DOWNLOAD'

exporting

filename = 'C:\Documents and Settings\ak0020758\abc2.xls'

filetype = 'ASC'

write_field_separator = 'X'

  • IMPORTING

  • FILELENGTH =

tables

data_tab = itab

fieldnames = itab1 " for 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.

former_member1052991
Active Participant
0 Kudos

hi karthik,

You can use gui_download for this one.

Former Member
0 Kudos

u can use either of the 2 FMs below

GUI_DOWNLOAD

TEXT_CONVERT_XLS_TO_SAP

Hope dis will clear ur doubt..

Reward all helpful answers

Former Member
0 Kudos

Hi Karthik,

what ever FM you use either WS_DOWNLOAD or GUI_DOWNLOAD

Usually If you download any data from SAP to excel file with decimal values.. if there are any numeric after decimal then only it’ll display in excel sheet .

For example if value is 100.01 then display like 100.01

If value is 100.00 then it display like 100.

To overcome this problem after (or before ) download use formatting techniques in excel like

Select cell column in excel sheet> right click> format cells --> select category as ‘ Number’ and decimal places 2.

After this you can see 100 as 100.00

I hope this will solve your problem.

Message was edited by:

Perez C

0 Kudos

Hi Perez,

Thanks for the reply, You are correct even with Gui_download I got same results

but I got the values in excel sheet like 200.00 even formatting or without formatting the excel sheet but some cases it is displaying like 200 or 100.

I don't know why this is happening pls advice

thanks

karthik

0 Kudos

Ok....

you can do like this ..first download data to excel file....then apply format technique on particular field as explained you earlier..then close file and again download .. this time you won't see 200 or 100. all filed's should display like 200.00 and 100.00

0 Kudos

Hi Herez

Sorry I tryed formatting even though it is displaying the same results

Thanks

karthik

Former Member
0 Kudos

Hi

You can very well use the following fun modules for downloading data to EXCEL

GUI_DOWNLOAD

EXCEL_OLE_STANDARD_DAT

MS_EXCEL_OLE_STANDARD_DAT

Check this code:

PARAMETERS : P_FILE TYPE RLGRAP-FILENAME.

DATA: V_FILE TYPE P_FILE.

data: begin OF itab occurs 0,

matnr like mara-matnr,

end of itab.

data : begin of it_fieldnames occurs 0,

name(100),

end of it_fieldnames.

START-OF-SELECTION.

it_fieldnames-name = 'MATNR'.

APPEND IT_FIELDNAMES.

MOVE P_FILE TO V_FILE.

select matnr from mara into table itab UP TO 10 ROWS.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

FILENAME = V_FILE

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

FIELDNAMES = IT_FIELDNAMES .