*&---------------------------------------------------------------------*
*& Report ZMMR011
*&
*&---------------------------------------------------------------------*
*&程序名称:供应商、工厂对应公里数维护
*&事物代码:ZMM031
*&导入模板:无
*&作者:董冬
*&时间:2016/3/2
*&更新时间:2016/3/3
*&---------------------------------------------------------------------*
REPORT zmmr011.
TABLES: tvbvk ,cskt ,ztmm002,sscrfields.
TYPES:ty_xs LIKE v_tvbur.
DATA:gt_xs LIKE TABLE OF v_tvbur.
DATA:wa_xs TYPE v_tvbur.
DATA:edit(1) VALUE ‘‘."ALV是否处于可编辑状态
DATA: excel TYPE ole2_object,
workbook TYPE ole2_object,
sheet TYPE ole2_object,
cell TYPE ole2_object,
row TYPE ole2_object.
DATA:lt_lfa1 TYPE lfa1 OCCURS 0 WITH HEADER LINE. "供应商内表
DATA:lt_t001w TYPE t001w OCCURS 0 WITH HEADER LINE."工厂内表
FIELD-SYMBOLS: <f1>, <f2>, <f3>.
TYPES:BEGIN OF ty_tab.
INCLUDE TYPE ztmm002.
TYPES: lifnr_name LIKE lfa1-name1,
werks_name LIKE t001w-name1.
TYPES:END OF ty_tab.
DATA :gt_zz TYPE STANDARD TABLE OF ty_tab .
DATA:wa_zz TYPE ty_tab.
FORM get_data.
* CALL FUNCTION ‘VIEW_GET_DATA‘
* EXPORTING
* view_name = ‘V_TVBUR‘
* TABLES
* data = gt_xs.
SELECT *
FROM lfa1
INTO CORRESPONDING FIELDS OF TABLE lt_lfa1.
SELECT *
FROM t001w
INTO CORRESPONDING FIELDS OF TABLE lt_t001w.
SELECT *
FROM ztmm002
INTO CORRESPONDING FIELDS OF TABLE gt_zz.
LOOP AT gt_zz INTO wa_zz.
READ TABLE lt_lfa1 WITH KEY lifnr = wa_zz-lifnr.
wa_zz-lifnr_name = lt_lfa1-name1.
READ TABLE lt_t001w WITH KEY werks = wa_zz-werks.
wa_zz-werks_name = lt_t001w-name1.
MODIFY gt_zz FROM wa_zz.
ENDLOOP.
ENDFORM.
DATA: gs_fcat TYPE lvc_s_fcat,
gt_fcat TYPE lvc_t_fcat,
gs_layo TYPE lvc_s_layo,
gs_grid TYPE lvc_s_glay.
DATA: gt_event TYPE slis_t_event WITH HEADER LINE,
gt_event_exit TYPE slis_t_event_exit WITH HEADER LINE.
DATA: ref_grid TYPE REF TO cl_gui_alv_grid .
"parameters: p_ds type c as checkbox.
SELECTION-SCREEN BEGIN OF BLOCK blk2 WITH FRAME TITLE text-002.
PARAMETERS: r1 RADIOBUTTON GROUP gr1 DEFAULT ‘X‘ USER-COMMAND radio.
PARAMETERS: r2 RADIOBUTTON GROUP gr1.
SELECTION-SCREEN END OF BLOCK blk2.
DATA: filepath LIKE rlgrap-filename .
DATA: file LIKE rlgrap-filename.
START-OF-SELECTION.
IF r1 EQ ‘X‘.
PERFORM get_data.
PERFORM show_data_to_alv.
ELSEIF r2 EQ ‘X‘.
PERFORM frm_path_selected CHANGING filepath.
CONCATENATE filepath ‘\供应商工厂对应公里数模板.XLS‘ INTO file.
PERFORM frm_download_template USING file.
ENDIF.
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS handle_modify
FOR EVENT data_changed_finished OF cl_gui_alv_grid
IMPORTING e_modified et_good_cells.
METHODS data_changed
FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed.
ENDCLASS.
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_modify.
* PERFORM refresh.
DATA stbl TYPE lvc_s_stbl.
stbl-row = ‘X‘." 基于行的稳定刷新
stbl-col = ‘X‘." 基于列稳定刷新
CALL METHOD ref_grid->refresh_table_display
EXPORTING
is_stable = stbl.
ENDMETHOD.
METHOD data_changed.
DATA: ls_mod_cells TYPE lvc_s_modi,
tvalue TYPE string.
DATA: ls_stable TYPE lvc_s_stbl.
DATA: l_message TYPE string.
*
DATA:wa_lfa1 TYPE lfa1.
DATA:wa_t001w TYPE t001w.
DATA:row_no TYPE i.
CHECK er_data_changed->mt_inserted_rows[] IS INITIAL.
LOOP AT er_data_changed->mt_good_cells INTO ls_mod_cells.
CLEAR tvalue.
CALL METHOD er_data_changed->get_cell_value
EXPORTING
i_row_id = ls_mod_cells-row_id
i_fieldname = ls_mod_cells-fieldname
IMPORTING
e_value = tvalue.
IF ls_mod_cells-fieldname EQ ‘LIFNR‘.
LOOP AT lt_lfa1 INTO wa_lfa1 .
IF wa_lfa1-lifnr EQ tvalue.
CALL METHOD er_data_changed->modify_cell
EXPORTING
i_row_id = ls_mod_cells-row_id
i_fieldname = ‘LIFNR_NAME‘
i_value = wa_lfa1-name1.
EXIT.
ENDIF.
CLEAR lt_lfa1.
ENDLOOP.
ENDIF.
IF ls_mod_cells-fieldname EQ ‘WERKS‘.
LOOP AT lt_t001w INTO wa_t001w.
IF wa_t001w-werks EQ tvalue.
CALL METHOD er_data_changed->modify_cell
EXPORTING
i_row_id = ls_mod_cells-row_id
i_fieldname = ‘WERKS_NAME‘
i_value = wa_t001w-name1.
EXIT.
ENDIF.
CLEAR wa_t001w.
ENDLOOP.
ENDIF.
* DATA:blank_zz TYPE ztmm002.
*
*
*
* LOOP AT tab_tvgrt INTO wa_tvgrt .
* IF wa_tvgrt-vkgrp EQ tvalue.
* CLEAR wa_zz.
* LOOP AT gt_zz INTO wa_zz.
* IF wa_zz-vkgrp EQ tvalue AND tvalue NE ‘‘.
* MESSAGE i001(00) WITH ‘已有相同的销售组!‘.
*
* "MODIFY gt_zz INDEX ls_mod_cells-row_id FROM blank_zz .
* CLEAR wa_tvgrt.
* "如果有重复的销售组,那么将输入的销售组清空
* CALL METHOD er_data_changed->modify_cell
* EXPORTING
* i_row_id = ls_mod_cells-row_id
* i_fieldname = ‘VKGRP‘
* i_value = ‘‘.
* ENDIF.
*
* CONTINUE.
* ENDLOOP.
*
* CALL METHOD er_data_changed->modify_cell
* EXPORTING
* i_row_id = ls_mod_cells-row_id
* i_fieldname = ‘VKGRPTEXT‘
* i_value = wa_tvgrt-bezei.
* ENDIF.
* CLEAR wa_tvgrt.
* ENDLOOP.
*
* IF strlen( tvalue ) GT 4.
*
*
* LOOP AT tab_cskt INTO wa_cskt .
* IF wa_cskt-kostl EQ tvalue.
* CALL METHOD er_data_changed->modify_cell
* EXPORTING
* i_row_id = ls_mod_cells-row_id
* i_fieldname = ‘LTEXT‘
* i_value = wa_cskt-ltext.
* EXIT.
* ENDIF.
* CLEAR wa_cskt.
* ENDLOOP.
* ENDIF.
ENDLOOP.
ENDMETHOD. "HANDLE_MODIFY
ENDCLASS. "LCL_EVENT_RECEIVER IMPLEMENTATION
DATA gt_event_receiver TYPE REF TO lcl_event_receiver .
FORM show_data_to_alv.
CLEAR gt_fcat[].
PERFORM set_fcat USING edit.
PERFORM set_layout.
PERFORM show_alv TABLES gt_fcat gt_zz[]
USING gs_layo.
ENDFORM.
FORM frm_edit_alv." TABLES GT.
*DATA: ls_row TYPE lvc_s_cell,
* lt_rows TYPE lvc_t_cell.
* "CLEAR GT_HEADER.
* "CLEAR GT_ITEMS.
* CALL METHOD ref_grid->GET_SELECTED_CELLS
* IMPORTING
* et_index_cells = lt_rows
ENDFORM.
FORM show_changed_alv.
CLEAR gt_fcat[].
* IF edit EQ ‘‘ .
* edit = ‘X‘.
* ELSE.
* edit = ‘‘.
* ENDIF.
PERFORM set_fcat USING edit.
PERFORM set_layout.
PERFORM show_alv TABLES gt_fcat gt_zz[]
USING gs_layo.
PERFORM frm_edit_alv.
ENDFORM.
FORM set_fcat USING edit.
PERFORM csalv_set_fcat USING :
" ‘Field‘ ‘Text‘ ‘Edit‘ ‘Zero‘ ‘Type‘ ‘Qfieldname‘ ‘Key‘ ‘Hostspot‘ ‘Emphasize‘ ‘Checkbox‘
‘LIFNR‘ ‘供应商或债权人账号‘ edit ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘X‘ ‘ZTMM002‘ ‘LIFNR‘ ‘LIFNR‘ ‘C‘,
‘LIFNR_NAME‘ ‘供应商名称‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘,
‘WERKS‘ ‘工厂‘ edit ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘X‘ ‘ZTMM002‘ ‘WERKS‘ ‘‘ ‘‘,
‘WERKS_NAME‘ ‘工厂名称‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘,
‘MENGE‘ ‘数量‘ edit ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘C‘ ‘QUAN‘,
‘MEINS‘ ‘单位‘ edit ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘ ‘‘.
ENDFORM. " SET_FCAT
FORM set_layout .
gs_layo
-zebra = ‘X‘.
* gs_layout-stylefname = ‘FIELD_STYLE‘.
gs_layo
-cwidth_opt = ‘X‘.
ENDFORM. " SET_LAYOUT
*&---------------------------------------------------------------------*
FORM csalv_set_fcat USING
p_name
p_text
p_edit
p_zero
p_type
p_qfieldname
p_key
p_hotspot
p_emphasize
p_checkbox
p_do_sum
p_decimals_out
p_no_out
p_f4availabl
p_ref_table
p_ref_field
p_inttype
p_datatype
.
gs_fcat
-fieldname = p_name.
* gs_fcat-reptext_l =
* gs_fcat-selddictxt =
gs_fcat
-reptext = p_text.
gs_fcat
-edit = p_edit.
gs_fcat
-no_zero = p_zero.
gs_fcat
-datatype = p_type.
gs_fcat
-qfieldname = p_qfieldname.
gs_fcat
-key = p_key.
gs_fcat
-hotspot = p_hotspot.
gs_fcat
-emphasize = p_emphasize.
gs_fcat
-checkbox = p_checkbox.
gs_fcat
-do_sum = p_do_sum.
gs_fcat
-decimals_o = p_decimals_out.
gs_fcat
-no_out = p_no_out.
gs_fcat
-f4availabl = p_f4availabl.
gs_fcat
-ref_table = p_ref_table.
gs_fcat
-ref_field = p_ref_field.
gs_fcat
-inttype = p_inttype.
gs_fcat
-datatype = p_datatype.
APPEND gs_fcat TO gt_fcat.
ENDFORM. "csalv_set_fcat
FORM show_alv TABLES pt_fcat
pt_tab
USING ps_layout.
gs_grid
-edt_cll_cb = ‘X‘."当屏幕失去焦点时,自动刷新
gt_event
-name = ‘CALLER_EXIT‘. "slis_ev_caller_exit_at_start事件
gt_event
-form = ‘FM_BUTTON‘.
APPEND gt_event .
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC‘
EXPORTING
i_callback_program
= sy-repid
i_callback_user_command
= ‘USER_COMMAND‘
i_grid_settings
= gs_grid
i_callback_pf_status_set
= ‘SET_PF_STATUS‘
is_layout_lvc
= ps_layout
it_fieldcat_lvc
= pt_fcat[]
it_events
= gt_event[]
* it_event_exit = gt_event_exit[]
TABLES
t_outtab
= pt_tab
EXCEPTIONS
program_error
= 1
OTHERS = 2.
ENDFORM. "csalv_set_fcat
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield
TYPE slis_selfield.
CASE r_ucomm.
WHEN ‘&CHANGE‘.
IF edit EQ ‘‘ .
edit = ‘X‘.
ELSE.
edit = ‘‘.
ENDIF.
PERFORM show_changed_alv.
WHEN ‘&BACK‘.
LEAVE PROGRAM.
WHEN ‘&ADD_ROW‘.
* CLEAR wa_zz.
* DATA:end TYPE i.
* DESCRIBE TABLE gt_zz LINES end.
*
* READ TABLE gt_zz INDEX end INTO wa_zz.
* IF wa_zz-vkbur IS INITIAL AND gt_zz is NOT INITIAL .
* MESSAGE i001(00) WITH ‘不能继续添加行!‘.
* exit.
* ENDIF.
"edit = ‘‘.
CLEAR wa_zz.
IF edit EQ ‘X‘.
wa_zz
-meins = ‘KM‘.
APPEND wa_zz TO gt_zz.
"PERFORM show_changed_alv.
PERFORM show_data_to_alv.
ENDIF.
WHEN ‘&SAVE_DATA‘.
DATA:lt_ztmm002 TYPE TABLE OF ztmm002.
DATA:wa_ztmm002 TYPE ztmm002.
CLEAR wa_ztmm002.
DELETE FROM ztmm002 .
MOVE-CORRESPONDING gt_zz TO lt_ztmm002.
IF lt_ztmm002 IS NOT INITIAL.
LOOP AT lt_ztmm002 INTO wa_ztmm002 .
IF wa_ztmm002-lifnr IS NOT INITIAL AND wa_ztmm002-werks IS NOT INITIAL.
INSERT INTO ztmm002 VALUES wa_ztmm002 .
ENDIF.
ENDLOOP.
"MODIFY ztmm002 FROM TABLE lt_ztmm002.
ENDIF.
IF sy-subrc EQ 0.
MESSAGE i001(00) WITH ‘保存成功!‘.
ELSE.
MESSAGE i001(00) WITH ‘保存失败!‘.
ENDIF.
WHEN ‘&DELE_ROW‘.
DATA:ls_row TYPE lvc_s_row,
lt_rows
TYPE lvc_t_row.
DATA:del_rows TYPE STANDARD TABLE OF ty_tab.
CALL METHOD ref_grid->get_selected_rows
IMPORTING
et_index_rows
= lt_rows
* et_row_no =
.
CLEAR wa_zz.
LOOP AT lt_rows INTO ls_row.
READ TABLE gt_zz INTO wa_zz INDEX ls_row-index.
"delete gt_zz INDEX ls_row-index.
"DELETE ztmm002 FROM wa_zz.
APPEND wa_zz TO del_rows.
ENDLOOP.
LOOP AT del_rows INTO wa_zz.
DELETE TABLE gt_zz FROM wa_zz.
ENDLOOP.
CLEAR del_rows.
CLEAR ls_row.
CLEAR lt_rows.
PERFORM show_changed_alv.
WHEN ‘&IN‘.
DATA: filepath LIKE rlgrap-filename.
PERFORM set_file_path CHANGING filepath.
PERFORM frm_upload_from_excel USING filepath.
PERFORM show_changed_alv.
ENDCASE.
ENDFORM.
FORM set_pf_status USING rt_extab TYPE slis_t_extab..
SET PF-STATUS ‘STANDARD‘.
ENDFORM. "SET_PF_STATUS
FORM fm_button USING e_grid TYPE slis_data_caller_exit.
DATA: lt_f4 TYPE lvc_t_f4,
ls_f4
TYPE lvc_s_f4.
CALL FUNCTION ‘GET_GLOBALS_FROM_SLVC_FULLSCR‘
* EXPORTING
* IR_SALV_FULLSCREEN_ADAPTER =
IMPORTING
* ET_EXCLUDING =
* E_REPID =
* E_CALLBACK_PROGRAM =
* E_CALLBACK_ROUTINE =
e_grid
= ref_grid
* ET_FIELDCAT_LVC =
* ER_TRACE =
* E_FLG_NO_HTML =
* ES_LAYOUT_KKBLO =
* ES_SEL_HIDE =
* ET_EVENT_EXIT =
* ER_FORM_TOL =
* ER_FORM_EOL =
.
* CALL METHOD ref_grid->check_changed_data.
* 设置enter事件
CALL METHOD ref_grid->register_edit_event
EXPORTING
i_event_id
= cl_gui_alv_grid=>mc_evt_enter
EXCEPTIONS
error
= 1
OTHERS = 2.
CREATE OBJECT gt_event_receiver.
SET HANDLER gt_event_receiver->handle_modify FOR ref_grid.
SET HANDLER gt_event_receiver->data_changed FOR ref_grid.
ENDFORM.
FORM frm_upload_from_excel USING p_pa_fname LIKE rlgrap-filename.
TYPES: BEGIN OF ty_tmp,
lifnr
LIKE ztmm002-lifnr,
lifnr_name
LIKE lfa1-name1,
werks
LIKE ztmm002-werks,
werks_name
LIKE t001w-name1,
menge
LIKE ztmm002-menge,
meins
LIKE ztmm002-meins,
END OF ty_tmp.
DATA: git_xls TYPE TABLE OF ty_tmp WITH HEADER LINE,
gwa_xls
TYPE ty_tmp.
**数据从EXCEL导入程序
DATA: l_exception TYPE REF TO cx_root.
DATA: lit_intern TYPE alsmex_tabline OCCURS 0 WITH HEADER LINE,
l_index
TYPE i,
l_no
TYPE i.
DATA: ls_style TYPE lvc_s_styl.
FIELD-SYMBOLS: <f>.
CHECK p_pa_fname IS NOT INITIAL.
REFRESH: git_xls.
CALL FUNCTION ‘ALSM_EXCEL_TO_INTERNAL_TABLE‘
EXPORTING
filename
= p_pa_fname
i_begin_col
= 1
i_begin_row
= 2
i_end_col
= 6
i_end_row
= 30000
TABLES
intern
= lit_intern
EXCEPTIONS
inconsistent_parameters
= 1
upload_ole
= 2
OTHERS = 3.
IF sy-subrc = 0.
l_no
= 0.
LOOP AT lit_intern.
MOVE lit_intern-col TO l_index.
ASSIGN COMPONENT l_index OF STRUCTURE gwa_xls TO <f>.
TRY.
MOVE lit_intern-value TO <f>.
CATCH cx_root INTO l_exception.
* gwa_xls-err_info = l_exception->get_text( ).
* gwa_xls-status = icon_led_red.
ENDTRY.
AT END OF row.
ADD 1 TO l_no.
"gwa_xls-no = l_no.
APPEND gwa_xls TO git_xls.
CLEAR gwa_xls.
ENDAT.
ENDLOOP.
ENDIF.
LOOP AT git_xls INTO gwa_xls.
MOVE-CORRESPONDING gwa_xls TO wa_zz.
CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘
EXPORTING
input = wa_zz-lifnr
IMPORTING
output = wa_zz-lifnr.
SELECT SINGLE name1 INTO wa_zz-lifnr_name
FROM lfa1 WHERE lifnr EQ wa_zz-lifnr.
CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT‘
EXPORTING
input = wa_zz-werks
IMPORTING
output = wa_zz-werks.
SELECT SINGLE name1 INTO wa_zz-werks_name
FROM t001w WHERE werks EQ wa_zz-werks.
APPEND wa_zz TO gt_zz.
CLEAR wa_zz.
ENDLOOP.
ENDFORM.
FORM set_file_path CHANGING filepath LIKE rlgrap-filename.
FIELD-SYMBOLS: <f> TYPE file_table .
DATA: gd_path TYPE string.
DATA: it_tab TYPE filetable,
gd_subrc
TYPE i.
DATA: ld_filename TYPE string,
ld_path
TYPE string,
ld_fullpath
TYPE string,
ld_result
TYPE i,
gd_file
TYPE c.
DATA:"filepath LIKE rlgrap-filename,
openfile
LIKE rlgrap-filename.
* CALL METHOD cl_gui_frontend_services=>directory_browse
* EXPORTING
* window_title = ‘文件路径选择‘
* initial_folder = ‘C:‘
* CHANGING
* selected_folder = gd_path.
* CALL METHOD cl_gui_cfw=>flush.
* CONCATENATE gd_path ‘‘ INTO filepath.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title
= ‘Select File‘
default_filename
= ‘供应商工厂对应公里数模板.XLS‘
multiselection
= ‘X‘
CHANGING
file_table
= it_tab
rc
= gd_subrc.
* LOOP AT it_tab INTO openfile-low.
* openfile-sign = ‘I‘.
* openfile-option = ‘EQ‘.
* APPEND openfile.
* ENDLOOP.
CALL METHOD cl_gui_cfw=>flush.
READ TABLE it_tab ASSIGNING <f> INDEX 1.
IF sy-subrc EQ 0.
filepath
= <f>-filename.
ENDIF.
*CALL METHOD cl_gui_frontend_services=>file_save_dialog
* EXPORTING
* default_extension = ‘XLS‘
* default_file_name = ‘产品出库单‘
* initial_directory = ‘c:/temp/‘
* CHANGING
* filename = ld_filename
* path = filepath
* fullpath = ld_fullpath
* user_action = ld_result.
ENDFORM.
FORM frm_path_selected CHANGING filepath LIKE rlgrap-filename.
DATA: gd_path TYPE string.
DATA: it_tab TYPE filetable,
gd_subrc
TYPE i.
DATA: ld_filename TYPE string,
ld_path
TYPE string,
ld_fullpath
TYPE string,
ld_result
TYPE i,
gd_file
TYPE c.
DATA:"filepath LIKE rlgrap-filename,
openfile
LIKE rlgrap-filename.
CALL METHOD cl_gui_frontend_services=>directory_browse
EXPORTING
window_title
= ‘文件路径选择‘
initial_folder
= ‘C:‘
CHANGING
selected_folder
= gd_path.
CALL METHOD cl_gui_cfw=>flush.
CONCATENATE gd_path ‘‘ INTO filepath.
ENDFORM.
FORM frm_download_template USING c_path .
DATA: lv_objdata LIKE wwwdatatab,
lv_obj_name
LIKE wwwdatatab-objid,
lv_destination
LIKE rlgrap-filename,
lv_objid
LIKE sy-repid,
lv_subrc
LIKE sy-subrc.
DATA:l_ret TYPE abap_bool, lv_answer
.
DATA:lv_file TYPE string.
MOVE c_path TO lv_file.
CALL METHOD cl_gui_frontend_services=>file_exist
EXPORTING
file
= lv_file
RECEIVING
result
= l_ret
EXCEPTIONS
cntl_error
= 1
error_no_gui
= 2
wrong_parameter
= 3
not_supported_by_gui
= 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT.
ENDIF.
IF l_ret EQ ‘X‘.
* 模版已存在,是否覆盖
CALL FUNCTION ‘POPUP_TO_CONFIRM‘
EXPORTING
text_question
= ‘模版已存在,是否覆盖?‘
text_button_1
= ‘是‘(001)
text_button_2
= ‘否‘(002)
IMPORTING
answer
= lv_answer
EXCEPTIONS
text_not_found
= 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
IF lv_answer EQ ‘A‘. "取消
EXIT.
ELSEIF lv_answer NE ‘1‘. "否
"p_filepath = c_path.
ENDIF.
ELSE.
lv_answer
= ‘1‘.
ENDIF.
CREATE OBJECT excel ‘EXCEL.APPLICATION‘.
GET PROPERTY OF excel ‘Workbooks‘ = workbook .
CALL METHOD OF workbook
‘Close‘.
IF lv_answer EQ ‘1‘.
MOVE ‘ZMM_XLS_002‘ TO lv_obj_name."引用传入到服务器中xls模板
SELECT relid objid
FROM wwwdata
INTO CORRESPONDING FIELDS OF lv_objdata
UP TO 1 ROWS
WHERE srtf2 = 0 AND relid = ‘MI‘
AND objid = lv_obj_name.
ENDSELECT.
CALL FUNCTION ‘DOWNLOAD_WEB_OBJECT‘
EXPORTING
key = lv_objdata
destination
= c_path
IMPORTING
rc
= lv_subrc.
* IF lv_subrc = 0.
* p_filepath = c_path.
* ENDIF.
ENDIF.
* CALL METHOD OF
* g_workbook
* ‘open‘
*
* EXPORTING
* #1 = c_path.
*
* CALL METHOD OF
* g_excel
* ‘worksheets‘ = g_sheet
* EXPORTING
* #1 = 1.
* CALL METHOD OF
* g_sheet
* ‘activate‘.
"SET PROPERTY OF g_excel ‘visible‘ = 0.
FREE OBJECT sheet.
"FREE OBJECT g_applica.
FREE OBJECT workbook.
FREE OBJECT excel.
ENDFORM. "frm_download_template