ABAP ALV 模板
项目中使用频率最高的的技术ALV,可以快速调用:
*&---------------------------------------------------------------------* *& Form FRM_DISPLAY_ALV *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* form frm_display_alv tables it_alv. data: lv_repid type syst-repid, lt_fieldcat type lvc_t_fcat, ls_layout type lvc_s_layo, lt_sort type lvc_t_sort. lv_repid = sy-repid. perform frm_alv_fieldcat tables lt_fieldcat it_alv. perform frm_alv_layout using ls_layout. * lt_sort = value #( ( fieldname = 'MBLNR' subtot = abap_on ) * ( fieldname = 'ZEILE' ) ). * perform frm_user_command. * perform frm_set_pf_status. call function 'REUSE_ALV_GRID_DISPLAY_LVC' exporting i_callback_program = lv_repid i_callback_pf_status_set = 'FRM_SET_PF_STATUS' i_callback_user_command = 'FRM_USER_COMMAND' is_layout_lvc = ls_layout it_fieldcat_lvc = lt_fieldcat it_sort_lvc = lt_sort * it_excluding = gt_excluding * it_events = gt_events i_default = 'X' i_save = 'A' tables t_outtab = it_alv 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. *&---------------------------------------------------------------------* *& Form FRM_USER_COMMAND *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* form frm_user_command using r_ucomm like sy-ucomm rs_selfield type slis_selfield. data: lc_grid type ref to cl_gui_alv_grid, lv_refresh type char1. call function 'GET_GLOBALS_FROM_SLVC_FULLSCR' importing e_grid = lc_grid. lc_grid->check_changed_data( importing e_valid = data(lv_valid) changing c_refresh = lv_refresh ). rs_selfield-refresh = 'X'. lc_grid->get_selected_rows( importing et_index_rows = data(lt_index_rows) et_row_no = data(lt_row_no) ). case r_ucomm. when 'ZPOST'. perform post. endcase. endform. "frm_user_command *&---------------------------------------------------------------------* *& Form FRM_ALV_FIELDCAT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* form frm_alv_fieldcat tables it_fieldcat type lvc_t_fcat it_table. refresh:it_fieldcat. perform frm_create_fieldcat tables it_fieldcat it_table. perform frm_change_fieldcat tables it_fieldcat. endform. " FRM_ALV_FIELDCAT *&---------------------------------------------------------------------* *& Form FRM_ALV_LAYOUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* form frm_alv_layout using ps_layout type lvc_s_layo . ps_layout-zebra = 'X'. ps_layout-sel_mode = 'A'. ps_layout-cwidth_opt = 'X'. * Ps_layout-box_fname = 'CHECKBOX'. * Ps_layout-ctab_fname = 'CELLCOL'. * Ps_layout-stylefname = 'CELLTAB'. * Ps_layout-info_fname = 'ROWCOLOR'. endform. " FRM_ALV_LAYOUT *&---------------------------------------------------------------------* *& Form FRM_SET_PF_STATUS *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* form frm_set_pf_status using rt_extab type slis_t_extab. data fcode type table of sy-ucomm. * append 'ZPOST' to fcode. set pf-status 'STATUS_ALV' excluding fcode. endform. "frm_set_pf_status *&---------------------------------------------------------------------* *& Form FRM_CREATE_FIELDCAT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_GT_FIELDCAT text * -->P_0079 text *----------------------------------------------------------------------* form frm_create_fieldcat tables it_fieldcat type lvc_t_fcat it_table. data: lr_tabdescr type ref to cl_abap_structdescr, lr_data type ref to data, lt_dfies type ddfields, ls_dfies type dfies, ls_fieldcat type lvc_s_fcat. clear it_fieldcat. create data lr_data like line of it_table. lr_tabdescr ?= cl_abap_structdescr=>describe_by_data_ref( lr_data ). lt_dfies = cl_salv_data_descr=>read_structdescr( lr_tabdescr ). loop at lt_dfies into ls_dfies. clear ls_fieldcat. move-corresponding ls_dfies to ls_fieldcat. append ls_fieldcat to it_fieldcat. endloop. endform. *&---------------------------------------------------------------------* *& Form FRM_CHANGE_FIELDCAT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * <--P_GT_FIELDCAT text *----------------------------------------------------------------------* form frm_change_fieldcat tables it_fieldcat type lvc_t_fcat. loop at it_fieldcat assigning field-symbol(<fs_fieldcat>). data(lv_tabix) = sy-tabix. case <fs_fieldcat>-fieldname. when 'ZEILE'. perform fieldcat_name using '序号' <fs_fieldcat>. when 'MANDT'. delete it_fieldcat[] index lv_tabix. continue. when others. endcase. endloop. endform. *&---------------------------------------------------------------------* *& Form fieldcat_name *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_0067 text *----------------------------------------------------------------------* form fieldcat_name using p_name ps_fieldcat type lvc_s_fcat. ps_fieldcat-reptext = p_name. ps_fieldcat-scrtext_l = ps_fieldcat-reptext. ps_fieldcat-scrtext_m = ps_fieldcat-reptext. ps_fieldcat-scrtext_s = ps_fieldcat-reptext. endform.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏