Skip to Content
avatar image
Former Member

How to check pc file path validity?

Hi,

In my program I have to extract so much SAP data and write in a file in the fornt-end PC. In the selection screen I will input the filepath\name to write the data.

But how should I check whether the filepath is valid or not in the 'AT SELECTION-SCREEN' event itself? so that if it is not valid path, I can give an error message before extracting all the SAP data.

Thank you!

Sunitha.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

7 Answers

  • Best Answer
    avatar image
    Former Member
    Apr 25, 2006 at 01:27 AM

    Hi Sunitha,

    Use the function module WS_QUERY to check whether the given directory exist or not...

    Hope this helps.

    Regards,

    Nagaraju Chidurupalli.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Sunitha,

      I am still NOT clear as to what is big difference between validating the path / file itself.

      Anyways, you can call the DIRECTORY_BROWSE method, if it returns the values, the path is right, other wise it has problems. There is no separate method to validate the path alone.

      Regards,

      Ravi

      Note : Please close the thread, if this solves the issue.

  • avatar image
    Former Member
    Apr 25, 2006 at 05:37 PM

    You got to find that last '\' in your path and use the string till that point as path.

    use the following code as reference.

    data v_pos like sy-fdpos value 1.

    data v_path(100).

    parameters v_file(100) default 'C:\temp\filename.txt' lower case.

    *v_file = strrev( v_file ).

    do.

    search v_file for '\' starting at v_pos.

    if sy-subrc ne 0.

    exit.

    endif.

    v_pos = v_pos + sy-fdpos + 1.

    enddo.

    if v_pos gt 1.

    subtract 1 from v_pos.

    v_path = v_file(v_pos).

    endif.

    Regards,

    Nagaraju Chidurupalli

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 25, 2006 at 02:16 AM

    Hi Sunitha,

    Please check the following sample code from other thread at selection screen value request event.

    Using ABAP Objects:

    PARAMETER : p_file LIKE rlgrap-filename.
    
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR path.
    
    DATA: directory TYPE string,                             
          filetable TYPE filetable,                          
          line      TYPE LINE OF filetable,                  
          rc        TYPE i.                                  
     
    CALL METHOD cl_gui_frontend_services=>get_temp_directory 
      CHANGING                                               
          temp_dir = directory.       
                             
    CALL METHOD cl_gui_frontend_services=>file_open_dialog   
      EXPORTING                                              
          window_title      = 'SELECT THE FILE'          
          initial_directory = directory                      
          file_filter       = '*.XLS'                        
          multiselection    = ' '                            
        CHANGING                                             
          file_table        = filetable     
          rc                = rc.                        
       
    IF rc = 1.                                           
      READ TABLE filetable INDEX 1 INTO line.            
      P_FILE = line-filename.                          
    ENDIF.    

    Using Normal ABAP:

    DATA: P_FILE LIKE RLGRAP-FILENAME,
          DPATH LIKE RLGRAP-FILENAME,
          UPATH LIKE RLGRAP-FILENAME,
          MODE TYPE C,
          FLG_UD TYPE C.
     
    CALL FUNCTION 'WS_ULDL_PATH'
      IMPORTING
        DOWNLOAD_PATH = DPATH
        UPLOAD_PATH   = UPATH.
     
    IF FLG_UD <> 'D'.
      DPATH = UPATH.
      MODE = 'O'.
    ELSE.
      MODE = 'S'.
    ENDIF.
     
    CALL FUNCTION 'WS_FILENAME_GET'
      EXPORTING
        DEF_FILENAME     = '*.XLS'
        DEF_PATH         = DPATH
        MASK             = ',*.XLS,*.*,*.*.'
        MODE             = MODE
      IMPORTING
        FILENAME         = P_FILE
      EXCEPTIONS
        SELECTION_CANCEL = 3.
    
    IF SY-SUBRC <> 0.
      EXIT.
    ENDIF.
    

    Hope this will help.

    Regards,

    Ferry Lianto

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 25, 2006 at 03:14 AM

    Hi Sunita,

    You can also use this function module 'F4_Filename'. I am giving you a sample code also illustrating how to use that function module.

    data : gv_file type string.

    *****************************************************************

    *SELECTION SCREEN *

    *****************************************************************

    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

    <b>PARAMETERS: p_file LIKE ibipparms-path obligatory. " For file selection</b>

    SELECTION-SCREEN END OF BLOCK b1.

    *****************************************************************

    *AT SELECTION SCREEN *

    *****************************************************************

    <b>AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.</b>

    <b>CALL FUNCTION 'F4_FILENAME'

    EXPORTING

    PROGRAM_NAME = SYST-CPROG

    DYNPRO_NUMBER = SYST-DYNNR

    • FIELD_NAME = ' '

    IMPORTING

    FILE_NAME = p_file.</b>*****************************************************************

    *START OF SELECTION * *

    *****************************************************************

    START-OF-SELECTION.

    • P_FILE is not compatible with the FM GUI_UPLOAD, so pass it to

    • GV_FILE.

    gv_file = p_file.

    *********************

    Now you can use the function module gui_download to extract SAP data and write in a file in the fornt-end PC. Here the file can be gv_file.

    Thanks and Regards,

    Kunal.

    Message was edited by: Kunal Kumar

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 25, 2006 at 05:36 AM

    Hi Sunitha,

    You have to write file check filepath validation in the 'AT SELECTION-SCREEN' event.You can refer to the following code:

    PARAMETERS: <screen-field name> TYPE fileextern.

    AT SELECTION-SCREEN ON VALUE-REQUEST FOR <screen-field name>.

    CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'

    IMPORTING

    serverfile = <File name>

    EXCEPTIONS

    canceled_by_user = 1

    OTHERS = 2.

    IF sy-subrc = 0.

    <screen-field name> = <file name>

    ELSE.

    error message.

    ENDIF.

    Kindly mark if helpful.

    Regards,

    Shakuntala

    Message was edited by: shakuntala Negi

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 24, 2006 at 10:31 PM

    Hi Sunitha,

    You can use the FILE_OPEN_DIALOG or FILE_SAVE_DIALOG methods in the class CL_GUI_FRONTEND_SERVICES so that the useer selects a valid file path.

    regards,

    Suresh Datti

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Apr 24, 2006 at 10:55 PM

    Checkout !!!

    parameter: p_path(50) type c default '/ds/<SYS>/int/hr/bud/' obligatory lower case.

    parameter p_dsn like rlgrap-filename obligatory. " OUTPUT FILENAME

    lower case.

    selection-screen skip.

    selection-screen skip.

    DATA: wc_logical_path like filenameci-fileintern . "( You have create this logical path in :Transaction :FILE )

    data: wc_output_file(128) type c. " INPUT FILE PATH AND NAME

    parameters: ds type localfile default '/usr/sap/nsp/tmp/file.txt'.

    at selection-screen.

    wc_logical_path = 'Z_INTERFACE_MTI_BUD'.

    • TRANSLATE THE LOGICAL PATH TO THE PHYSICAL PATH

    CALL FUNCTION 'FILE_GET_NAME_USING_PATH'

    EXPORTING

    CLIENT = SY-MANDT

    logical_path = wc_logical_path

    operating_system = sy-opsys

    file_name = p_dsn

    IMPORTING

    file_name_with_path = wc_output_file

    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 e001(00) with 'Can not open file in path'.

    endif.

    oteher option : i`ll reccomand this Why ! less maintaince you font have to create logical path again and gain in File transaction .

    use this

    open dataset ds for output in text mode encoding default.

    if sy-subrc <> 0.

    message e001(00) with 'Can not open file in path'.

    endif.

    Add comment
    10|10000 characters needed characters exceeded