示例REUSE_ALV_GRID_DISPLAY_LVC(更好的和ALV容器结合)
REPORT ztest1.
"引入类型池
TYPES: slis.
TYPES:
BEGIN OF ty_customer,
id TYPE char10,
name TYPE char10,
city TYPE char30,
END OF ty_customer .
TYPES: ty_t_customer TYPE STANDARD TABLE OF ty_customer WITH EMPTY KEY.
"数据源
DATA(gt_customer) =
VALUE ty_t_customer(
( id = 'C01' name = 'zhangsan' city = 'CSC')
( id = 'C02' name = 'lishi' city = 'CDC')
( id = 'C03' name = 'wangwu' city = 'SHC')
).
DATA: wa_fieldcat_lvc TYPE lvc_s_fcat , " 相当于工作区
gt_fieldcat TYPE STANDARD TABLE OF lvc_s_fcat, " 内表
wa_layout TYPE lvc_s_layo , " 负责整个ALV的全局属性、格式
wa_grid_setting TYPE lvc_s_glay.
DEFINE mcr_set_fieldcat.
wa_fieldcat-fieldname = &1.
wa_fieldcat-scrtext_m = &2.
wa_fieldcat-scrtext_s = &2.
wa_fieldcat-scrtext_l = &2.
wa_fieldcat-colddictxt = 'L'.
wa_fieldcat-edit = &3.
wa_fieldcat-lowercase = &4 .
wa_fieldcat-no_out = &5 .
wa_fieldcat-ref_field = &6 .
wa_fieldcat-ref_table = &7 .
wa_fieldcat-fix_column = &8.
APPEND wa_fieldcat to gt_fieldcat.
CLEAR wa_fieldcat.
END-OF-DEFINITION.
"定义全局格式
wa_layout-cwidth_opt = c_flag_x.
wa_layout-box_fname = 'MARK'.
wa_layout-sel_mode = c_flag_d.
wa_layout-zebra = c_flag_x.
wa_layout-excp_fname = 'LIGHT' .
wa_grid_setting-edt_cll_cb = 'X'.
"调用宏定义列
mcr_set_fieldcat:
'ID' 'ID' '' '' '' '' '' 'X',
'NAME' '名字' '' '' '' '' '' 'X',
'CITY' '城市' '' '' '' '' '' 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid " 当前程序
i_callback_pf_status_set = 'FRM_SET_PFSTATUS' "工具栏,见下
i_callback_user_command = 'FRM_ACTION_COMMAND' "实现对应菜单项及相应事件功能,见下
is_layout_lvc = wa_layout
i_grid_settings = wa_grid_setting
it_fieldcat_lvc = gt_fieldcat[]
i_default = 'X'
i_save = 'A'
TABLES
t_outtab = gt_customer " 数据内表
EXCEPTIONS
program_error = 1
OTHERS = 2.
""""附
FORM frm_set_pfstatus USING pu_extab TYPE slis_t_extab.
lt_fcode = VALUE #( ( |APPROVE| )
( |PAPAY| )
( |TLPAY| )
( |VENREFUND| )
( |STSPUSH| )
) .
SET PF-STATUS 'STATUS_ALV' EXCLUDING lt_fcode . "lt_fcode内表可自定义
SET TITLEBAR 'TITLE_ALV' . "TITLE_ALV可动态设置使用&1占位符
ENDFORM.
FORM frm_action_command USING pu_r_ucomm LIKE sy-ucomm
ps_selfield TYPE slis_selfield.
ps_selfield-refresh = c_flag_x.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = gv_grid.
CALL METHOD gv_grid->check_changed_data.
CASE pu_r_ucomm .
WHEN 'xxx' .
WHEN '&IC1'. "双击穿透-----单击实现则需设置wa_fieldcat-hotpost = 'X'
ENDCASE.
CALL METHOD gv_grid->refresh_table_display.
ENDFORM.