弹出输入文件路径提示
*1. Open File Dialog
CALL METHOD cl_gui_frontend_services=>file_open_dialog
CHANGING
file_table = lt_file "Table Holding Selected Files
user_action = l_user_action
rc = l_rc.
IF l_user_action = cl_gui_frontend_services=>action_ok. "ACTION_CANCEL.
READ TABLE lt_file INTO lx_file INDEX 1.
IF sy-subrc = 0.
l_filename = lx_file-filename.
ELSE.
CLEAR l_filename.
ENDIF.
ELSE.
CLEAR l_filename.
ENDIF.
1、文件上传到 FTP 参考程序 ZFG_MM052d
CALL FUNCTION 'Z_FTP_UPLOAD'
EXPORTING
l_data = wa_data
EXCEPTIONS
connecterror = 1
OTHERS = 2.
2、文件下载从 FTP 参考程序 ZFG_MM052d
CALL FUNCTION 'Z_FTP_DOWNLOAD'
EXPORTING
l_data = wa_data
TABLES
t_dir = l_dir[]
EXCEPTIONS
connecterror = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
3、图片转换成编码上传到 ZTPICTURE表中
DATA: l_url TYPE char256,
l_filename TYPE string,
* L_PATH type STRING,
l_length TYPE i,
lt_file TYPE filetable,
lx_file LIKE LINE OF lt_file,
l_rc TYPE i,
l_user_action TYPE i.
DATA: l_picid TYPE indx_srtfd.
REFRESH f_it_pic_data_out.
*2. Upload the file
IF l_filename IS NOT INITIAL .
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = l_filename "Name of file
filetype = 'BIN' "Here is ”Binary type”
IMPORTING
filelength = l_length "File length
CHANGING
data_tab = f_it_pic_data_out[] "Transfer table for file contents
EXCEPTIONS
OTHERS = 19.
IF sy-subrc NE 0 .
MESSAGE e001(00) WITH 'Upload the file Error'.
ENDIF.
ENDIF.
4、从表 ZTPICTURE 中下载图片 参考程序成衣询价单 ZFC_MM005B
FORM load_picture_from_db USING f_key_in ”F_KEY_IN是通知单号也就是流水号
CHANGING f_it_pic_data_out TYPE ty_t_pic_data.
DATA: l_picid TYPE indx_srtfd.
REFRESH f_it_pic_data_out.
CONCATENATE 'ZCOSTACCH' f_key_in INTO l_picid .
IMPORT pic_data = f_it_pic_data_out FROM DATABASE ztpicture(mm) ID l_picid.”取得表中编码
IF sy-subrc <> 0.
REFRESH f_it_pic_data_out.
ENDIF.
ENDFORM. "LOAD_PICTURE_FROM_DB
data :l_length TYPE i. “这两个方法都可以把图片编码以图片的形式下载到本地 ZT
CALL METHOD cl_gui_frontend_services=>gui_DOWNLOAD
EXPORTING
filename = 'C:Documents and SettingsAdministrator桌面1.JPG' "Name of file
filetype = 'BIN' "Here is ”Binary type”
IMPORTING
filelength = l_length "File length
CHANGING
data_tab = it_pic_data[] "Transfer table for file contents
EXCEPTIONS
OTHERS = 19.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE =
filename = 'C:Documents and SettingsAdministrator桌面1.JPG'
filetype = 'JPG'
TABLES
data_tab = it_pic_data[]
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.