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: 

Problem in excel file download.

Former Member
0 Kudos

Hi Experts,

I have a requirement where i have to upload the excel and download the error excel file if there is any initial value in the excel or couldn't upload any value of excel properly.

following is my code, please help me i couldn't find where i went wrong.

Moderator message - Please respect the 5,000 character maximum when posting. Post only the relevant portions of code

Thanks in Advance,

sap52

Edited by: Rob Burbank on Sep 27, 2011 9:02 AM

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Problem is here.. You are checking in the wrong work area.

LOOP AT lt_excel1 INTO wa_excel1.

CLEAR: outputtab.

  • Validate input data

errors_occured = 'X'.

IF wa_final-shipcust IS INITIAL.

outputtab-errortext = text-002.

Data is looped into work area wa_excel1 and you are validating initial values in work area wa_final.

14 REPLIES 14

Former Member
0 Kudos

can any1 help me..

Thanks in advance,

sap52

Former Member
0 Kudos

Problem is here.. You are checking in the wrong work area.

LOOP AT lt_excel1 INTO wa_excel1.

CLEAR: outputtab.

  • Validate input data

errors_occured = 'X'.

IF wa_final-shipcust IS INITIAL.

outputtab-errortext = text-002.

Data is looped into work area wa_excel1 and you are validating initial values in work area wa_final.

0 Kudos

Thanku for ur response,

but the download file is not in excel format, it is in some other format.

DATA: FILENAME TYPE RLGRAP-FILENAME,

SOURCEFILENAME TYPE STRING.

PARAMETERS: P_FILE TYPE RLGRAP-FILENAME OBLIGATORY,

SPLIT SOURCEFILENAME AT '.XLS' INTO SOURCEFILENAME P_FILE.

CONCATENATE SOURCEFILENAME '_ERRORS' INTO FILENAME.

CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'

EXPORTING

FILE_NAME = P_FILE

TABLES

DATA_TAB = DOWNLOADTAB

EXCEPTIONS

OTHERS = 1.

IF SY-SUBRC <> 0.

MOVE FILENAME TO SOURCEFILENAME.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = SOURCEFILENAME

FILETYPE = 'DAT'

APPEND = ' '

WRITE_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = DOWNLOADTAB

EXCEPTIONS

OTHERS = 1.

IF SY-SUBRC <> 0.

MESSAGE S000(ZZ) WITH TEXT-001.

ENDIF.

ENDIF.

Thanku in advance.

0 Kudos

Hi,

As I understand from your requirement, you need to filter errors in the uploaded excel file. For that you are preparing one internal table it_excel1 which has all the uploaded data. But while validating error, you are checking in wa_final instead of wa_excel. Please change the validation as below.

LOOP AT lt_excel1 INTO wa_excel1.

CLEAR: outputtab.

  • Validate input data

errors_occured = 'X'.

IF wa_excel1-shipcust IS INITIAL.

outputtab-errortext = text-002

Regards,

Syam

deepak_dhamat
Active Contributor
0 Kudos

Hi ,

WHen you are uploading Data from excel to internal table , First display that data using ALV GRID .

if data is correct then only save that data to FInal table .

IN order to check whether your data uploaded is correct you can validate your data after taking in internal table .

@don't go for download again . it will take your lot of time .

regards

Deepak.

0 Kudos

Thanku for ur reply.

but i have to download the error excel file, which is not downlading in excel for, cud u plz check where i went wrong in above post.

Thanks in Advance.

0 Kudos

Hi,

You need to append .xls to the file name and change the file type to 'ASC'.

CONCATENATE SOURCEFILENAME '_ERRORS' '.xls' INTO FILENAME.

CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'

EXPORTING

FILE_NAME = P_FILE

TABLES

DATA_TAB = DOWNLOADTAB

EXCEPTIONS

OTHERS = 1.

IF SY-SUBRC 0.

MOVE FILENAME TO SOURCEFILENAME.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = SOURCEFILENAME

FILETYPE = 'ASC'

APPEND = ' '

WRITE_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = DOWNLOADTAB

EXCEPTIONS

OTHERS = 1.

IF SY-SUBRC 0.

MESSAGE S000(ZZ) WITH TEXT-001.

ENDIF.

ENDIF.

0 Kudos

Please Use this Sample code ....

INT_HEAD-FILED1 = 'MBRSH'. (for Header field Capturing in Excel)

APPEND INT_HEAD.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

FILENAME = LV_FILENAME "'C:\TEST_1.XLS'

FILETYPE = 'DBF' " leading zero's

  • APPEND = ' '

WRITE_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = I_FINAL (your Error Internal Table)

FIELDNAMES = INT_HEAD (if you need soem Header the pass this internal table)

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6

HEADER_NOT_ALLOWED = 7

SEPARATOR_NOT_ALLOWED = 8

FILESIZE_NOT_ALLOWED = 9

HEADER_TOO_LONG = 10

DP_ERROR_CREATE = 11

DP_ERROR_SEND = 12

DP_ERROR_WRITE = 13

UNKNOWN_DP_ERROR = 14

ACCESS_DENIED = 15

DP_OUT_OF_MEMORY = 16

DISK_FULL = 17

DP_TIMEOUT = 18

FILE_NOT_FOUND = 19

DATAPROVIDER_EXCEPTION = 20

CONTROL_FLUSH_ERROR = 21

OTHERS = 22

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

Thanks&Regards

Smruti

0 Kudos

Hi now excel download is working fine but error file downloaded id showing last record of file uploaded and loop is running only in that row.

*Populating The Values Into Internal Table Format.

IF LT_EXCEL1 IS NOT INITIAL.

READ TABLE LT_EXCEL1 INTO WA_EXCEL1 INDEX 1.

SORT LT_EXCEL1 BY ROW COL.

LOOP AT LT_EXCEL1 INTO WA_EXCEL1.

CASE WA_EXCEL1-COL.

WHEN '0003'.

WA_FINAL-SHIPCUST = WA_EXCEL1-VALUE.

ENDCASE.

AT END OF ROW.

IF WA_FINAL IS NOT INITIAL.

APPEND WA_FINAL TO LT_FINAL.

CLEAR : WA_EXCEL1, WA_FINAL.

ENDIF.

ENDAT.

ENDLOOP.

ENDIF.

LOOP AT LT_EXCEL1 INTO WA_EXCEL1.

CLEAR: OUTPUTTAB.

  • Validate input data

ERRORS_OCCURED = 'X'.

IF WA_FINAL-SHIPCUST IS INITIAL.

OUTPUTTAB-ERRORTEXT = TEXT-002.

ENDIF.

F ERRORS_OCCURED = 'X'.

MOVE-CORRESPONDING WA_FINAL TO OUTPUTTAB.

APPEND OUTPUTTAB.

CLEAR OUTPUTTAB.

CONTINUE.

ENDIF.

ENDLOOP.

error excel file is showing only 1 error record.

can u plz help me with my code.

0 Kudos

Hi,

Below is the code for the same.

*Populating The Values Into Internal Table Format.

IF LT_EXCEL1 IS NOT INITIAL.

READ TABLE LT_EXCEL1 INTO WA_EXCEL1 INDEX 1.

SORT LT_EXCEL1 BY ROW COL.

LOOP AT LT_EXCEL1 INTO WA_EXCEL1.

CASE WA_EXCEL1-COL.

WHEN '0003'.

WA_FINAL-SHIPCUST = WA_EXCEL1-VALUE.

ENDCASE.

AT END OF ROW.

IF WA_FINAL IS NOT INITIAL.

APPEND WA_FINAL TO LT_FINAL.

CLEAR : WA_EXCEL1, WA_FINAL.

ENDIF.

ENDAT.

ENDLOOP.

ENDIF.

LOOP AT LT_EXCEL1 INTO WA_EXCEL1.

CLEAR: OUTPUTTAB.

  • Validate input data

ERRORS_OCCURED = 'X'.

IF WA_EXCEL1-SHIPCUST IS INITIAL.

OUTPUTTAB-ERRORTEXT = TEXT-002.

ENDIF.

F ERRORS_OCCURED = 'X'.

MOVE-CORRESPONDING WA_FINAL TO OUTPUTTAB.

APPEND OUTPUTTAB.

CLEAR OUTPUTTAB.

CONTINUE.

ENDIF.

ENDLOOP.

0 Kudos

Hi,

I haven't found any changes in the code u have provided. can u plz let me know.

thanks in advance.

0 Kudos

Hi,

The change in the code as shown.

This is your code.

IF WA_FINAL-SHIPCUST IS INITIAL.

This is my code.

IF WA_excel1-SHIPCUST IS INITIAL.

0 Kudos

Hi,

i have declared

LT_EXCEL1 TYPE TABLE OF ALSMEX_TABLINE.

WA_EXCEL1 TYPE ALSMEX_TABLINE.

if the code is replaced this way, it is telling wa_excel1 has no component shipcust.

IF WA_excel1-SHIPCUST IS INITIAL

thnaks in advance.

0 Kudos

Hi,

To download contents of internal table to excel, please make use of function module GUI_DOWNLOAD in which you pass the internal table, file name and file extension. Give the file extension as DAT.

To upload excel file to internal table, please make use of function module TEXT_CONVERT_XLS_TO_SAP wherein you pass the uploaded file to internal table.

Also, while uploading the excel file to internal table make sure that the excel file has the extension .xls instead of .xlsx

The logic has been given in many threads in SDN. Please search.

Regards,

Danish.