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

FM for checking valid drive on PC

Former Member
0 Likes
1,281

Hi all,

I am developing an interface.

There is one file which is to be uplaoded in my code. I am doing some processing on that code and downloading that file on PC.

User will enter the input & output file name. When user will enter the path I want o check for the drive. Means if user has only C & D drive on my PC & user has given F drive while giving the output file name then it should give error.

Is there any FM or method available for this? I have tried with FM "PC_CHECK_PATH_WITH_DRIVE" but it is not giving me desired result.

Please help.... Its urgent....

Thanks in advance.

Deepti

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,181

Hello Deepti,

Try this...

data: FILE_TABLE type table of SDOKPATH,

wa_file type sdokpath,

line type i,

DIR_TABLE type table of SDOKPATH.

parameter path(30) type c default 'C:\KARTHIKEYAN\'.

CALL FUNCTION 'TMP_GUI_DIRECTORY_LIST_FILES'

EXPORTING

directory = path

tables

file_table = file_table[]

dir_table = dir_table[].

describe table file_table lines line.

if line = 0.

write : 'invalid path'.

else.

write : 'valid path'.

endif.

9 REPLIES 9
Read only

Former Member
0 Likes
1,181

Hi Deepthi,

Try this:

http://www.sapdevelopment.co.uk/file/file_updownpop.htm

A sample code:


*&---------------------------------------------------------------------*
*&      Form  f1003_f4_hlp_for_pc_file
*&---------------------------------------------------------------------*
*       F4 Hlep for PC File
*----------------------------------------------------------------------*
FORM f1003_f4_hlp_for_pc_file.

  DATA: li_filetable TYPE STANDARD TABLE OF file_table,
        lv_return TYPE i,
        lw_filetable TYPE file_table.

  CALL METHOD cl_gui_frontend_services=>file_open_dialog
     EXPORTING
       window_title            = 'Select file for download'
       default_extension       = '.txt'
*       DEFAULT_FILENAME        = '.txt'
*       file_filter             = '*.txt ,*.txt.'
       initial_directory       =  'C:'
     CHANGING
       file_table              = li_filetable
       rc                      = lv_return
     EXCEPTIONS
       file_open_dialog_failed = 1
       cntl_error              = 2
       error_no_gui            = 3
       OTHERS                  = 4
           .
  IF sy-subrc <> 0.
    MESSAGE e003 WITH text-015.
  ELSE.
    READ TABLE li_filetable INTO lw_filetable INDEX 1.
    p_fnam2 = lw_filetable-filename.
  ENDIF.


ENDFORM.                    " f1003_f4_hlp_for_pc_file

Best Regards,

Anjali

Read only

Former Member
0 Likes
1,181

Hi deepti,

1. Why do u want to check the DRIVER?

2 in FM GUI_UPLOAD,

the file name is specified FULL,

along with the drive and path name.

eg. d:\myfolder\myfile.txt

3. If the file (along with the path and drive)

does not exist,

the the FM will give EXCEPTION

saying that -- file not found.

4. So, it checks for the DRIVE as well as FULL PATH Name.

regards,

amit m.

Read only

Former Member
0 Likes
1,181

Hi Amit

I don't have problem while uploading the file. I have problem in GUI_DOWNLOAD.

As I said if my PC has C & D drive only and I am giving F drive in the path name it is not giving any error.

Thanks & Regards

Deepti

Read only

0 Likes
1,181

Hi Deepti,

check this code..

i checked it using e drive , pass the driver dynamically and get the result.

Report ZTEST_DRIVECHECK.
data: rc type c.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_EXIST
  EXPORTING
    DIRECTORY            = 'F'
  RECEIVING
    RESULT               = rc
  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 rc = space.
Write: 'F drive exists'.
else.
Write: 'F drive is not there'.
endif.

regards

vijay

Read only

0 Likes
1,181

Hi,

Pls note Ws_DOWNLOAD is preferred to gui_download.


*p_fnam2 LIKE rlgrap-filename.

  CALL FUNCTION 'WS_DOWNLOAD'
       EXPORTING
            filename                = p_fnam2
            filetype                = 'DAT'
       TABLES
            data_tab                = i_download
       EXCEPTIONS
            file_open_error         = 1
            file_write_error        = 2
            invalid_filesize        = 3
            invalid_type            = 4
            no_batch                = 5
            unknown_error           = 6
            invalid_table_width     = 7
            gui_refuse_filetransfer = 8
            customer_error          = 9
            OTHERS                  = 10.

  IF sy-subrc = 0.
    MESSAGE i352.                          "File downloded successfully
  ENDIF.

Best Regards,

Anjali

Read only

Former Member
0 Likes
1,181

Hi Deepti,

1. file_not_found = 19

2. sy-subrc = 19 if drive is wrong.

3. It surely gives error (by value of sy-subrc <> 0)

after the FM is called.

4. try this code (just copy paste in new program)

5. It WILL GIVE ERROR

6.

REPORT abc.

DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.

SELECT * FROM t001 INTO TABLE t001.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE =

filename = 'k:\abc.txt'

  • FILETYPE = 'ASC'

  • APPEND = ' '

  • WRITE_FIELD_SEPARATOR = ' '

  • HEADER = '00'

  • TRUNC_TRAILING_BLANKS = ' '

  • WRITE_LF = 'X'

  • COL_SELECT = ' '

  • COL_SELECT_MASK = ' '

  • DAT_MODE = ' '

  • CONFIRM_OVERWRITE = ' '

  • NO_AUTH_CHECK = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • WRITE_BOM = ' '

  • TRUNC_TRAILING_BLANKS_EOL = 'X'

  • WK1_N_FORMAT = ' '

  • WK1_N_SIZE = ' '

  • WK1_T_FORMAT = ' '

  • WK1_T_SIZE = ' '

  • IMPORTING

  • FILELENGTH =

TABLES

data_tab = t001

  • FIELDNAMES =

EXCEPTIONS

file_write_error = 1

no_batch = 2

gui_refuse_filetransfer = 3

invalid_type = 4

no_authority = 5

unknown_error = 6

header_not_allowed = 7

separator_not_allowed = 8

filesize_not_allowed = 9

header_too_long = 10

dp_error_create = 11

dp_error_send = 12

dp_error_write = 13

unknown_dp_error = 14

access_denied = 15

dp_out_of_memory = 16

disk_full = 17

dp_timeout = 18

file_not_found = 19

dataprovider_exception = 20

control_flush_error = 21

OTHERS = 22

.

IF sy-subrc = '19'.

WRITE 😕 'FILE NOT FOUND - '.

ENDIF.

regards,

amit m.

Read only

Former Member
0 Likes
1,182

Hello Deepti,

Try this...

data: FILE_TABLE type table of SDOKPATH,

wa_file type sdokpath,

line type i,

DIR_TABLE type table of SDOKPATH.

parameter path(30) type c default 'C:\KARTHIKEYAN\'.

CALL FUNCTION 'TMP_GUI_DIRECTORY_LIST_FILES'

EXPORTING

directory = path

tables

file_table = file_table[]

dir_table = dir_table[].

describe table file_table lines line.

if line = 0.

write : 'invalid path'.

else.

write : 'valid path'.

endif.

Read only

0 Likes
1,181

Hi Abhijit

Thanks a lot.

Problem solved.

Thanks & regards

Deepti

Read only

andreas_mann3
Active Contributor
0 Likes
1,181

Hi,

or look here:

Andreas