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: 

validation of file path

Former Member
0 Kudos
927

Hi all,

I need to validate the filepath while downloading the excel file. To elaborate this, When user is given a space on screen to put on the path where the he wants to save the excel file, I need to check that path, whether its valid or not.

Please tell me if there is any FM or any method to do it?

Regards,

Nikita

Edited by: Nikita Jain on Oct 17, 2008 2:29 PM

1 ACCEPTED SOLUTION

satsrockford
Active Participant
0 Kudos
287

Hi,

You can use FM RZL_READ_DIR_LOCAL to validate the file path.

Please check this link for sample code.

Hope this will help.

Regards,

Satish

11 REPLIES 11

satsrockford
Active Participant
0 Kudos
288

Hi,

You can use FM RZL_READ_DIR_LOCAL to validate the file path.

Please check this link for sample code.

Hope this will help.

Regards,

Satish

Mohamed_Mukhtar
Active Contributor
0 Kudos
287

Hi ,

try this code

PARAMETERS : p_dload TYPE rlgrap-filename.

AT SELECTION-SCREEN ON   p_dload.
DATA: lv_len       TYPE i.
  lv_len = STRLEN( p_dnload ).
  lv_len = lv_len - 4.
  TRANSLATE p_dnload+lv_len TO UPPER CASE.
  IF p_dnload+lv_len NE '.XLS'.
    MESSAGE text-020 TYPE 'S'.
    LEAVE TO SCREEN 1000.
  ENDIF.

Thanks and Regards

Former Member
0 Kudos
287

Hi

Check the following Code

types for data to be downloaded

types: begin of tp_kna1,

KUNNR type kna1-kunnr, " customer number

LAND1 type kna1-land1, " Country Key

NAME1 type kna1-name1, " customer name

ORT01 type kna1-ort01, " city

PSTLZ type kna1-pstlz, " postal code

REGIO type kna1-regio, " region

end of tp_kna1.

-


I n t e r n a l T a b l e s

-


Internal table for data to be downloaded

data: it_kna1 type standard table of tp_kna1 with header line.

-


S e l e c t i o n S c r e e n

-


selection-screen begin of block b1 with frame title text-001.

parameters: p_afile type rlgrap-filename

default 'customer.txt'.

selection-screen end of block b1.

-


-


At selection screen on value request

-


at selection-screen on value-request for p_afile.

*--Get the F4 help for Sales Deal File

perform get_val_help changing p_afile .----


S t a r t o f s e l e c t i o n

-


start-of-selection.

Upload the data from Sales Deal file

perform upload_app_file.

end-of-selection.

perform write_data.

*&----


*& Form upload_app_file

*&----


Upload the application server file data

*----


form upload_app_file.

data: l_msg(100). " error message

open dataset p_afile for input in text mode encoding default message

l_msg.

if sy-subrc 0.

message i004 with l_msg.

else.

do.

read dataset p_afile into it_kna1.

if sy-subrc = 0.

append it_kna1.

clear it_kna1.

else.

exit.

endif.

enddo.

close dataset p_afile.

endif.

endform. " upload_app_file

&----


*& Form write_data

&----


text

-


--> p1 text

<-- p2 text

-


FORM write_data .

loop at it_kna1.

write:/ it_kna1-kunnr,

it_kna1-land1,

it_kna1-name1,

it_kna1-ort01,

it_kna1-pstlz,

it_kna1-regio.

endloop.

ENDFORM. " write_data

&----


*& Form get_val_help

&----


Get F4 help for the File name

-


form get_val_help changing p_file type rlgrap-filename.

call function 'F4_FILENAME'

importing

file_name = p_file

exceptions

others = 1.

if sy-subrc 0.

message e001. " File Open Error

endif.

endform. " get_val_help

Regards

Rajesh

Former Member
0 Kudos
287

Hi

use this FM

CALL FUNCTION 'TMP_GUI_DIRECTORY_LIST_FILES'
    EXPORTING
      DIRECTORY        = 'C:\My Programs\folder\'
     FILTER           = '*.*'
* IMPORTING
*   FILE_COUNT       =
*   DIR_COUNT        =
    TABLES
      FILE_TABLE       = it_filelist
      DIR_TABLE        = dirlist
* EXCEPTIONS
*   CNTL_ERROR       = 1
*   OTHERS           = 2

in it_filelist u can get all the files of folder then you can validate your filename by caomparing that(it_filelist) files

Former Member
0 Kudos
287

Hi,

Try this...

TYPE-POOLS: abap.

DATA: v_dir TYPE string.

DATA: v_bol TYPE abap_bool.

v_dir = 'c:\sap\'.

CALL METHOD cl_gui_frontend_services=>directory_exist

EXPORTING

directory = v_dir

RECEIVING

result = v_bol

EXCEPTIONS

cntl_error = 1

error_no_gui = 2

wrong_parameter = 3

not_supported_by_gui = 4

OTHERS = 5.IF NOT v_bol IS INITIAL.

WRITE:/ 'Directory exists.'.

ELSE.

WRITE:/ 'Directory does not exist.'.

ENDIF.

0 Kudos
287

Hi Ajay,

Although I have given F4 help for the filepath, the requirement is if before pressing F4, if user types some invalid path, then it should give the error message accordingly.

The method that you have given has a hard coded path. So will it work according to my requirement?

Regards,

Nikita

0 Kudos
287

Hi,

I believe ..it should work.....Are you not able to solve your problem by this?

0 Kudos
287

Hi,

Check This..

0 Kudos
287

Hi,

Although I have given F4 help for the filepath, the requirement is if before pressing F4, if user types some invalid path, then it should give the error message accordingly.

Try this :


REPORT  z_validate_path                         .

PARAMETERS p_path(150) TYPE c.

DATA flag.

DATA path TYPE string.

AT SELECTION-SCREEN ON p_path.
  IF p_path IS NOT INITIAL.
    path = p_path.
    CALL METHOD cl_gui_frontend_services=>directory_exist
      EXPORTING
        directory            = path
      RECEIVING
        result               = flag
      EXCEPTIONS
        cntl_error           = 1
        error_no_gui         = 2
        wrong_parameter      = 3
        not_supported_by_gui = 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.
    IF flag IS INITIAL.
      MESSAGE 'Directory does not exist !' TYPE 'E'.
    ENDIF.

  ENDIF.

Former Member
0 Kudos
287

hi

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.

regards

Neha

Former Member
0 Kudos
287

Hi Nikita,

You can use the following FM,

CALL METHOD cl_gui_frontend_services=>file_exist
  EXPORTING
    file                 = w_file
  receiving
    RESULT               =  w_valid.

IF w_valid NE 'X'.
"File name is invalid
ENDIF.

Hope this helps you.

Regards,

Manoj Kumar P