REPORT Z1.
REPORT zsbxc_fi_0014.
TABLES:sscrfields.
*&---------------------------------------------------------------------*
*& 定义结构、内表、工作区
*&---------------------------------------------------------------------*
TYPES:BEGIN OF ty_upload,
box TYPE C, "选择框
light TYPE char4, "状态灯
mesg TYPE char200,
END OF ty_upload.
TYPES:BEGIN OF ty_alv,
box TYPE C, "选择框
light TYPE char4, "状态灯
mesg TYPE char200,
END OF ty_alv.
DATA:gt_fieldcat TYPE lvc_t_fcat,
gs_fieldcat TYPE lvc_s_fcat,
gs_layout TYPE lvc_s_layo.
DATA:gt_excel TYPE alsmex_tabline OCCURS 0 WITH HEADER LINE,
gs_excel TYPE alsmex_tabline.
DATA:gt_upload TYPE STANDARD TABLE OF ty_upload WITH HEADER LINE,
gs_upload TYPE ty_upload.
DATA:gt_alv TYPE TABLE OF ty_alv,
gs_alv TYPE ty_alv.
*&---------------------------------------------------------------------*
*& 按钮
*&---------------------------------------------------------------------*
DATA:functxt TYPE smp_dyntxt.
DATA:p_down TYPE rlgrap-filename.
*&---------------------------------------------------------------------*
*& 屏幕
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK bk1 WITH FRAME TITLE TEXT-001.
PARAMETERS:p_file LIKE rlgrap-filename MODIF ID m1. "文件
SELECTION-SCREEN END OF BLOCK bk1.
SELECTION-SCREEN: FUNCTION KEY 1.
*&---------------------------------------------------------------------*
*& 初始化
*&---------------------------------------------------------------------*
INITIALIZATION.
MOVE '@49@模板下载' TO sscrfields-functxt_01.
AT SELECTION-SCREEN OUTPUT.
AT SELECTION-SCREEN.
CASE sscrfields-ucomm.
WHEN 'FC01'.
PERFORM frm_get_filepath.
PERFORM frm_file_down. "下载模板
WHEN OTHERS.
...
ENDCASE.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM frm_bro_form. "选择文件
START-OF-SELECTION.
PERFORM frm_upload_data."解析上传的EXCEL文件
PERFORM frm_deal_data."处理导入的数据
PERFORM frm_alv_display.
*&---------------------------------------------------------------------*
*& Form frm_get_filepath
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_get_filepath .
DATA: it_file TYPE filetable,
wa_file TYPE file_table,
p_type TYPE C VALUE 'A'.
DATA:l_rc TYPE I,
l_extension TYPE string,
l_default TYPE string,
l_filter TYPE string,
l_filename TYPE string,
l_path TYPE string,
l_fullpath TYPE string,
l_action TYPE I.
CLEAR:p_down.
l_filter = 'Excel Files (*.xls)|*.xls|'.
l_extension = '*.xls,*.*'. "
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
window_title = '选择文件'
default_extension = l_extension
default_file_name = '统计指标批量录入模板'
file_filter = l_filter
initial_directory = 'D:\'
CHANGING
filename = l_filename
path = l_path
fullpath = l_fullpath
user_action = l_action
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
IF sy-subrc = 0.
p_down = l_fullpath.
ENDIF.
IF l_action <> 0.
STOP.
ENDIF.
ENDFORM. " frm_get_filepath
*&---------------------------------------------------------------------*
*& Form frm_file_down
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_file_down .
DATA: lv_objdata LIKE wwwdatatab,
lv_mime LIKE w3mime,
lv_destination LIKE rlgrap-filename,
lv_objnam TYPE string,
lv_rc LIKE sy-subrc,
lv_errtxt TYPE string.
DATA: lv_filename TYPE string,
lv_result,
lv_subrc TYPE sy-subrc.
DATA: lv_objid TYPE wwwdatatab-objid .
lv_objid = 'ZTJZB'. "上传的模版名称
*&---查找文件是否存在。
SELECT SINGLE relid objid
FROM wwwdata
INTO CORRESPONDING FIELDS OF lv_objdata
WHERE srtf2 = 0
AND relid = 'MI'
AND objid = lv_objid.
*&---判断模版不存在则报错
IF sy-subrc NE 0 OR lv_objdata-objid EQ space.
CONCATENATE '模板文件:' lv_objid '不存在,请用TCODE:SMW0进行加载' INTO lv_errtxt.
MESSAGE lv_errtxt TYPE 'E'.
ENDIF.
lv_destination = p_down.
CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
EXPORTING
KEY = lv_objdata
destination = lv_destination
IMPORTING
rc = lv_rc.
IF lv_rc NE 0.
MESSAGE '模板文件下载失败' TYPE 'E'.
ENDIF.
ENDFORM. " frm_file_down
*&---------------------------------------------------------------------*
*& Form FRM_BRO_FORM
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_bro_form .
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
MASK = ',Excel Files,*.XLS,All Files,*.*.'
TITLE = '选择上传文件'
IMPORTING
filename = p_file
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.
IF sy-subrc <> 0 AND sy-subrc <> 3.
MESSAGE '选择文件出错!' TYPE 'E'.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_upload_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_upload_data .
DATA: begin_row TYPE I VALUE '2',
begin_col TYPE I VALUE '1',
end_row TYPE I VALUE '9999',
end_col TYPE I VALUE '8'.
DATA: g_row TYPE I.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file
i_begin_col = begin_col "列
i_begin_row = begin_row "行
i_end_col = end_col
i_end_row = end_row
TABLES
intern = gt_excel.
IF gt_excel[] IS INITIAL.
MESSAGE '请填充数据 ' TYPE 'S' DISPLAY LIKE 'E' .
LEAVE LIST-PROCESSING .
ENDIF.
SORT gt_excel BY row col VALUE.
LOOP AT gt_excel INTO gs_excel.
ON CHANGE OF gs_excel-row.
IF sy-tabix NE 1.
APPEND gs_upload TO gt_upload.
CLEAR gs_upload.
ENDIF.
ENDON.
ASSIGN COMPONENT gs_excel-col OF STRUCTURE gs_upload TO FIELD-SYMBOL(<fs>).
IF <fs> IS ASSIGNED.
<fs> = gs_excel-VALUE.
UNASSIGN <fs>.
ENDIF.
ENDLOOP.
APPEND gs_upload TO gt_upload.
ENDFORM. " frm_upload_data
*&---------------------------------------------------------------------*
*& Form FRM_DEAL_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_deal_data .
MOVE-CORRESPONDING gt_upload[] TO gt_alv[].
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_ALV_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_alv_display .
DEFINE m_fieldcat.
gs_fieldcat-fieldname = &1.
gs_fieldcat-coltext = &2.
gs_fieldcat-ref_table = &3.
gs_fieldcat-ref_field = &4.
gs_fieldcat-no_zero = &5.
gs_fieldcat-EDIT = &6.
gs_fieldcat-CHECKBOX = &7.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
END-OF-DEFINITION.
m_fieldcat 'BOX' '选择框' '' '' '' 'X' 'X' .
gs_layout-zebra = 'X'. "颜色间隔
gs_layout-cwidth_opt = 'X'. "自适应宽度
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
it_fieldcat_lvc = gt_fieldcat
i_callback_pf_status_set = 'FRM_GUI_STATUS'
i_callback_user_command = 'FRM_USER_COMMAND'
i_callback_program = sy-repid
is_layout_lvc = gs_layout
i_save = 'A'
TABLES
t_outtab = gt_alv
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_gui_status
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PT_EXTAB text
*----------------------------------------------------------------------*
FORM frm_gui_status USING pt_extab TYPE slis_t_extab.
SET PF-STATUS 'STANDARD'. "gui状态
ENDFORM. "frm_gui_status
*&---------------------------------------------------------------------*
*& Form frm_user_command
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PV_UCOMM text
* -->PW_SELFIELD text
*----------------------------------------------------------------------*
FORM frm_user_command USING pv_ucomm LIKE sy-ucomm
pw_selfield TYPE slis_selfield.
DATA:lo_grid TYPE REF TO cl_gui_alv_grid.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = lo_grid. "获取全局变量
CALL METHOD lo_grid->check_changed_data.
pw_selfield-REFRESH = 'X'. "刷新界面
CASE pv_ucomm.
WHEN 'ALL'. "全选
PERFORM frm_all.
WHEN 'SAL'. "删除
PERFORM frm_sal.
WHEN OTHERS.
ENDCASE.
pw_selfield-REFRESH = 'X'. "刷新界面
ENDFORM. "frm_user_command
*&---------------------------------------------------------------------*
*& Form FRM_ALL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_all .
LOOP AT gt_alv ASSIGNING FIELD-SYMBOL(<fs_01>).
<fs_01>-box = 'X'.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_SAL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_sal .
LOOP AT gt_alv ASSIGNING FIELD-SYMBOL(<fs_02>).
<fs_02>-box = ''.
ENDLOOP.
ENDFORM.
上传下载模板
最新推荐文章于 2024-08-27 21:25:39 发布