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: 

Corrupted / overwritten XLS file

Former Member
0 Kudos

Hi Friends,

I am looking for a solution where in i am using 'GUI_DOWNLOAD' to download data into xls format , its working but when i am looking at the xls output i am getting corrupted data , in short if u go to Transaction SE37 and test with Function Module by passing

1000194015000102 as input for TABLES (data_tab) and u get (corrupted )output 1000194015000100 - check the downloaded xls file only.

check the last digit its '0' not '2'

can any one please help me in getting it solved .

3 REPLIES 3

Former Member
0 Kudos

the thing is as it is a long number...excel converts to exponent due to which 2 is been shown as 0.

say u check by using '1000194015000102' and it will show u correctly...try to use less digits as the exponent will convert last digits to round off numbers.

0 Kudos

Hi Ramesh ,

my requirement is to print 1000194015000102( input) as it is and in some cases it can go upto 22 characters , but i should get the output displayed as it is with out any over writting , and if we give any character like say 'K'

10001940150001K02 you get output in xls as it is ,

the problem is with XLS download , can there be any possibility of getting it stopped from overwritting .

Would be waiting for ur reply,

Thanks

Srikanth.

Thanks,

Former Member
0 Kudos

Dear Srikanth,

I'm providing you with the following piece of code ... Its working fine for me ... hopefully it suits your requirement ...

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

  • 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 .......

Regards,

Abir

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

  • Please don't forget to award points *