sexta-feira, 19 de março de 2010

How to create a dialog to go to a local/server directory and save/read a file

this form opens a dialog to select the directory where you want to save/read a local file


*&---------------------------------------------------------------------*
*& Form f4_save_lfile
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_P_LFILE text *----------------------------------------------------------------------* FORM f4_save_lfile CHANGING p_file. DATA: l_filename TYPE string, l_path TYPE string, l_fullpath TYPE string. CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
* window_title =
default_extension = 'TXT'
* default_file_name =
* with_encoding =
* file_filter =
* initial_directory =
prompt_on_overwrite = 'X'
CHANGING
filename = l_filename
path = l_path
fullpath = l_fullpath
* user_action =
* file_encoding =
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

p_file = l_fullpath.

ENDFORM. " f4_save_lfile

To do the same but on a server file, you should use this:

*&---------------------------------------------------------------------*
*& Form f4_rfile
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_P_RFILE text *----------------------------------------------------------------------* FORM f4_rfile CHANGING p_rfile. *" VALUE(I_LOCATION_FLAG) LIKE DXFIELDS-LOCATION DEFAULT ' ' *" VALUE(I_SERVER) LIKE MSXXLIST-NAME DEFAULT '?' *" VALUE(I_PATH) LIKE DXFIELDS-LONGPATH OPTIONAL *" VALUE(FILEMASK) LIKE DXFIELDS-FILEMASK DEFAULT '*.*' *" VALUE(FILEOPERATION) LIKE DXFIELDS-FILEOPER DEFAULT 'R' *" EXPORTING DATA: l_location LIKE dxfields-location, l_server LIKE msxxlist-name, l_path LIKE dxfields-longpath, l_flag LIKE dxfields-abendflag. CALL FUNCTION 'F4_DXFILENAME_TOPRECURSION' EXPORTING i_location_flag = 'A' * I_SERVER = '?' * I_PATH = * FILEMASK = '*.*' * FILEOPERATION = 'R' IMPORTING o_location_flag = l_location o_server = l_server o_path = l_path abend_flag = l_flag EXCEPTIONS rfc_error = 1 error_with_gui = 2 OTHERS = 3 . IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

MOVE l_path TO p_rfile.

ENDFORM. " f4_rfile

Sem comentários:

Enviar um comentário