04-24-2006 11:26 PM
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.
04-25-2006 2: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.
04-24-2006 11: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
04-24-2006 11: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.
04-25-2006 2: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.
04-25-2006 3:51 AM
Just to add to what Nagaraju has mentioned
DATA: g_return.
CALL FUNCTION 'WS_QUERY'
EXPORTING
* ENVIRONMENT =
filename = 'C:temp'
query = 'DE'
* WINID =
IMPORTING
return = g_return
EXCEPTIONS
inv_query = 1
no_batch = 2
frontend_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
***some error message
ENDIF.
CASE g_return.
WHEN '0'.
**does not exist
WHEN '1'.
*exists
ENDCASE.
04-25-2006 6:11 PM
Hi,
In the selection screen, I will input the whole filepath along with the file name also. So to use the function Module 'WS_QUERY' in the event 'AT SELECTION-SCREEN', I should just get the file path alone from the selection screen field. How can I get it?
For example: from 'C:\temp\filename.txt' how can I get 'C:\temp' alone?
Thanks!
Sunitha.
04-25-2006 6:21 PM
Sunitha,
I think you will have to check if the file exists or not which you can do using FILE_EXIST method of class CL_GUI_FRONTEND_SERVICES.
You can SELECT the fields using the F4 help and in the POH you can call the method FILE_OPEN_DIALOG which will POPUP the windows for the user. After that call the FILE_EXIST method to validate the file. Even if the user enters the path manually you can validate.
Regards,
Ravi
Note : Please mark all the helpful answers
04-25-2006 6:26 PM
Hi Ravi,
I will have to create the file in a valid file path. So I don't have to check with FILE_EXIST method, I just want to check whether the file path exists.
Thanks!
Sunitha.
04-25-2006 6:31 PM
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.
04-25-2006 3: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
04-25-2006 4: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
04-25-2006 6: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
04-25-2006 6: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
04-25-2006 10:50 PM