*&---------------------------------------------------------------------*
*& Report ZHRROFFICETEMPLATE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZHRROFFICETEMPLATE.
tables: zhr_office.
*AVL控制需要的结构
type-pools: slis.
constants : gc_charx value 'X' .
data: gt_fieldcat type slis_t_fieldcat_alv .
data: alv_program like sy-repid.
data: alv_events type slis_t_event.
data: alv_event_exit type slis_t_event_exit.
data: alv_layout type slis_layout_alv.
data: g_colpos(2) type n.
data alv_print type slis_print_alv.
data itab_line type zhr_office.
data itab like itab_line occurs 0 with header line.
start-of-selection.
*读取数据到内表中
perform getdata.
end-of-selection.
*在ALV控制中显示内表数据
g_colpos = '2'.
perform set_fieldcat using gt_fieldcat.
*alv_layout-edit = gc_charx.
*alv_layout-edit_mode = 'A'.
alv_layout-get_selinfos = gc_charx.
*自动设置列宽
alv_layout-colwidth_optimize = gc_charx. " space .
alv_layout-detail_popup = gc_charx.
* alv_layout-box_tabname = ''. "pi_box_tabname.
* alv_layout-box_fieldname = 'MARK'. "pi_box_fieldname.
alv_layout-no_keyfix = gc_charx.
alv_layout-key_hotspot = gc_charx.
alv_layout-group_change_edit = gc_charx.
alv_layout-totals_before_items = gc_charx.
alv_layout-reprep = gc_charx.
alv_print-no_coverpage = 'X'.
alv_print-no_print_listinfos = 'X'.
alv_print-no_change_print_params = space.
alv_print-no_print_listinfos = 'X'.
alv_print-no_print_selinfos = 'X'.
alv_print-no_print_hierseq_item = 'X'.
perform set_layout using alv_layout.
perform reuse_alv_events tables alv_events
using alv_program.
perform reuse_events_exit tables alv_event_exit.
perform displayalv.
*---------------------------------------------------------------------*
* FORM DISPLAYALV *
*---------------------------------------------------------------------*
* 显示alv表 *
*---------------------------------------------------------------------*
form displayalv.
SORT itab by SRTFD.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_bypassing_buffer = 'X'
i_buffer_active = 'X'
* TOP_OF_PAGE事件处理 可以写页头
i_callback_top_of_page = 'COMMENT_BUILD'
i_callback_html_top_of_page = 'HTML_TOP_OF_PAGE'
* 自定义状态
i_callback_pf_status_set = 'SET_STATUS'
* 自定义程序处理函数
i_callback_user_command = 'USER_COMMAND'
* 指明处理函数所在的Form
i_callback_program = alv_program
* I_STRUCTURE_NAME = '有余数的订单'
* 设置显示布局
is_layout = alv_layout
* 设置列格式
it_fieldcat = gt_fieldcat[]
* 设置非激活的功能码
* it_excluding = gs_sd_alv-excluding
* it_special_groups = gs_sd_alv-special_groups
* 设置排序字段
* IT_SORT = GS_SD_ALV-SORT
* 设置过滤字段
* IT_FILTER = GS_SD_ALV-FILTER
* is_sel_hide = gs_sd_alv-sel_hide
* 允许激活VARIANT功能
i_default = 'X'
* i_save = gs_sd_alv-save
* 设置变式
* is_variant = gs_sd_alv-variant
* 设置事件处理函数
it_events = alv_events
it_event_exit = alv_event_exit
* 设置打印机参数
is_print = alv_print
tables
t_outtab = itab .
endform. "displayalv
*---------------------------------------------------------------------*
* FORM write_fieldcat_top *
*---------------------------------------------------------------------*
* 写字段说明 *
*---------------------------------------------------------------------*
form write_fieldcat_top using fieldcat type slis_fieldcat_alv
fieldname
seltext_s.
fieldcat-tabname = 'ITAB'.
fieldcat-fieldname = fieldname.
fieldcat-seltext_s = seltext_s.
fieldcat-seltext_m = seltext_s.
fieldcat-seltext_l = seltext_s.
* fieldcat-ddictxt = 'L'.
fieldcat-col_pos = g_colpos.
fieldcat-outputlen = 100.
g_colpos = g_colpos + 1.
endform. "write_fieldcat_top
*---------------------------------------------------------------------*
* FORM write_fieldcat *
*---------------------------------------------------------------------*
* 写字段说明 *
*---------------------------------------------------------------------*
form write_fieldcat using p_fieldcat type slis_t_fieldcat_alv
fieldname
seltext_s.
data: fieldcat type slis_fieldcat_alv.
clear fieldcat.
perform write_fieldcat_top using fieldcat fieldname seltext_s.
append fieldcat to p_fieldcat.
endform. "write_fieldcat
*---------------------------------------------------------------------*
* FORM write_fieldcat_kunnr *
*---------------------------------------------------------------------*
* 写字段说明 *
*---------------------------------------------------------------------*
*FORM write_fieldcat_kunnr USING p_fieldcat TYPE slis_t_fieldcat_alv
* fieldname
* seltext_s.
* PERFORM write_fieldcat_ref USING p_fieldcat fieldname seltext_s 'KNA1'
* 'KUNNR'.
*ENDFORM. "write_fieldcat_kunnr
*&---------------------------------------------------------------------*
*& Form write_fieldcat_dh
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_FIELDCAT text
* -->FIELDNAME text
* -->SELTEXT_S text
*----------------------------------------------------------------------*
*FORM write_fieldcat_dh USING p_fieldcat TYPE slis_t_fieldcat_alv
* fieldname
* seltext_s.
* PERFORM write_fieldcat_ref USING p_fieldcat fieldname seltext_s 'VBAK'
* 'VBELN'.
*ENDFORM. "write_fieldcat_dh
*&---------------------------------------------------------------------*
*& Form write_fieldcat_sl
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_FIELDCAT text
* -->FIELDNAME text
* -->SELTEXT_S text
*----------------------------------------------------------------------*
*FORM write_fieldcat_sl USING p_fieldcat TYPE slis_t_fieldcat_alv
* fieldname
* seltext_s.
* PERFORM write_fieldcat_ref USING p_fieldcat fieldname seltext_s 'ZJNSD'
* 'DDSL'.
*ENDFORM. "write_fieldcat_sl
*---------------------------------------------------------------------*
* FORM write_fieldcat_type *
*---------------------------------------------------------------------*
* 写字段说明 *
*---------------------------------------------------------------------*
*FORM write_fieldcat_type USING p_fieldcat TYPE slis_t_fieldcat_alv
* fieldname
* seltext_s
* rname.
* DATA: fieldcat TYPE slis_fieldcat_alv.
* CLEAR fieldcat.
* PERFORM write_fieldcat_top USING fieldcat fieldname seltext_s.
* fieldcat-rollname = rname.
* APPEND fieldcat TO p_fieldcat.
*ENDFORM. "write_fieldcat_type
*---------------------------------------------------------------------*
* FORM write_fieldcat_ref *
*---------------------------------------------------------------------*
* 写字段说明 *
*---------------------------------------------------------------------*
form write_fieldcat_ref using p_fieldcat type slis_t_fieldcat_alv
fieldname
seltext_s
tbname
fdname.
data: fieldcat type slis_fieldcat_alv.
clear fieldcat.
perform write_fieldcat_top using fieldcat fieldname seltext_s.
fieldcat-ref_tabname = tbname.
fieldcat-ref_fieldname = fdname.
fieldcat-reptext_ddic = seltext_s.
append fieldcat to p_fieldcat.
endform. "write_fieldcat_ref
*---------------------------------------------------------------------*
* FORM write_fieldcat *
*---------------------------------------------------------------------*
* 写可编辑字段说明 *
*---------------------------------------------------------------------*
*FORM write_fieldcat_edit USING p_fieldcat TYPE slis_t_fieldcat_alv
* fieldname
* seltext_s.
* DATA: fieldcat TYPE slis_fieldcat_alv.
* CLEAR fieldcat.
* fieldcat-tabname = 'ITAB'.
* fieldcat-fieldname = fieldname.
* fieldcat-seltext_s = seltext_s.
* fieldcat-col_pos = g_colpos.
* fieldcat-input = gc_charx.
* fieldcat-edit = gc_charx.
* APPEND fieldcat TO p_fieldcat.
* g_colpos = g_colpos + 1.
*ENDFORM. "write_fieldcat_edit
*&---------------------------------------------------------------------*
*& Form REUSE_ALV_EVENTS
*&---------------------------------------------------------------------*
* 赋定制事件的值
*----------------------------------------------------------------------*
form reuse_alv_events tables pt_events type slis_t_event
using pe_program like sy-repid.
pt_events-form = pt_events-name = 'COMMENT_BUILD'.
append pt_events.
pt_events-form = pt_events-name = 'USER_COMMAND'.
append pt_events.
pe_program = sy-repid.
endform. "reuse_alv_events
*&---------------------------------------------------------------------*
*& Form REUSE_EVENTS_EXIT
*&---------------------------------------------------------------------*
* 退出事件
*----------------------------------------------------------------------*
form reuse_events_exit tables pt_events_exit type slis_t_event_exit.
clear pt_events_exit.
pt_events_exit-ucomm = '&IC1'.
pt_events_exit-after = gc_charx.
append pt_events_exit.
clear pt_events_exit.
pt_events_exit-ucomm = '&REFRESH'.
pt_events_exit-after = gc_charx.
append pt_events_exit.
endform . "reuse_events_exit
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
* 管理定制事件
*----------------------------------------------------------------------*
form user_command using i_ucomm like sy-ucomm
es_selfield type slis_selfield.
es_selfield-refresh = 'X'.
case i_ucomm.
when '&REFRESH'.
perform getdata.
when others.
perform alv_command using i_ucomm es_selfield.
perform getdata.
endcase.
endform . "user_command
*&---------------------------------------------------------------------*
*& Form COMMENT_BUILD
*&---------------------------------------------------------------------*
* 显示列标题
*----------------------------------------------------------------------*
form comment_build .
data: ls_line type slis_listheader.
data: grid_top_of_page type slis_t_listheader.
data: linfo type slis_listheader-info.
data: rq_low like sy-datum.
data: rq_high like sy-datum.
data: rq(14),rq1(14).
perform alv_top_page_title using linfo.
refresh grid_top_of_page.
clear ls_line.
ls_line-typ = 'H'.
ls_line-info = linfo.
append ls_line to grid_top_of_page.
perform alv_top_page_rq using rq_low rq_high.
if not ( rq_low is initial ).
clear ls_line.
ls_line-typ = 'S'.
ls_line-key = text-002. "'日期范围:'
concatenate rq_low+0(4) text-003 rq_low+4(2) text-004 rq_low+6(2) text-005 into rq.
concatenate rq_high+0(4) text-003 rq_high+4(2) text-004 rq_high+6(2) text-005 into rq1.
concatenate rq text-006 rq1 into ls_line-info.
append ls_line to grid_top_of_page.
endif.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = grid_top_of_page.
endform. " COMMENT_BUILD
*&---------------------------------------------------------------------
*& Form SET_LAYOUT
*&---------------------------------------------------------------------
* 设置ALV的布局,主要设置窗口标题
*----------------------------------------------------------------------
form set_layout using alv_layout type slis_layout_alv.
alv_layout-window_titlebar = text-001. "'OFFICE模板维护程序'
endform. "set_layout
*&---------------------------------------------------------------------
*& Form set_fieldcat
*&---------------------------------------------------------------------
* 设置ALV的列标题
*----------------------------------------------------------------------
form set_fieldcat using t_fieldcat type slis_t_fieldcat_alv.
perform write_fieldcat using t_fieldcat 'SRTFD' text-010. " '关键字'
perform write_fieldcat using t_fieldcat 'FILEDESC' text-011. "'描述'
perform write_fieldcat using t_fieldcat 'FILENAME' text-012. "'文件名'.
perform write_fieldcat using t_fieldcat 'AEDAT' text-013. "'修改日期'.
perform write_fieldcat using t_fieldcat 'USERA' text-014. "'修改人'.
endform. "set_fieldcat
*&-------------------------------------------------------------------
*
*& Form set_status
*&-------------------------------------------------------------------
* 设置状态
*--------------------------------------------------------------------
form set_status using extab type slis_t_extab.
set pf-status 'STANDARD_FULLSCREEN'.
endform . "set_status
*---------------------------------------------------------------------*
* FORM alv_top_page_title *
*---------------------------------------------------------------------*
* 设置标题头 *
*---------------------------------------------------------------------*
form alv_top_page_title using linfo type slis_listheader-info.
linfo = 'OFFICE模板维护程序'.
endform. "alv_top_page_title
*---------------------------------------------------------------------*
* FORM alv_top_page_rq *
*---------------------------------------------------------------------*
* 设置标题中的日期范围 *
*---------------------------------------------------------------------*
form alv_top_page_rq using rq_low type sy-datum
rq_high type sy-datum.
endform. "alv_top_page_rq
*&---------------------------------------------------------------------
*& Form alv_COMMAND
*&---------------------------------------------------------------------
* 自定义管理定制事件
*----------------------------------------------------------------------
form alv_command using i_ucomm like sy-ucomm
es_selfield type slis_selfield.
read table itab index es_selfield-tabindex.
data answer .
case i_ucomm.
when 'DOWN'.
if es_selfield-tabindex <> 0.
perform download(zhrrofficetemplateupload) using itab-srtfd.
else.
call function 'POPUP_TO_DISPLAY_TEXT'
exporting
titel = text-021 "'下载文件'
textline1 = text-022 "'请选择一个模版!'
exceptions
others = 1.
endif.
when 'DELE'.
if es_selfield-tabindex <> 0.
call function 'POPUP_TO_CONFIRM'
exporting
titlebar = text-007 "'确认'
text_question = text-008 "'你确实要删除这个文件吗?'
text_button_1 = text-009 "'确定'
text_button_2 = text-020 "'取消'
default_button = '2'
display_cancel_button = ' '
start_column = 10
start_row = 6
importing
answer = answer.
if answer = '1'.
delete from database zhr_office(cn) id itab-srtfd.
endif.
else.
call function 'POPUP_TO_DISPLAY_TEXT'
exporting
titel = text-023 "'删除文件'
textline1 = text-022 "'请选择一个文件!'
exceptions
others = 1.
endif.
when 'UPLOAD'.
submit zhrrofficetemplateupload via selection-screen and return.
when 'UPDATE'.
if es_selfield-tabindex <> 0.
submit zhrrofficetemplateupload with srtfd eq itab-srtfd
with filedesc eq itab-filedesc
via selection-screen and return.
else.
call function 'POPUP_TO_DISPLAY_TEXT'
exporting
titel = text-024 "'更新文件'
textline1 = text-022 "'请选择一个文件!'
exceptions
others = 1.
endif.
endcase.
endform . "alv_command
*&---------------------------------------------------------------------*
*& Form getdata
*&---------------------------------------------------------------------*
* 得到数据
*----------------------------------------------------------------------*
form getdata.
select distinct srtfd aedat usera filename filedesc
into corresponding fields of table itab from zhr_office
where relid = 'CN'.
sort itab by srtfd.
endform. " getdata