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: 

convert table data into EXCEL Format in Application Server using Datasets

former_member210642
Participant
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
    • 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**

10 REPLIES 10

anup_deshmukh4
Active Contributor
0 Kudos

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..! )

former_member186491
Contributor
0 Kudos

This message was moderated.

0 Kudos

>

> 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?

kesavadas_thekkillath
Active Contributor
0 Kudos

Just changing the extension will do. Rest all syntax are same for TXT and XLS to save it in application server.

Former Member
0 Kudos

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.

anjan_paul
Active Contributor
0 Kudos

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.

Former Member
0 Kudos
    • 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**

Clemenss
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

former_member210642
Participant
0 Kudos

Thanks