05-24-2013 11:05 AM
Hi,
I call the method to display an open dialog. But after I choose a file via the dialog triggered by the method, the file name cannot be imported to the corresponding PARAMETER at the selection screen.
Are further coding or other methods needed?
Best regards,
ts
05-24-2013 1:24 PM
After calling method you need to set the parameter value.
Check below code for your ref...
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
lcl_maintain_pa_mc=>get_file( ).
p_file = gw_file-filename.
METHOD get_file.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
* EXPORTING
* window_title =
* default_extension =
* default_filename =
* file_filter =
* with_encoding =
* initial_directory =
* multiselection =
CHANGING
file_table = gt_file_table
rc = gw_rc
user_action = gw_user_action
* file_encoding =
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5
.
IF sy-subrc EQ 0.
* Implement suitable error handling here
READ TABLE gt_file_table INTO gw_file INDEX 1.
ENDIF.
endmethod.
Message was edited by: vasu devarao
05-24-2013 11:46 AM
Hi,
Try with below code.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
EXPORTING
WINDOW_TITLE = 'Save file'
DEFAULT_EXTENSION = ''
DEFAULT_FILE_NAME = 'Image'
WITH_ENCODING = ''
FILE_FILTER = ''
INITIAL_DIRECTORY = 'D\'
PROMPT_ON_OVERWRITE = 'X'
CHANGING
FILENAME = GV_FILENAME
PATH = GV_PATH
FULLPATH = GV_FULLPATH
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 3
OTHERS = 4.
05-24-2013 11:57 AM
For better responses please paste relevant portion of the code snippet. 2 questions:
BR,
Suhas
05-24-2013 12:24 PM
05-24-2013 1:24 PM
After calling method you need to set the parameter value.
Check below code for your ref...
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
lcl_maintain_pa_mc=>get_file( ).
p_file = gw_file-filename.
METHOD get_file.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
* EXPORTING
* window_title =
* default_extension =
* default_filename =
* file_filter =
* with_encoding =
* initial_directory =
* multiselection =
CHANGING
file_table = gt_file_table
rc = gw_rc
user_action = gw_user_action
* file_encoding =
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5
.
IF sy-subrc EQ 0.
* Implement suitable error handling here
READ TABLE gt_file_table INTO gw_file INDEX 1.
ENDIF.
endmethod.
Message was edited by: vasu devarao
05-24-2013 3:46 PM
Hi,
Please check the wiki article in the below link.
http://wiki.sdn.sap.com/wiki/display/ABAP/File,+Directory+Operations+using+CL_GUI_FRONTEND_SERVICES
You will get a good idea of what's missing. This class usage is quiet common, just debug to understand the values that is getting passed to the parameters to understand why it cannot do so. Check the datatype of parameter.
Cheers,
Arindam
07-08-2019 11:20 PM
Hi,
try this..
SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L0S31 { font-style: italic; color: #808080; } .L0S32 { color: #3399FF; } .L0S52 { color: #0000FF; } .L0S55 { color: #800080; } .L0S70 { color: #808080; }
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file. "For F4 Help Event
* Give file path
CALL METHOD cl_gui_frontend_services=>file_open_dialog
CHANGING
file_table = lv_file " This will capture File path but it's a table "format
rc = rc "row count
* user_action =
* file_encoding =
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.
IF sy-subrc EQ 0.
* in this point will pass the path to the parameter
READ TABLE lv_file INDEX 1 INTO file_path.
p_file = file_path.
ENDIF.
Cheers,
Luis Hidalgo.
12-15-2023 4:20 PM
Hello, for getting the file you need to create an internal table and work area of FILE_TABLE structure and then you need to pass your parameter into the filename field of the above created work area and append it into the internal table. Use the AT selection on value request event for parameter , and read the internal table after running FILE_OPEN_DIALOG, you will get the file.
DATA: lt_file TYPE TABLE OF file_table,
ls_file TYPE file_table,
lv_file TYPE string,
lv_rc TYPE i.
PARAMETERS : p_file TYPE localfile.
ls_file-filename = p_file.
APPEND ls_file TO lt_file.
CLEAR ls_file.
"Providing a search help.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = 'Please Select your file'
CHANGING
file_table = lt_file
rc = lv_rc
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.
READ TABLE lt_file INTO ls_file INDEX 1.
IF sy-subrc EQ 0.
lv_file = ls_file-filename.
CLEAR ls_file.
ENDIF.
Note :- you will get your file in lv_file, after that you can call gui_upload to upload this file and store it into internal table.
12-15-2023 7:07 PM
Please edit your answer (Actions>Edit), select your code and press the button [CODE], which makes the code appear colored/indented, it'll be easier for people to look at it. Thanks!
Note that your code doesn't compile and even after the quick fix, it still "doesn't work": the selected file doesn't return in the screen field.
PS: not sure your answer will be spotted, there are tens of questions about this method (also blog posts like Dump DYNPRO_MSG_IN_HELP on F4 help for file selection | SAP Blogs), I recommend to publish a blog post with the best fit title like "Demo program of CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG".
DATA lt_file TYPE TABLE OF file_table.
DATA ls_file TYPE file_table.
DATA lv_file TYPE string.
DATA lv_rc TYPE i.
PARAMETERS p_file TYPE localfile.
ls_file-filename = p_file.
APPEND ls_file TO lt_file.
CLEAR ls_file.
"Providing a search help.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
cl_gui_frontend_services=>file_open_dialog( EXPORTING window_title = 'Please Select your file'
CHANGING file_table = lt_file
rc = lv_rc
EXCEPTIONS file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5 ).
READ TABLE lt_file INTO ls_file INDEX 1.
IF sy-subrc EQ 0.
lv_file = ls_file-filename.
CLEAR ls_file.
ENDIF.
12-16-2023 9:25 AM
-1 because your code doesn't compile and even after the quick fix, it still "doesn't work": the selected file doesn't fill the screen field.
I think that the F4 dialog doesn't show the folder which corresponds to the P_FILE value.
12-16-2023 9:32 AM
Hey Sandra Rossi,
thanx for replying.
The code is perfectly fine, It was just a common mistake, the declaration of lv_rc TYPE i. was missing.
please re run the code, you will get your file in lv_file. Open the debugger and check for any queries. After that you can use GUI_UPLOAD for uploading it.
And let me know if there is any issue
12-16-2023 1:33 PM
Yes there are the two issues I told you, unless you have declared P_FILE for no reason, but I think people would expect that your code works with P_FILE, not by debug of LV_FILE.
I hope that now I made it clear with this third comment.
12-16-2023 1:40 PM
Look I think you have misunderstood the code. p_file is of type localfile which is because when we select a file we use this field. But lv_file is of type string which will be used for gui_upload. Because gui_upload takes file in string only. So for using gui_ upload everyone will require to convert this p_file into string only. Please understand the requirement first.
And please remove your minus -1.
12-16-2023 2:13 PM
It deserves a -1 for the reason I mentioned, you can't go against the rules, please read them here, voting is explained: Ask and Answer Questions on SAP Community | SAP Tutorials.
You can change the type of P_FILE to STRING and LOWER CASE, but maybe you don't want to learn.
I'm sorry that you don't accept positive criticism.