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: 

how can i validate a path

Former Member
0 Kudos

hi experts,

how can i validate a path... i tried to use cl_gui_frontend_services=>directory_exist

but it gives me an error

for a local path and an app server path??

thx in advance

18 REPLIES 18

sastry_gunturi
Active Participant
0 Kudos

cl_gui_frontend_services=>directory_exist is for checking directories (not files) on the presentation server ( on local pc, laptop)... You cannot use it for validating path on App server. For App server you need to use open dataset... read dataset. etc...

Edited by: Karthik on Aug 20, 2009 2:21 AM

former_member226239
Contributor
0 Kudos

you can use CL_GUI_FRONTEND_SERVICES=>FILE_EXIST to check for file on the desktop.

for the App server use Open dataset. If it fails then there is no file at the specified location.

Former Member
0 Kudos

hi Carlos Venturo,

use the method

file_exist from the class cl_gui_frontend_services...

this will return you wether you have the file on the specified path or not...

You can use method CL_GUI_FRONTEND_SERVICES=>FILE_EXIST

Or you can also refer 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

Or when you simply upload a file using any FM, just check sy-subrc.

If not equal to 0, then display message Invalid Directory or File Name.

Hope this helps you.

-Thanks & Regards

Saurabh Goel

Former Member
0 Kudos

Hi Carlos,

Go through this link, I hope your problem will be solved.

Regards,

Nidhi Kothiyal

0 Kudos

cl_GUI_FROMENT_services

from the name itself its says its from front end only. so it doesnt checks app server path.

now. directory_exist from the name it checks directory.

so need fle_exist for a file in presentation server.

and for a path in app server use OPEN DATASET and read dataset.

Edited by: soumya prakash mishra on Aug 20, 2009 10:24 AM

Former Member
0 Kudos

please guys read carefully .. i nver said validate files ...

0 Kudos

Hi,

You could use the FM to find the file path. See if this of some to you



parameters: p_fname type string.
data: GV_FPATH TYPE FILEEXTERN.
                    

CALL FUNCTION 'FILE_GET_NAME_USING_PATH'
  EXPORTING
   CLIENT                           = SY-MANDT
    logical_path                     = 'HOME'
*   OPERATING_SYSTEM                 = SY-OPSYS
*   PARAMETER_1                      = ' '
*   PARAMETER_2                      = ' '
*   PARAMETER_3                      = ' '
*   USE_BUFFER                       = ' '
    file_name                        = P_FNAME
*   USE_PRESENTATION_SERVER          = ' '
*   ELEMINATE_BLANKS                 = 'X'
 IMPORTING
   FILE_NAME_WITH_PATH              = GV_FPATH
 EXCEPTIONS
   PATH_NOT_FOUND                   = 1
   MISSING_PARAMETER                = 2
   OPERATING_SYSTEM_NOT_FOUND       = 3
   FILE_SYSTEM_NOT_FOUND            = 4
    OTHERS                           = 5
         .
IF sy-subrc <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

WRITE:/ 'File Path:',GV_FPATH.

0 Kudos

where is your file? presentation server or app server?

0 Kudos

there is no yet a file... im gonna create the pdf. file

all i want to validate is that for example if the user input 'C:\dir\' that PATH exist (NOT FILE), thats it ..

thx for the previous answers

0 Kudos

Hi,

Check use the method CL_GUI_FRONTEND_SERVICES->DIRECTORY_EXIST for path validation in the presentation server.

Regards,

Vik

0 Kudos

thats great,.

now

pass your path to the method directory_exist as : 'C:\DIR\' ... case is not a problem and last '\' also is not a problem you may or may not give.

that result parameter = X means directory exist. if not then it ddoesnt

Former Member
0 Kudos

Hi Carlos,

you follow the below coding, where you will get to separate validation

for presentation server & application server file path.

FORM present_validation .

DATA: lw_check TYPE c,

lw_file TYPE string.

IF po_psv IS INITIAL.

IF sy-ucomm = 'ONLI' OR sy-ucomm = space.

MESSAGE 'Please input the file name' TYPE lc_e.

ENDIF.

ELSE.

lw_file = po_psv.

lw_check = cl_gui_frontend_services=>file_exist( lw_file ).

IF lw_check IS INITIAL.

MESSAGE 'Please input the correct file path' TYPE lc_e.

ENDIF.

ENDIF.

ENDFORM. " PRESENT_VALIDATION

FORM application_validation .

DATA: lw_file TYPE string.

lw_file = po_asv.

IF po_asv IS INITIAL.

IF sy-ucomm = 'ONLI' OR sy-ucomm = space.

MESSAGE 'Please input the file name' TYPE lc_e.

ENDIF.

ELSE.

OPEN DATASET lw_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc NE 0.

MESSAGE 'Please input the correct file path' TYPE lc_e.

ENDIF.

ENDIF.

ENDFORM. " APPLICATION_VALIDATION

Hope this can solve your problems.

Regards,

Tutun

Former Member
0 Kudos

Hi Carlos,

I suggest you to go through the below link .

I guess there are few methods that you can chose to solve your problem.

.

Hope this helps you .

Thanks and Regards .

Aditi Wason.

rainer_hbenthal
Active Contributor
0 Kudos

Is there a \ or a / at the end of your path?

Maybe

c:\xyz\wherever\whatever

is treated as a file. So please check if your path ends with one ofdof the path delimters and check with

c:\xyz\wherever\whatever\

again

Former Member
0 Kudos

hii carlos,

for validation of path on application server

use fm EPS_GET_DIRECTORY_LISTING

Second use FM PFL_CHECK_OS_FILE_EXISTENCE which perfectly working fine for application server file validation. Here also file name is case sensitive. Check this FM in SE37 by giving ur file name and check the check box Lower case

rgrds,

shweta

Edited by: Shweta Joon on Aug 20, 2009 8:01 AM

Former Member
0 Kudos

thx for the answer ... but PLEASE read at least the first post.. i'm looking for another way to valdiate because the FM cl_gui_frontend_services=>directory_exist gives me an error!!! it says there is no method (probably because its an old version).. because its works fine in another server...but in the one im programming it doesnt

thx

0 Kudos

Well my mistake i dint read the first post. In case cl_gui_frontend_services=>directory_exist is not working check if the FM's

PC_CHECK_PATH or PC_CHECK_PATH_WITH_DRIVE work for you.

Regards,

Vik

0 Kudos

may be you are using a lower version.

any ways

i have tried FM GUI_CREATE_DIRECTORY

if a directory exist it just doesnt harm the directory. but if the directory is not present it create it and raises exception FAILED.

you can try this FM