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

path validation

Former Member
0 Likes
626

Hi,

I'm generating files in my program and dropping those files based on the path given in the selection screen. The user might choose a path on his system or shared drive or a path on the app. server.

I need to validate whether those paths, whether those paths exists or not. please let me know how to handle this situation.

Regards,

ravi.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
579

Please try to use the DIRECTORY_EXIST method of the class CL_GUI_FRONTEND_SERVICES.

Regards,

Rich Heilman

3 REPLIES 3
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
580

Please try to use the DIRECTORY_EXIST method of the class CL_GUI_FRONTEND_SERVICES.

Regards,

Rich Heilman

Read only

0 Likes
579

You can use this example.



report zrich_0001 .

type-pools: abap.

data: path type string.
data: result type abap_bool.

parameters: p_path type localfile default 'C:sap'.

at selection-screen .


path = p_path.

call method cl_gui_frontend_services=>directory_exist
  exporting
    directory            = path
  receiving
    result               = result
  EXCEPTIONS
    CNTL_ERROR           = 1
    ERROR_NO_GUI         = 2
    WRONG_PARAMETER      = 3
    NOT_SUPPORTED_BY_GUI = 4
    others               = 5
        .
if result = space.
  message e001(00) with 'Path/Directory does not exist'.
endif.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
579

Hi Ravi,

Please check this sample codes.


DATA: c_file_mask TYPE dxfields-filemask VALUE '*',
      searched_dir TYPE dxfields-longpath,
      file_path LIKE dxfields-longpath.

searched_dir = 'INITIAL_DIRECTORY_TO_START_WITH'.
TRANSLATE searched_dir TO LOWER CASE .

CALL FUNCTION 'F4_DXFILENAME_TOPRECURSION'
  EXPORTING
    i_location_flag = 'A'
    i_server = ' '
    i_path = searched_dir
    filemask = c_file_mask
* FILEOPERATION = 'R'
  IMPORTING
* O_LOCATION_FLAG =
* O_SERVER =
  o_path = file_path
* ABEND_FLAG =
  EXCEPTIONS
    rfc_error = 1
    OTHERS = 2.

IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

Hope this will help.

Regards,

Ferry Lianto