report ztest.
data : begin of li_makt occurs 0,
matnr type matnr,
maktx type maktx,
end of li_makt.
data: begin of li_head occurs 0,
field(30) type c,
end of li_head.
selection-screen begin of block b2 with frame title text-002.
parameters:
p_file type rlgrap-filename obligatory.
selection-screen end of block b2.
at selection-screen on value-request for p_file.
perform browse_file changing p_file.
start-of-selection.
refresh li_head.
define mc_head.
li_head-field = &1.
append li_head.
end-of-definition.
select matnr maktx into table li_makt from makt up to 20 rows
where spras = sy-langu .
mc_head : '物料编码', '物料名称'.
call function 'EXCEL_OLE_STANDARD_DAT'
exporting
file_name = p_file
create_pivot = 0
data_sheet_name = 'Data Material'
pivot_sheet_name = ' '
password = '1234'
password_option = 1
tables
data_tab = li_makt
fieldnames = li_head
exceptions
file_not_exist = 1
filename_expected = 2
communication_error = 3
ole_object_method_error = 4
ole_object_property_error = 5
invalid_filename = 6
invalid_pivot_fields = 7
download_problem = 8
others = 9.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
*&---------------------------------------------------------------------*
*& Form browse_file
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_FILE text
*----------------------------------------------------------------------*
form browse_file changing p_file like rlgrap-filename.
data: filetab type filetable,
rc type i,
lv_offset type i.
free filetab.
call method cl_gui_frontend_services=>file_open_dialog
exporting
window_title = 'Choose File'
default_extension = '*.*'
default_filename = 'c:\*.xls'
changing
file_table = filetab
rc = rc
exceptions
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
others = 4.
if sy-subrc = 0.
read table filetab into p_file index 1.
endif.
endform. " browse_file
阅读(1701) | 评论(0) | 转发(0) |