‎2006 Aug 09 7:31 PM
Hi all,
I'm using ALSM_EXCEL_TO_INTERNAL_TABLE to load a spreadsheet from the desktop. I've notcied that if I type some garbage into the file name field and execute the program it dumps and does not provide me with an opportunity to catch the error and gracefully execute the program. am I missing something in ALSM_EXCEL_TO_INTERNAL_TABLE or is there another way i can check for the existence of the file and prevent the user from executing the program with a non-existent fiel name?
regards,
Mat
Message was edited by: Mathew Laba
‎2006 Aug 09 7:34 PM
‎2006 Aug 09 7:34 PM
Please make sure that your exceptions are specified for this function module. Then this should catch the error for you.
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = file
i_begin_col = '1'
i_begin_row = '1'
i_end_col = '200'
i_end_row = '5000'
tables
intern = xcel.
<b> exceptions
inconsistent_parameters = 1
upload_ole = 2
others = 3.</b>
Regards,
Rich Heilman
‎2006 Aug 09 7:34 PM
‎2006 Aug 09 7:37 PM
Following is my code but the crash appears to take place within ALSM_EXCEL_TO_INTERNAL_TABLE and no return takes place. Following is my code...
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE e999 WITH 'FM call unsuccessful - file could not be loaded.'.
ENDIF.
‎2006 Aug 09 7:42 PM
‎2006 Aug 09 8:02 PM
the following did not DUMP for me..
report zexcel.
DATA meta_xl_itab TYPE alsmex_tabline OCCURS 0 WITH HEADER LINE.
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = '*xcvzxcvxzcv*'
i_begin_col = '1'
i_begin_row = '1'
i_end_col = '200'
i_end_row = '5000'
tables
intern = meta_xl_itab
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
if sy-subrc <> 0.
message i016(rp) with 'invalid file name'.
endif.
Like Rich hinted, there must be something else in your code that caused the DUMP..
~Suresh
‎2006 Aug 09 8:15 PM
File Exists checks for bogus file names like the one you typed Look at the code.
Mat
‎2006 Aug 09 8:19 PM
‎2006 Aug 09 8:21 PM
one more guess,
is your file variable is of type RLGRAP-FILENAME or any other thing ?
check this
Regards
srikanth
‎2006 Aug 09 8:27 PM
How do I mark a post as a question?
here is the code:
DATA: l_file_name TYPE STRING.
l_file_name = u_file. (where u_file is of type rlgrap-filename)
*C-- Check for existence of file
CALL METHOD cl_gui_frontend_services=>file_exist
EXPORTING
file = l_file_name
RECEIVING
result = l_fm_rc
EXCEPTIONS
OTHERS = 1.
IF SY-SUBRC <> 0 OR l_fm_rc EQ ' '.
MESSAGE e999 WITH 'FM call unsuccessful - file not found.'.
ENDIF.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = u_file
I_BEGIN_COL = '1'
I_BEGIN_ROW = '1'
I_END_COL = '100'
I_END_ROW = '25000'
TABLES
INTERN = c_raw_data
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE e999 WITH 'FM call unsuccessful - file could not be loaded.'.
ENDIF.
What return value should I check for in FILE_EXIST? I notice that if I pass a bogus file name I now get my error message and graceful exit...but if I pass a file name that exists then FILE_EXISTS throws and error within it's code...saying something about 'X' not being a number in DIRECTORY_LIST_FILES...
‎2006 Aug 09 8:29 PM
Srikanth,
I think you're on to something here...I do pass a variable into ALSM_EXCEL_TO_INTERNAL_TABLE that is of type rlgrap-filename...should I not do that? seems to work.
‎2006 Aug 09 8:32 PM
Check the value = 1. If 1, then the file is there, if 0, it is not there.
report zrich_0001.
data: c_raw_data type table of ALSMEX_TABLINE with header line.
data: l_file_name type string.
data: l_fm_rc type i.
parameters: u_file type localfile default 'C:test.xls'.
l_file_name = u_file.
*C-- Check for existence of file
call method cl_gui_frontend_services=>file_exist
exporting
file = l_file_name
receiving
result = l_fm_rc
exceptions
others = 1.
check l_fm_rc = 1. " If 0, then the file doesn't exits.
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = u_file
i_begin_col = '1'
i_begin_row = '1'
i_end_col = '100'
i_end_row = '25000'
tables
intern = c_raw_data
exceptions
inconsistent_parameters = 1
upload_ole = 2
others = 3.
if sy-subrc <> 0.
* message e999 with 'FM call unsuccessful - file could not be loaded.'.
endif.
Regards,
Rich Heilman
‎2006 Aug 09 8:32 PM
IF SY-SUBRC <> 0.
*--this is enough i guess
MESSAGE e999 WITH 'FM call unsuccessful - file not found.'.
exit.
<b>else.</b>
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = u_file
I_BEGIN_COL = '1'
I_BEGIN_ROW = '1'
I_END_COL = '100'
I_END_ROW = '25000'
TABLES
INTERN = c_raw_data
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE e999 WITH 'FM call unsuccessful - file could not be loaded.'.
ENDIF.
<b>endif.</b>
regards,
srikanth
‎2006 Aug 09 8:34 PM
‎2006 Aug 09 8:38 PM
I'm sorry, its a BOOLEAN, so "X" if the file is found, space if it is not found.
report zrich_0001.
data: c_raw_data type table of ALSMEX_TABLINE with header line.
data: l_file_name type string.
<b>data: l_fm_rc type c.</b>
parameters: u_file type localfile default 'C:test.xls'.
l_file_name = u_file.
**C-- Check for existence of file
call method cl_gui_frontend_services=>file_exist
exporting
file = l_file_name
receiving
result = l_fm_rc
exceptions
others = 1.
<b>check l_fm_rc = 'X'. " If space, then the file doesn't exits.</b>
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = u_file
i_begin_col = '1'
i_begin_row = '1'
i_end_col = '100'
i_end_row = '25000'
tables
intern = c_raw_data
exceptions
inconsistent_parameters = 1
upload_ole = 2
others = 3.
if sy-subrc <> 0.
* message e999 with 'FM call unsuccessful - file could not be loaded.'.
endif.
There should be a checkbox somewhere on your post that says " Mark this post as a question". This will allow you to award points for helpful answers.
Regards,
Rich Heilman
‎2006 Aug 09 8:40 PM
‎2006 Aug 09 8:42 PM
‎2006 Aug 09 8:47 PM
‎2006 Aug 09 8:49 PM
Its working good in my 46c system. Anyway, there is nothing wrong with checking for the file existance first. Just follow the sample program above, it should work for you.
Please mark you post as a question and award points for helpful answers and mark as solved when solved completely. Thanks.
Regards,
Rich Heilman
‎2006 Aug 09 8:52 PM
hi Mathew,
alternatively you also can check other options(just FYI).
http://www.sapdevelopment.co.uk/file/file_upexcel.htm
http://www.sapdevelopment.co.uk/file/file_upexcelalt1.htm
http://www.sapdevelopment.co.uk/file/file_upexcelalt2.htm
Regards
Srikanth.
‎2006 Aug 09 11:54 PM
I set the retrun code variable as type I and not type C!!!
Thanks all.
‎2006 Aug 10 12:42 AM
‎2006 Aug 10 1:03 AM
Hi Rich...Still on line hey Can I change the message type after it has been created?
‎2006 Aug 10 1:12 AM
Yes, you can. Go back to the original post and click the pencil to change. There is a checkbox that says "Mark this topic as a question". Check this box. What this will do is put radiobuttons next to each answer that you received. Here is where you can award points for helpful answers. Do so at your discretion. Mark the answer that helped you most in solving your problem with 10 points(blue star). This "closes" the thread and lets others know that there was a solution to your problem. This is how it is done on SDN.
And yes, I'm still online. You will find me in this forum about 16 hours out of the day.
Regards,
Rich Heilman
‎2006 Aug 10 1:33 AM
‎2006 Aug 10 1:34 AM
‎2006 Aug 09 7:35 PM
hi Mathew,
Before using that one check whether that file exists with FM <b>CL_GUI_FRONTEND_SERVICES=>FILE_EXIST</b>
CALL METHOD cl_gui_frontend_services=>file_exist
EXPORTING
file = l_filename
RECEIVING
result = l_ret
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT.
ENDIF.Regards,
Santosh
Message was edited by: Santosh Kumar P