alv 事件
alv定义按钮 http://wenku.baidu.com/view/2d65580bf78a6529647d539b.html
report test_alv_function . data:l_flag_modify type c value 'X'. types: begin of itype, matnr like mara-matnr, matkx like makt-maktx, vbeln like vbak-vbeln, field_style type lvc_t_styl,"可设定这一单元格的输入,输出属性 end of itype. data itab type table of itype with header line. type-pools: slis. data: * gt_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE, gt_fieldcat type lvc_t_fcat with header line, * gs_layout TYPE slis_layout_alv, gs_layout type lvc_s_layo, * gs_print TYPE slis_print_alv, "ALV打印格式 gs_print type lvc_s_prnt ,"occurs 0 with header line, "ALV打印格式 g_repid like sy-repid. data: v_stru_disvar type disvariant, "ALV 显示格式 * it_sort TYPE slis_t_sortinfo_alv WITH HEADER LINE, "ALV 排序内表 it_sort type lvc_t_sort with header line, "ALV 排序内表 git_events type slis_t_event, "ALV 事件 git_listheader type slis_t_listheader. "ALV 表头 data l_tmp type lvc_title. constants cns_pf_status type slis_formname value 'ALV_PF_STATUS'. constants cns_user_command type slis_formname value 'ALV_USER_COMMAND'. data: gt_filtter type lvc_t_fcat with header line. data tem_grid type ref to cl_gui_alv_grid. *----------------------------------------------------------------------* * CLASS LCL_EVENT_RECEIVER DEFINITION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* 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 handle_data_changed for event data_changed of cl_gui_alv_grid importing er_data_changed e_onf4 e_onf4_before e_onf4_after e_ucomm. endclass. "LCL_EVENT_RECEIVER DEFINITION *----------------------------------------------------------------------* * CLASS LCL_EVENT_RECEIVER IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* class lcl_event_receiver implementation. method handle_modify. data stbl type lvc_s_stbl. perform frm_refresh_data. * 稳定刷新 stbl-row = 'X'." 基于行的稳定刷新 stbl-col = 'X'." 基于列稳定刷新 call method tem_grid->refresh_table_display exporting is_stable = stbl. endmethod. "HANDLE_MODIFY method handle_data_changed. data stbl type lvc_s_stbl. perform handle_data_changed using er_data_changed. "处理受变化的数据 * 稳定刷新 stbl-row = 'X'." 基于行的稳定刷新 stbl-col = 'X'." 基于列稳定刷新 call method tem_grid->refresh_table_display exporting is_stable = stbl. endmethod. "HANDLE_MODIFY endclass. "LCL_EVENT_RECEIVER IMPLEMENTATION data gt_event_receiver type ref to lcl_event_receiver . *&---------------------------------------------------------------------* *& 宏定义 *&---------------------------------------------------------------------* define init_fieldcat. " ALV Fieldcat设置 gt_fieldcat-fieldname = &1. gt_fieldcat-reptext = &2. gt_fieldcat-outputlen = &3. if &4 = 'X'. gt_fieldcat-no_zero = 'X'. endif. gt_fieldcat-checkbox = &5. if l_flag_modify is initial. gt_fieldcat-edit = ''. * gt_fieldcat-key = 'X'. else. gt_fieldcat-edit = &6. endif. * if &6 is initial. * gt_fieldcat-key = 'X'. * endif. gt_fieldcat-fix_column = &7. append gt_fieldcat. clear gt_fieldcat. end-of-definition. *&---------------------------------------------------------------------* *& start of selection *&---------------------------------------------------------------------* start-of-selection. break-point. perform frm_get_data. *&---------------------------------------------------------------------* *& end-of-selection *&---------------------------------------------------------------------* end-of-selection. perform frm_comment_build. "设置表头 perform frm_get_event. "设置自定义事件处理程序 perform init_layout. "设置输出格式 perform init_fieldcat. "设置输出字段 perform init_sort. "设置排序、合计 perform init_print. "设置打印 perform frm_output. "输出 . *&---------------------------------------------------------------------* *& Form FRM_COMMENT_BUILD *&---------------------------------------------------------------------* form frm_comment_build . *ALV表头 data l_listheader type slis_listheader. data: v_title(60). clear: git_listheader, l_listheader. l_listheader-typ = 'H'. v_title = 'ALV功能测试程式'. l_listheader-info = v_title. append l_listheader to git_listheader. endform. " FRM_COMMENT_BUILD *&---------------------------------------------------------------------* *& Form FRM_GET_EVENT *&---------------------------------------------------------------------* form frm_get_event . data formname_top_of_page type slis_formname value 'FRM_TOP_OF_PAGE'. data l_events type line of slis_t_event. call function 'REUSE_ALV_EVENTS_GET' exporting i_list_type = 0 importing et_events = git_events exceptions list_type_wrong = 1 others = 2. if sy-subrc <> 0. message id sy-msgid type sy-msgty number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. endif. * 修改TOP_OF_PAGE以加入表头,设置处理子程序为'FRM_TOP_OF_PAGE' clear l_events. read table git_events with key name = slis_ev_top_of_page into l_events. if sy-subrc = 0. move 'FRM_TOP_OF_PAGE' to l_events-form. modify git_events from l_events index sy-tabix. else. l_events-form = 'FRM_TOP_OF_PAGE'. l_events-name = slis_ev_top_of_page. append l_events to git_events. endif. l_events-name = 'CALLER_EXIT'. l_events-form = 'FM_BUTTON'. append l_events to git_events. endform. " FRM_GET_EVENT *&---------------------------------------------------------------------* *& Form FRM_TOP_OF_PAGE 表头 *&---------------------------------------------------------------------* form frm_top_of_page. call function 'REUSE_ALV_COMMENTARY_WRITE' exporting it_list_commentary = git_listheader. endform. "FRM_TOP_OF_PAGE *&---------------------------------------------------------------------* *& Form INIT_LAYOUT *&---------------------------------------------------------------------* form init_layout . gs_layout-zebra = 'X'. * gs_layout-f2code = '&ETA'. * gs_layout-detail_popup = 'X'. gs_layout-stylefname = 'FIELD_STYLE'. * gs_layout-edit = 'X'. * gs_layout-colwidth_optimize = 'X'. * GS_LAYOUT-TOTALS_ONLY = 'X'. endform. " INIT_LAYOUT *&---------------------------------------------------------------------* *& Form INIT_FIELDCAT *&---------------------------------------------------------------------* form init_fieldcat . init_fieldcat 'MATNR' '料号' 4 '' 'X' l_flag_modify 'X'. init_fieldcat 'MATKX' '料号说明' 13 'X' '' '' 'X'. init_fieldcat 'VBELN' '号码' 12 '' '' l_flag_modify ''. endform. " INIT_FIELDCAT *&---------------------------------------------------------------------* *& Form INIT_SORT *&---------------------------------------------------------------------* * ALV 排序 *----------------------------------------------------------------------* form init_sort . clear it_sort. it_sort-fieldname = 'MATNR'. "排序字段 it_sort-spos = 1. it_sort-up = 'X'. "升序 * it_sort-subtot = 'X'. "小计依据 append it_sort . endform. " INIT_SORT *&---------------------------------------------------------------------* *& Form INIT_PRINT *&---------------------------------------------------------------------* * ALV 打印 *----------------------------------------------------------------------* form init_print . * gs_print-no_print_listinfos = 'X'. "不打印汇总页 * gs_print-prnt_info = 'X'. "打印日期,程序标题和页号 endform. " INIT_PRINT *&---------------------------------------------------------------------* *& Form FRM_OUTPUT *&---------------------------------------------------------------------* form frm_output . * ALV输出 g_repid = sy-repid. call function 'REUSE_ALV_GRID_DISPLAY_LVC' exporting i_callback_program = g_repid is_layout_lvc = gs_layout it_fieldcat_lvc = gt_fieldcat[] i_save = 'X' i_callback_pf_status_set = cns_pf_status i_callback_user_command = 'ALV_USER_COMMAND' is_variant = v_stru_disvar it_events = git_events it_sort_lvc = it_sort[] is_print_lvc = gs_print tables t_outtab = itab[] exceptions program_error = 1 others = 2. if sy-subrc <> 0. message id sy-msgid type sy-msgty number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. endif. endform. " FRM_OUTPUT *&---------------------------------------------------------------------* *& Form ALV_PF_STATUS *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->RT_EXTAB text *----------------------------------------------------------------------* form alv_pf_status using rt_extab type slis_t_extab. set pf-status 'STANDARD_FULLSCREEN' . endform. "ALV_PF_STATUS *&---------------------------------------------------------------------* *& Form ALV_USER_COMMAND *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->R_UCOMM text * -->RS_SELFIELD text *----------------------------------------------------------------------* form alv_user_command using r_ucomm like sy-ucomm rs_selfield type slis_selfield. data: s_str type string, l_num_a type string, l_num_s type string. case r_ucomm. when '&DATA_SAVE'. when '&IC1'. when others. endcase. endform. "ALV_USER_COMMAND *end of add. form frm_refresh_alv . data: ref_grid type ref to cl_gui_alv_grid. * 取得当前alv的grid和fieldcat call function 'GET_GLOBALS_FROM_SLVC_FULLSCR' importing e_grid = ref_grid. * et_fieldcat_lvc = gt_fieldcat call method ref_grid->check_changed_data. call method ref_grid->refresh_table_display. endform. " FRM_REFRESH_ALV *&---------------------------------------------------------------------* *& Form frm_get_data *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* form frm_get_data . do 10 times. itab-vbeln = sy-index. append itab. enddo . endform. " frm_save_data *&---------------------------------------------------------------------* *& Form fm_button *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->E_GRID text *----------------------------------------------------------------------* form fm_button using e_grid type slis_data_caller_exit. 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 = tem_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 = . * 设置enter事件 call method tem_grid->register_edit_event exporting i_event_id = cl_gui_alv_grid=>mc_evt_enter exceptions error = 1 others = 2. * 设置 单光标焦点移开被修改单元格后既触发事件 call method tem_grid->register_edit_event exporting i_event_id = cl_gui_alv_grid=>mc_evt_modified exceptions error = 1 others = 2. create object gt_event_receiver. set handler gt_event_receiver->handle_modify for tem_grid. set handler gt_event_receiver->handle_data_changed for tem_grid. endform. "FM_BUTTON *&---------------------------------------------------------------------* *& Form FRM_REFRESH_DATA *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* form frm_refresh_data . data ls_stylerow type lvc_s_styl . message '你敲下了回车键,如果将VBELN改为8,则变成不可输入' type 'I'. loop at itab. if itab-vbeln = 8. ls_stylerow-fieldname = 'VBELN'. ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled."设成可以输入用mc_style_enabled insert ls_stylerow into table itab-field_style. modify itab. endif. endloop. endform. " FRM_REFRESH_DATA *&---------------------------------------------------------------------* *& Form handle_data_changed *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_ER_DATA_CHANGED text *----------------------------------------------------------------------* form handle_data_changed using p_er_data_changed type ref to cl_alv_changed_data_protocol. *如果更新的reason字段长度小于10为则提示用户填入字符数不能低于10 data:mod_data type lvc_t_modi, wa_mod_data type lvc_s_modi. mod_data = p_er_data_changed->mt_mod_cells. endform. "handle_data_changed.
    最爱江南烟雨如画:浩浩宇宙,朗朗乾坤,花花世界,滚滚红尘
 
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号