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

check for file path

Former Member
0 Likes
2,060

Hi All,

Is there any check for right or wrong file path.

for exa.

I have decleared

PARAMETER : p_file LIKE rlgrap-filename .

and give f4 help

SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

CHANGING

file_name = p_file.

but when I give only text.txt in file path it is giving succesful message.

That time it should give error.

Please tell me the solution.

1 ACCEPTED SOLUTION
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,715

Hello,

You can use the method FILE_EXIST of the class CL_GUI_FRONTEND_SERVICES.

TYPE-POOL: abap.

PARAMETER : p_file LIKE rlgrap-filename .

DATA: 
rcbool type ABAP_BOOL,
v_file TYPE string.

v_file = p_file.

  CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_EXIST
    EXPORTING
      FILE                 = v_file
    RECEIVING
      RESULT               = rcbool
   EXCEPTIONS
     CNTL_ERROR           = 1
     ERROR_NO_GUI         = 2
     WRONG_PARAMETER      = 3
     NOT_SUPPORTED_BY_GUI = 4
     OTHERS               = 5.
IF sy-subrc <> 0.
" Do your error handling here
ENDIF.

BR,

Suhas

8 REPLIES 8
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,715

PARAMETERS: p_path LIKE rlgrap-filename OBLIGATORY.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.

CALL FUNCTION 'F4_FILENAME'

  • EXPORTING

  • PROGRAM_NAME = SYST-CPROG

  • DYNPRO_NUMBER = SYST-DYNNR

  • FIELD_NAME = ' '

IMPORTING

file_name = p_path.

START-OF-SELECTION.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = p_path

i_begin_col = 1

i_begin_row = p_start

i_end_col = 6

i_end_row = p_end

TABLES

intern = it_excel

EXCEPTIONS

inconsistent_parameters = 1

upload_ole = 2

OTHERS = 3.

IF sy-subrc <> 0.

MESSAGE i001(ZCS).

"i001(zmm01) 'File not exsits!!Please check again'.

CLEAR p_path.

CALL SELECTION-SCREEN 1000.

ENDIF.

Read only

Former Member
0 Likes
1,715

It is custom developed error checks. Based on the ur business create folder in a common drive and make sure the user is picking the file from this folder path.

Read only

Former Member
0 Likes
1,715

hi AMar,


PC_CHECK_DRIVE 	                     "check drive
PC_CHECK_PATH 		    "check Path 
PC_CHECK_FILENAME 	   "check file name	
PC_CHECK_EXTENSION 	         "Check extension ex:-xls,dat,csv	
PC_CHECK_PATH_WITH_DRIVE          ""check drive and path	 	
PC_CHECK_FILENAME_WITH_EXT 		
PC_BUILD_COMPLETE_FILENAME 		
PC_SPLIT_COMPLETE_FILENAME 		

Reagrds,

Prabhudas

Read only

Former Member
0 Likes
1,715

Hi,

KD_GET_FILENAME_ON_F4 just gives file path popup.....

but when u provide the same file path to GUI_UPLOAD , an exception ll get triggered saying required file path does not exist.

There u can identify the file path error.

Regards,

Ajit.

Read only

former_member203501
Active Contributor
0 Likes
1,715

hi do liike this ..

use this 'SO_SPLIT_FILE_AND_PATH' and put a message if there is not a file

Read only

Former Member
0 Likes
1,715

Hi,

Try using

CALL METHOD cl_gui_frontend_services=>directory_exist

Hope it will help you

Regards

Natasha Garg

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,716

Hello,

You can use the method FILE_EXIST of the class CL_GUI_FRONTEND_SERVICES.

TYPE-POOL: abap.

PARAMETER : p_file LIKE rlgrap-filename .

DATA: 
rcbool type ABAP_BOOL,
v_file TYPE string.

v_file = p_file.

  CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_EXIST
    EXPORTING
      FILE                 = v_file
    RECEIVING
      RESULT               = rcbool
   EXCEPTIONS
     CNTL_ERROR           = 1
     ERROR_NO_GUI         = 2
     WRONG_PARAMETER      = 3
     NOT_SUPPORTED_BY_GUI = 4
     OTHERS               = 5.
IF sy-subrc <> 0.
" Do your error handling here
ENDIF.

BR,

Suhas

Read only

Former Member
0 Likes
1,715

hi

u can use CL_GUI_FRONTEND_SERVICES=>FILE_EXIST for file and CL_GUI_FRONTEND_SERVICES=>DIRECTRY_EXIST for directry

~linganna