12-23-2010 10:25 AM
Hi ,
We hav a program , in that we upload data in application server as text format.The data need to sent to application server as EXCEL file format.
Please help me how to send data in to application server as '.xls' ?
we are using Datasets to transfer data into aplication server as text format.
Thanks,
Balu.
12-23-2010 4:51 PM
T e s t e d C o d e **
S U C C E S S F U L L Y**
DATA: LW_TEXT(500),
LW_OUTFILE TYPE TYPE_OUTFILE.
P_UXOUTF = '.../TEST.XLS
OPEN DATASET P_UXOUTF FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC NE 0.
MESSAGE 'Outfile open failed' TYPE 'E'.
ELSE.
LOOP AT I_OUTFILE INTO LW_OUTFILE.
CLEAR LW_TEXT.
CONCATENATE LW_OUTFILE-ONE
LW_OUTFILE-TWO
LW_OUTFILE-THREE
LW_OUTFILE-FOUR
LW_OUTFILE-FIVE
INTO LW_TEXT SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
"Transfer file to Unix
TRANSFER LW_TEXT TO P_UXOUTF.
CLEAR LW_OUTFILE.
ENDLOOP.
CLOSE DATASET P_UXOUTF.
ENDIF.
T e s t e d C o d e **
S U C C E S S F U L L Y**
12-23-2010 10:31 AM
Just Transfer the text file with ',' as a separator then it will be a CSV file and then save it as CSV ...I guess...check if your Application server identifies a excel . Note ( CSV file Open with MS Excel too..! )
12-23-2010 11:10 AM
12-23-2010 11:14 AM
>
> Hi,
>
> You can check following link --
>
> [http://wiki.sdn.sap.com/wiki/display/Snippets/downloaddataintoexcelwith+header]
>
> Available code is sufficient to attend to your requirements.
>
> Thanks.
> Kumar Saurav.
Did you actually read what his requirement is? Download to APPLICATION SERVER and not DESKTOP
So please do tell me how your link would be to any benefit to him?
12-23-2010 11:55 AM
Just changing the extension will do. Rest all syntax are same for TXT and XLS to save it in application server.
12-23-2010 12:25 PM
Hi,
I am sending you the piece of code...please check it..
*****************************************************************************************************************
** declaring the file name...
data:
w_filename type string value 'file_save.xls'.
** Opening the Dataset.....
open dataset w_filename for output in text mode encoding default.
* Transfering data from workarea into file name, w_filename .
loop at itab into wa.
** Transferring one by one record
transfer wa to w_filename .
endloop. " LOOP AT t_burks INTO fs_burks
close dataset w_filename.
if sy-subrc eq 0.
message 'File created succesfully in SAP System'(002) type 'S'.
endif. " if sy-subrc ne 0
*********************************************************************************************************
.
Regards,
Suvajit.
12-23-2010 12:29 PM
HI,
You need to add the tab inbetween all the fields of internal table and upload to application server using
OPEN DATASET
TRANSFER
CLOSE DATASET.
to add the tab inbetween the fields..you can use this code....
concatenete itb-field1 itab-field2......... into string seperated by CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
one exception while uploading data to the Application server you need to convert dec or currency field to char type otherwise it will give you short dump.
12-23-2010 4:51 PM
T e s t e d C o d e **
S U C C E S S F U L L Y**
DATA: LW_TEXT(500),
LW_OUTFILE TYPE TYPE_OUTFILE.
P_UXOUTF = '.../TEST.XLS
OPEN DATASET P_UXOUTF FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC NE 0.
MESSAGE 'Outfile open failed' TYPE 'E'.
ELSE.
LOOP AT I_OUTFILE INTO LW_OUTFILE.
CLEAR LW_TEXT.
CONCATENATE LW_OUTFILE-ONE
LW_OUTFILE-TWO
LW_OUTFILE-THREE
LW_OUTFILE-FOUR
LW_OUTFILE-FIVE
INTO LW_TEXT SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
"Transfer file to Unix
TRANSFER LW_TEXT TO P_UXOUTF.
CLEAR LW_OUTFILE.
ENDLOOP.
CLOSE DATASET P_UXOUTF.
ENDIF.
T e s t e d C o d e **
S U C C E S S F U L L Y**
12-23-2010 5:12 PM
Hi,
- you can not create original MS excel format without using EXCEL.
- you can enclose all fields values in quotes (") and separate them by comma (,) to a C omma S eparated V alues aka CSV.
- you can separate the fields by tabulator (CL_ABAP_CHAR_UILITIES=>HORIZONTAL_TAB) and save them into tab-delimited text file with the extension .xls. Excel can read this.
- you can use advanced methods to save the values formatted as XHTML which is as good as excel. You can search for this, there are blogs. But I doubt that it's worth the effort.
Regards,
Clemens
12-23-2010 5:47 PM
Assuming you do not need any formatting, etc, then the CSV way may be the simplest way to go. If you do need some formatting, you can create data tables via HTML <TABLE> elements and name file file with an XLS extension, and also get an excel file to show up.
Neither of these ways creates a native excel file, however.
There is a tool provided through the blogs to do this. it creates native excel (xlsx) files in memory, without using Excel AT ALL. it writes to the new XML excel file format. I have used it a lot, and it works GREAT. you can do about ANYTHING excel can do, without excel, and save it to the app server, or email it or anything you want.
here is a place to start. there are good demos, too...
[http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/20046] [original link is broken] [original link is broken] [original link is broken];
See the links at the end of the blog, too for an updated version that allows reading. we created our own object for this using the techniques BORROWED from the author, before he had added the reading portion.
its really good work.
dave
12-24-2010 6:12 AM