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

Validate filepath and filename

Former Member
0 Likes
413

Hello friends,

I have a filepath given in the selection screen. How to check whetehr the file attributes are valid. ie file path and name is a valid one.

Regards,

jamshed

Hello friends,

I have a filepath given in the selection screen. How to check whetehr the file attributes are valid. ie file path and name is a valid one.

Regards,

jamshed

2 REPLIES 2
Read only

Former Member
0 Likes
390

hi John,

Use FM WS_FILENAME_GET FM...

i.e,


*AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_INFILE.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_infile.
  CALL FUNCTION 'WS_FILENAME_GET'
       EXPORTING
            def_filename     = p_infile
            mask             = ',*.txt.'
            mode             = 'O'
            title            = 'Upload File'(078)
       IMPORTING
            filename         = p_infile
       EXCEPTIONS
            inv_winsys       = 1
            no_batch         = 2
            selection_cancel = 3
            selection_error  = 4
            OTHERS           = 5.


************************************************************************
*START-OF-SELECTION
START-OF-SELECTION.
  gd_file = p_infile.

  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                = gd_file
      has_field_separator     = 'X'  "file is TAB delimited
    TABLES
      data_tab                = it_record
    EXCEPTIONS
      file_open_error         = 1
      file_read_error         = 2
      no_batch                = 3
      gui_refuse_filetransfer = 4
      invalid_type            = 5
      no_authority            = 6
      unknown_error           = 7
      bad_data_format         = 8
      header_not_allowed      = 9
      separator_not_allowed   = 10
      header_too_long         = 11
      unknown_dp_error        = 12
      access_denied           = 13
      dp_out_of_memory        = 14
      disk_full               = 15
      dp_timeout              = 16
      OTHERS                  = 17.
    IF sy-subrc NE 0.
      write: 'Error ', sy-subrc, 'returned from GUI_UPLOAD FM'.
      skip.
    endif.

Read only

Former Member
0 Likes
390

Check the following code.

  • Local Data

DATA: L_RC TYPE C,

L_PATH TYPE STRING.

L_PATH = P_DIR.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_EXIST

EXPORTING

DIRECTORY = L_PATH

RECEIVING

RESULT = L_RC

EXCEPTIONS

CNTL_ERROR = 1

ERROR_NO_GUI = 2

WRONG_PARAMETER = 3

NOT_SUPPORTED_BY_GUI = 4

OTHERS = 5.

IF SY-SUBRC <> 0.

EXIT.

ELSE.

  • Error if the directory doesn't exist

IF L_RC = SPACE.

MESSAGE E002 WITH L_PATH.

ENDIF.

ENDIF.