2011 Aug 19 9:59 AM
Hi Experts,
I am downloading data from Excel file which is saved on local desktop i.e. Presentation server into internal table.
Changing internal table data and uploading it back to same Excel sheet
Tried using FM 'MS_EXCEL_OLE_STANDARD_DAT'.
Issues faced:
1) New file is getting generated and existing one is not getting edited.
2) While executing the program the newly created Excel file opens as a pop up. I want to avoid this.
Please help.
Hi Experts,
I am downloading data from Excel file which is saved on local desktop i.e. Presentation server into internal table.
Changing internal table data and uploading it back to same Excel sheet
Tried using FM 'MS_EXCEL_OLE_STANDARD_DAT'.
Issues faced:
1) New file is getting generated and existing one is not getting edited.
2) While executing the program the newly created Excel file opens as a pop up. I want to avoid this.
Please help.
2011 Aug 19 10:11 AM
If I get this correctly, you want to edit exisiting file getting new data downloaded. Why don't you simply upload data from excel to SAP (internal table), add whatever you need to it or change it, then save data back to file overwritting it.
By FM MS_EXCEL_OLE_STANDARD_DAT I believe standard OLE starts working so it is like editing Excel file in place (like opening it manually and adding content). If such edition is not required, use download function like GUI_DOWNLOAD. Performance will not suffer here and no issues with OLE playing stuff, just pure data download.
Regards
Marcin
2011 Aug 19 10:17 AM
Yes Marcin, you got it right.
I want to update existing file.
I used FM 'TEXT_CONVERT_XLS_TO_SAP' to upload data from Excel to SAP(internal table). Performed changes.
Can you please tell, How can I download this new internal table to the existing file by overwriting it?
2011 Aug 19 10:54 AM
Hi,
I would recommend you to use 'GUI_UPLOAD' and then 'GUI_DOWNLOAD'.
Regards,
Pranav.
2011 Aug 19 1:10 PM
Thanks Pranav,
We can't use GUI_UPLOAD for Excel files.
So my procedure of using TEXT_CONVERT_XLS_TO_SAP FM is correct.
Can you just help me in knowing which FM can help me in DOWNLOADING the internal table data to local Excel file.
If it's GUI_DOWNLOAD then what should be the parameters?
I tried using the File path same as I got in my selection screen as Parameter to GUI_DOWNLOAD. But getting the dump saying
"The function module interface allows you to specify only fields of a particular type under "FILENAME". The field "P_FILE" specified here has a different field type."
Tried copying the value of "P_FILE" into STRING, which is the field type of "FILENAME"(Import parameter of FM). But still error persists.
Edited by: justfun87 on Aug 19, 2011 2:10 PM
2011 Aug 19 1:27 PM
Hi
PARAMETER P_file like RLGRAP-FILENAME
data : begin of int_head occurs 0,
Filed1(20) type c, " Header Data
end of int_head.
int_head-Filed1 = 'PLTNY'.
APPEND int_head.
CLEAR int_head.
int_head-Filed1 = 'WERKS'.
APPEND int_head.
CLEAR int_head.
int_head-Filed1 = 'KTEXT'.
APPEND int_head.
CLEAR int_head.
Select plnty werks ktext from plko into CORRESPONDING FIELDS OF TABLE itab
Where plnty = 'Q' .
v_filetype = '.xls'. "I just manipulate the file name using XLS file type.
v_filename = p_file.
CONCATENATE p_file v_filetype INTO lv_filename.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = lv_filename
filetype = 'ASC'
write_field_separator = 'X'
TABLES
data_tab = ITAB
FIELDNAMES = int_head
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.
ENDIF.
ENDFORM.
2011 Aug 19 1:41 PM
Thanks Devireddy for your reply.
I already got it done before you reply.
Bit correction in your code. You don't need to concatenate ".xls" to the existing filename. Because if you do so new file will get created. e.g. You inserted P_FILE = ABC.XLS. New file will be "ABC.XLS.XLS.
In order to avoid dump, which you might get if you pass P_FILE directly to "FILENAME" parameter of FM GUI_DOWNLOAD you need to copy the P_FILE into STRING type variable.