cancel
Showing results for 
Search instead for 
Did you mean: 

Download files in excel format

Former Member
0 Kudos

Hi,

Can anyone help me for downloading file in excel format? I have scheduled a job repeated everyday at a particular time, but it dumps a text file, NOT in excel format. My programme is an ALV.

Code snippet would be verymuch helpfull.

Thank,

Thushara.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

I am hoping that you are downloading your data to your application server. You cannot deal with your presentation server in the background job.

You will have to use the OPEN / TRANSFER / CLOSE DATASET to write to the file and after that you can manually move the file to presenation server using CG3Y transaction.


DATA FNAME(60) VALUE 'myfile'.

TYPES: BEGIN OF LINE,
         COL1 TYPE I,
         COL2 TYPE I,
       END OF LINE.

TYPES  ITAB TYPE LINE OCCURS 10.

DATA: LIN TYPE LINE,
      TAB TYPE ITAB.

DO 5 TIMES.
  LIN-COL1 = SY-INDEX.
  LIN-COL2 = SY-INDEX ** 2.
  APPEND LIN TO TAB.
ENDDO.

OPEN DATASET FNAME FOR OUTPUT.
LOOP AT TAB INTO LIN.
  TRANSFER LIN TO FNAME.
ENDLOOP.
CLOSE DATASET FNAME.

Regards,

Ravi

Note :Please mark the helpful answers

Answers (5)

Answers (5)

Former Member
0 Kudos

Eventhough the answers are not completly solved my prob, those were quite helpful

Former Member
0 Kudos

HI

GOOD

GO THROUGH THESE LINKS.

http://www.finance.utoronto.ca/Page662.aspx

/people/sap.user72/blog/2006/02/07/downloading-data-into-excel-with-format-options

http://searchsap.techtarget.com/tip/1,289483,sid21_gci1080995,00.html?bucket=ETA

THANKS

MRUTYUN

Former Member
0 Kudos

Hi thushara,

1. There are two major points here :

a) background job (and not front-end server )

b) Excel file (and not text file)

2. When we run background job,

we cannot use function modules like

gui_download

to save files.

We have to use OPEN DATASET, TRANSFER, CLOSE DATASET

commands,

which will write the file on

the APPLICATION SERVER (and the front-end server)

3. Excel file.

Since the file is going to be written on

application server,

the application servers OS

may not be Microsoft OS.

(It may be Unix, Aix etc) which do not

support microsoft products directly.

Hence, we cannot write / neither there

is any FM to write file in EXCEL

on the application server.

4. Its better to write the file

in TEXT format.

regards,

amit m.

Former Member
0 Kudos

Hello Thushara,

here is a code i am giving you . It will take the data from a database , and download it into the excel format..

You just can customize this program to download the data from an ALV ....

Here is the sample code...

REPORT ZKUN_FILE4 .

TABLES: USR03,DD02L.

DATA: ZX030L LIKE X030L.

DATA BEGIN OF ZDFIES OCCURS 0.

INCLUDE STRUCTURE DFIES.

DATA END OF ZDFIES.

DATA: BEGIN OF FLDITAB OCCURS 0,

FLDNAME(11) TYPE C,

END OF FLDITAB.

DATA ITABUSR03 LIKE USR03 OCCURS 0 WITH HEADER LINE.

DATA TNAME LIKE DD02L-TABNAME.

SELECT * FROM USR03 INTO TABLE ITABUSR03.

TNAME = 'USR03'.

PERFORM GETFIELEDS.

PERFORM SHOW123.

********************************************

FORM GETFIELEDS.

CALL FUNCTION 'GET_FIELDTAB'

EXPORTING

LANGU = SY-LANGU

ONLY = SPACE

TABNAME = TNAME

WITHTEXT = 'X'

IMPORTING

HEADER = ZX030L

TABLES

FIELDTAB = ZDFIES

EXCEPTIONS

INTERNAL_ERROR = 01

NO_TEXTS_FOUND = 02

TABLE_HAS_NO_FIELDS = 03

TABLE_NOT_ACTIV = 04.

CASE SY-SUBRC.

WHEN 0.

LOOP AT ZDFIES.

FLDITAB-FLDNAME = ZDFIES-FIELDNAME.

APPEND FLDITAB.

ENDLOOP.

WHEN OTHERS.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

with SY-SUBRC.

ENDCASE.

ENDFORM.

***********************************

FORM SHOW123.

CALL FUNCTION 'EXCEL_OLE_STANDARD_DAT'

EXPORTING

FILE_NAME = 'C:\USR03.XLS'

DATA_SHEET_NAME = 'USER LIST'

TABLES

DATA_TAB = ITABUSR03

FIELDNAMES = FLDITAB

EXCEPTIONS

FILE_NOT_EXIST = 1

FILENAME_EXPECTED = 2

COMMUNICATION_ERROR = 3

OLE_OBJECT_METHOD_ERROR = 4

OLE_OBJECT_PROPERTY_ERROR = 5

INVALID_FILENAME = 6

INVALID_PIVOT_FIELDS = 7

DOWNLOAD_PROBLEM = 8

OTHERS = 9.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM.

*****************************************************

Hope this solves your problem.

Regards,

Kunal.

Note : Reward points if found useful.

Former Member
0 Kudos

Hi,

You cannot download the excel file during background job.

Regards,

Tarun