2006 May 05 7:26 PM
Hi all,
I want to read a file name as an input. I tried the following syntax :
<b>parameters : p_file type RLGRAP-FILENAME.</b>
But I need F4 functionality too. Does any can provide me some inputs on this.
Thanks and regards,
Varun.
2006 May 05 7:31 PM
try this:
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_infile.
Local variable declaration
DATA: l_title TYPE string, " Title of dialog
" window
l_filename TYPE file_table, " For getting selected
" File name
l_filefilter TYPE string, " File Filter-excel
" files
l_filerc TYPE i, " Return Code
l_fileaction TYPE i. " User Action
*Internal table for getting the File name in the file selection
*dialog box
DATA: l_filetable TYPE filetable.
The method 'file_open_dialog' of class 'cl_gui_frontend_services'
is used for displaying the file selection dialog box.
CLASS cl_gui_frontend_services DEFINITION LOAD.
Move the title text from the text element to local variable
of type string
l_title = 'Select File'.
Setting the File Filter to Excel Files
l_filefilter = cl_gui_frontend_services=>filetype_all.
Display the file open dialog
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = l_title " Title of the file
" Selection window
default_extension = c_extension " Ext. of the file
file_filter = l_filefilter " All files to
" be displayed in the
" selection window
CHANGING
file_table = l_filetable " Contains the filename
" selected
rc = l_filerc " Return code
user_action = l_fileaction " User action
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4.
IF sy-subrc = 0.
On File name Selection
IF l_fileaction EQ cl_gui_frontend_services=>action_ok.
CHECK NOT l_filetable[] IS INITIAL.
Only one file can be selected at a time so read
the first entry of the table l_filetable
READ TABLE l_filetable INTO l_filename INDEX 1.
No sy-subrc check
Displaying the selected file name in the File name Parameter
on the screen
p_file = l_filename-filename.
ENDIF.
ENDIF.
2006 May 05 7:31 PM
try this:
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_infile.
Local variable declaration
DATA: l_title TYPE string, " Title of dialog
" window
l_filename TYPE file_table, " For getting selected
" File name
l_filefilter TYPE string, " File Filter-excel
" files
l_filerc TYPE i, " Return Code
l_fileaction TYPE i. " User Action
*Internal table for getting the File name in the file selection
*dialog box
DATA: l_filetable TYPE filetable.
The method 'file_open_dialog' of class 'cl_gui_frontend_services'
is used for displaying the file selection dialog box.
CLASS cl_gui_frontend_services DEFINITION LOAD.
Move the title text from the text element to local variable
of type string
l_title = 'Select File'.
Setting the File Filter to Excel Files
l_filefilter = cl_gui_frontend_services=>filetype_all.
Display the file open dialog
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = l_title " Title of the file
" Selection window
default_extension = c_extension " Ext. of the file
file_filter = l_filefilter " All files to
" be displayed in the
" selection window
CHANGING
file_table = l_filetable " Contains the filename
" selected
rc = l_filerc " Return code
user_action = l_fileaction " User action
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4.
IF sy-subrc = 0.
On File name Selection
IF l_fileaction EQ cl_gui_frontend_services=>action_ok.
CHECK NOT l_filetable[] IS INITIAL.
Only one file can be selected at a time so read
the first entry of the table l_filetable
READ TABLE l_filetable INTO l_filename INDEX 1.
No sy-subrc check
Displaying the selected file name in the File name Parameter
on the screen
p_file = l_filename-filename.
ENDIF.
ENDIF.
2006 May 05 7:33 PM
Please see the following sample program.
report zrich_0001.
parameters: p_file type localfile.
at selection-screen on value-request for p_file.
data: ifile type filetable.
data: xfile like line of ifile.
data: rc type i.
call method cl_gui_frontend_services=>file_open_dialog
exporting
initial_directory
= 'C:'
changing
file_table = ifile
rc = rc.
read table ifile into xfile index 1.
check sy-subrc = 0.
p_file = xfile-filename.
Regards,
Rich Heilman
2006 May 05 7:33 PM
Hi varun,
Try cl_gui_frontend_services=>file_open_dialog in the event..
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
Regrads,
Tanveer.
Please mark helpful answers
2006 May 05 7:44 PM
Hi all,
<b>Great minds think alike !!!</b>
All three gave the same answer. Thank you all guys for providing me prompt answer.
Regards,
Varun.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |