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

Program dump when file not found...

Former Member
0 Likes
2,599

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,417

have you commented the exceptions part of that function module ??

if so, un comment them.

if sy-subrc <> 0.

message i000.....will be there , make it un commented

endif.

check this SDN Post to know how to call this FM

Regards,

Srikanth

added SDN link,

Message was edited by: Srikanth Kidambi

26 REPLIES 26
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
2,417

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

Read only

Former Member
0 Likes
2,418

have you commented the exceptions part of that function module ??

if so, un comment them.

if sy-subrc <> 0.

message i000.....will be there , make it un commented

endif.

check this SDN Post to know how to call this FM

Regards,

Srikanth

added SDN link,

Message was edited by: Srikanth Kidambi

Read only

0 Likes
2,417

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.

Read only

0 Likes
2,417

Can we see all your code please?

P.S.

Please mark this post as a question. Thanks.

Regards,

Rich Heilman

Read only

0 Likes
2,417

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

Read only

0 Likes
2,417

File Exists checks for bogus file names like the one you typed Look at the code.

Mat

Read only

0 Likes
2,417

Code Pls??

Regds

Manohar

Read only

0 Likes
2,417

one more guess,

is your file variable is of type RLGRAP-FILENAME or any other thing ?

check this

Regards

srikanth

Read only

0 Likes
2,417

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

Read only

0 Likes
2,417

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.

Read only

0 Likes
2,417

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

Read only

0 Likes
2,417

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

Read only

0 Likes
2,417

Your function call is fine. It works quite well in my system and does not dump when giving a bogus file path/name. What release are you on?

Regards,

Rich Heilman

Read only

0 Likes
2,417

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

Read only

0 Likes
2,417

Very strange indeed...release is 9.00.2047.

Read only

0 Likes
2,417

I do not recoginize 9.00.2047 as a realease. Are you on 46c, 4.7, ECC 5.0, ECC 6.0?

Regards,

Rich Heilman

Read only

0 Likes
2,417

4.7

Read only

0 Likes
2,417

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

Read only

Read only

0 Likes
2,417

I set the retrun code variable as type I and not type C!!!

Thanks all.

Read only

0 Likes
2,417

Mathew, if you problem is solved, please mark this post as a question and award points for helpful answers and mark as solved. Thanks.

Regards,

Rich Heilman

Read only

0 Likes
2,417

Hi Rich...Still on line hey Can I change the message type after it has been created?

Read only

0 Likes
2,417

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

Read only

0 Likes
2,417

Thanks Rich. New to this forum.

regards,

Mat

Read only

0 Likes
2,417

No problem. Glad to help.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
2,417

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