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: 

File path Validation

Former Member
0 Kudos
169

validation of file path

Posted: Aug 2, 2006 2:42 PM Reply E-mail this post

OPEN DATASET g_filepath IN TEXT MODE FOR INPUT

MESSAGE g_msg.

IF sy-subrc = 0.

MESSAGE e001 WITH 'File Already Exist' g_msg .

CLOSE DATASET g_filepath.

leave Program.

ELSE .

CLOSE DATASET g_filepath.

ENDIF.

here when control goes to ELSE. then may be file doesnot exist or Invalid File Path.

if File doesnot exist then OK . (I have to write data into it)

what to do when Invalid File Path ( eg /temp/gtc\abc.txt). here \ wrongly given.

so how o handle such wrong inputs.

Plz reply

5 REPLIES 5

Former Member
0 Kudos
78

HI,

If the file does not exist then the SY-SUBRC will fail, if you give the wrong file name which is not existed in AL11 Transaction code then also the the SY-SUBRC will fail. so until unless if you give the right path which is existed in the Application server the SY-SUBRC will fail , so do not worry aboout the wrong paths

Thanks

Sudheer

Former Member
0 Kudos
78

Hi Sharada,

Check these FM's

CONV_UTIL_CHECK_FILE_EXISTENCE

CV120_DOC_FILE_EXISTENCE_CHECK

CV122_DOC_FILE_EXISTENCE_CHECK

DX_FILE_EXISTENCE_CHECK

PFL_CHECK_OS_FILE_EXISTENCE

i have u another idea!

try this following code

selection-screen begin of block b1 with frame .

PARAMETER : FILE(100) lower case.

selection-screen end of block b1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR FILE.

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

  • DEF_FILENAME = ' '

DEF_PATH = '.'

  • MASK = ' '

  • MODE = ' '

  • TITLE = ' '

IMPORTING

FILENAME = FILE

  • RC =

.

Regards,

Naveen

laxmanakumar_appana
Active Contributor
0 Kudos
78

Hi,

check this FM, if this FM returns sy-subrc not equal to zero , that means , given path is invalid.


data: ifile type table of  salfldir with header line.

parameters: p_path type salfile-longname
                    default '/temp/gtcabc.txt'


call function 'RZL_READ_DIR_LOCAL'
     exporting
          name           = p_path
     tables
          file_tbl       = ifile
     exceptions
          argument_error = 1
          not_found      = 2
          others         = 3.
       if sy-subrc ne 0.
         ----invalid path
       endif.

and also you can check like this :

read ifile index 1.
if ifile-name is initial.
   ----invalid path
endif.

Regards

Appana

Former Member
0 Kudos
78

Hi,

You cannot find out if the error is because of invalid path provided or because of the file not available.

For both the errors OPEN DATASET returns SY-SUBRC EQ 4.

Regards,

Sudhir.

Former Member
0 Kudos
78

Hi,

Check the below post , Hope this may be helpful.

Thanks,

sudheer