*&---------------------------------------------------------------------*
*& Report ZDEMO14
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zdemo14.
DATA:gs_bin TYPE tbl1024,
gt_bin LIKE TABLE OF gs_bin.
DATA:gv_filename TYPE string,
gv_filelength TYPE i,
gv_i TYPE i,
gv_header TYPE xstring,
gv_string TYPE xstring.
PERFORM get_filename USING gv_filename.
CHECK gv_filename IS NOT INITIAL.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = gv_filename
filetype = 'BIN'
IMPORTING
filelength = gv_filelength
header = gv_header
TABLES
data_tab = gt_bin
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = gv_filelength
IMPORTING
buffer = gv_string
TABLES
binary_tab = gt_bin
EXCEPTIONS
failed = 1
OTHERS = 2.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
bin_filesize = gv_filelength
filename = 'D:\20200921.xls'
filetype = 'BIN'
TABLES
data_tab = gt_bin
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.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
*&---------------------------------------------------------------------*
*& Form get_filename
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PV_PATH text
*----------------------------------------------------------------------*
FORM get_filename USING pv_path TYPE string..
DATA : lv_file_filter TYPE string.
DATA : ls_filetable TYPE file_table,
lt_filetable TYPE filetable.
DATA : lv_rc TYPE i.
DATA : lv_user_action TYPE i.
lv_file_filter = '(*.xlsx;*.xls)|*.xlsx;*.xls|'.
cl_gui_frontend_services=>file_open_dialog(
EXPORTING window_title = 'Select file'
file_filter = lv_file_filter
CHANGING file_table = lt_filetable
rc = lv_rc
user_action = lv_user_action ).
CHECK lv_user_action EQ 0.
CHECK lt_filetable[] IS NOT INITIAL.
READ TABLE lt_filetable INTO ls_filetable INDEX 1.
pv_path = ls_filetable-filename.
ENDFORM. "get_filename
阅读(4333) | 评论(0) | 转发(0) |