Application Development and Automation 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: 
Read only

To export report data to excel

Former Member
0 Likes
718

Can anyone tell me whether there are any program/function module that can be used to export report data to excel and save the file on application server ?

Thanks!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
666

Hi,

Please check this FM ARCHIVFILE_CLIENT_TO_SERVER.

Regards,

Ferry Lianto

Please reward points if helpful.

5 REPLIES 5
Read only

Former Member
0 Likes
666

Hi,

Please check report program RHVERI_EXCEL_DOWNLOAD to export data to excel.

Also you can use transaction CG3Z to download excel file from PC to application server.

Regards,

Ferry Lianto

Read only

0 Likes
666

is there any program/function module to save the file on application server ?

Message was edited by:

Uma

Read only

Former Member
0 Likes
666

Uma,

check this piece of code...

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

  • D A T A D E C L A R A T I O N *

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

TYPES: BEGIN OF TY_EXCEL,

CELL_01(80) TYPE C,

CELL_02(80) TYPE C,

CELL_03(80) TYPE C,

CELL_04(80) TYPE C,

CELL_05(80) TYPE C,

CELL_06(80) TYPE C,

CELL_07(80) TYPE C,

CELL_08(80) TYPE C,

CELL_09(80) TYPE C,

CELL_10(80) TYPE C,

END OF TY_EXCEL.

DATA: IT_EXCEL TYPE STANDARD TABLE OF TY_EXCEL,

WA_EXCEL TYPE TY_EXCEL..

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

  • E V E N T : S T A R T - O F - S E L E C T I O N *

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

START-OF-SELECTION.

  • Here you populate the Internal Table.

  • -------------------------------------

  • Display - Top of the Page.

  • --------------------------------------

PERFORM DISPLAY_TOP_OF_PAGE.

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

  • E V E N T : E N D - O F - S E L E C T I O N *

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

END-OF-SELECTION.

SET PF-STATUS 'GUI_STATUS'.

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

  • E V E N T : A T U S E R - C O M M AN D *

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

AT USER-COMMAND.

CASE SY-UCOMM.

WHEN 'EXPORT'.

  • Exporting the report data to Excel.

PERFORM EXPORT_TO_EXCEL.

ENDCASE.

&----


*& Form DISPLAY_TOP_OF_PAGE

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM DISPLAY_TOP_OF_PAGE .

SKIP.

WRITE: /05(128) SY-ULINE,

/05 SY-VLINE,

06(127) 'O R I C A'

CENTERED COLOR 1,

132 SY-VLINE.

WRITE: /05(128) SY-ULINE,

/05 SY-VLINE,

06(127) 'Shift Asset Depreciation - Period/Year-wise Report.'

CENTERED COLOR 4 INTENSIFIED OFF,

132 SY-VLINE.

WRITE: /05(128) SY-ULINE.

*----


  • E X C E L O P E R A T I O N

*----


CLEAR: IT_EXCEL[],

WA_EXCEL.

PERFORM APPEND_BLANK_LINE USING 1.

WA_EXCEL-cell_02 = ' XYZ Ltd. '.

APPEND WA_EXCEL TO IT_EXCEL.

CLEAR: WA_EXCEL.

WA_EXCEL-cell_02 = 'Shift Asset Depreciation - Period/Year-wise Report.'.

APPEND WA_EXCEL TO IT_EXCEL.

PERFORM APPEND_BLANK_LINE USING 1.

ENDFORM. " DISPLAY_TOP_OF_PAGE

&----


*& Form APPEND_BLANK_LINE

&----


  • text

----


  • -->P_1 text

----


FORM APPEND_BLANK_LINE USING P_LINE TYPE I.

DO P_LINE TIMES.

CLEAR: WA_EXCEL.

APPEND WA_EXCEL TO IT_EXCEL.

enddo.

ENDFORM.

&----


*& Form EXPORT_TO_EXCEL

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM EXPORT_TO_EXCEL .

DATA: L_FILE_NAME(60) TYPE C.

  • Create a file name

CONCATENATE 'C:\' 'Shift_Depn_' SY-DATUM6(2) '.' SY-DATUM4(2)

'.' SY-DATUM+0(4) INTO L_FILE_NAME.

  • Pass the internal table (it_excel which is already populated )

  • to the function module for excel download.

CALL FUNCTION 'WS_EXCEL'

exporting

filename = L_FILE_NAME

tables

data = IT_EXCEL

exceptions

unknown_error = 1

others = 2.

if sy-subrc <> 0.

message e001(ymm) with 'Error in exporting to Excel.'.

endif.

ENDFORM. " EXPORT_TO_EXCEL

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

When you click the button - Export to Excel ( GUI-Status) you'll be able to export the content of the Internal Table to an Excel file .......

check this below link also

~~Guduri

Read only

Former Member
0 Likes
667

Hi,

Please check this FM ARCHIVFILE_CLIENT_TO_SERVER.

Regards,

Ferry Lianto

Please reward points if helpful.

Read only

Former Member
0 Likes
666

HI

TYPES:

BEGIN OF ty_upload,

field1 TYPE c length 12,

field2 TYPE c length 12,

field3 TYPE c length 12,

END OF ty_upload.

DATA it_upload TYPE STANDARD TABLE OF ty_upload WITH DEFAULT KEY.

DATA wa_upload TYPE ty_upload.

DATA itab TYPE STANDARD TABLE OF alsmex_tabline WITH DEFAULT KEY.

FIELD-SYMBOLS: <wa> type alsmex_tabline.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = filename

i_begin_col = 1

i_begin_row = 1

i_end_col = 3

i_end_row = 65535

TABLES

intern = itab.

LOOP AT itab ASSIGNING <wa>.

CASE <wa>-col.

WHEN '0001'.

wa_upload-field1 = <wa>-value.

WHEN '0002'.

wa_upload-field2 = <wa>-value.

WHEN '0003'.

wa_upload-field3 = <wa>-value.

ENDCASE.

APPEND wa_upload TO it_upload.

CLEAR wa_upload.

ENDLOOP

.

http://www.sap-img.com/abap/upload-direct-excel.htm

Another Program

&----


*& Report UPLOAD_EXCEL *

*& *

&----


*& *

*& Upload and excel file into an internal table using the following *

*& function module: ALSM_EXCEL_TO_INTERNAL_TABLE *

&----


REPORT UPLOAD_EXCEL no standard page heading.

*Data Declaration

*----


data: itab like alsmex_tabline occurs 0 with header line.

  • Has the following format:

  • Row number | Colum Number | Value

  • ---------------------------------------

  • i.e. 1 1 Name1

  • 2 1 Joe

TYPES: Begin of t_record,

name1 like itab-value,

name2 like itab-value,

age like itab-value,

End of t_record.

DATA: it_record type standard table of t_record initial size 0,

wa_record type t_record.

DATA: gd_currentrow type i.

*Selection Screen Declaration

*----


PARAMETER p_infile like rlgrap-filename.

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

*START OF SELECTION

call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'

exporting

filename = p_infile

i_begin_col = '1'

i_begin_row = '2' "Do not require headings

i_end_col = '14'

i_end_row = '31'

tables

intern = itab

exceptions

inconsistent_parameters = 1

upload_ole = 2

others = 3.

if sy-subrc <> 0.

message e010(zz) with text-001. "Problem uploading Excel Spreadsheet

endif.

  • Sort table by rows and colums

sort itab by row col.

  • Get first row retrieved

read table itab index 1.

  • Set first row retrieved to current row

gd_currentrow = itab-row.

loop at itab.

  • Reset values for next row

if itab-row ne gd_currentrow.

append wa_record to it_record.

clear wa_record.

gd_currentrow = itab-row.

endif.

case itab-col.

when '0001'. "First name

wa_record-name1 = itab-value.

when '0002'. "Surname

wa_record-name2 = itab-value.

when '0003'. "Age

wa_record-age = itab-value.

endcase.

endloop.

append wa_record to it_record.

*!! Excel data is now contained within the internal table IT_RECORD

  • Display report data for illustration purposes

loop at it_record into wa_record.

write:/ sy-vline,

(10) wa_record-name1, sy-vline,

(10) wa_record-name2, sy-vline,

(10) wa_record-age, sy-vline.

endloop.

regards

Laxmi