原帖地址:http://www.cnblogs.com/elegantok/archive/2009/09/21/1570788.html
*-------------------------------------ALV参数 ------------------------------------
TYPE-POOLS: slis.
DATA: gt_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
gs_layout TYPE slis_layout_alv,
g_repid LIKE sy-repid VALUE sy-repid.
DATA :git_events TYPE slis_t_event,
it_sort TYPE slis_t_sortinfo_alv WITH HEADER LINE.
DATA: git_listheader TYPE slis_t_listheader,
git_listend TYPE slis_t_listheader.
DATA:BEGIN OF t_tab OCCURS 0,
sel TYPE c,
mark TYPE c,
matnr LIKE mseg-matnr, "物料编码
menge LIKE mseg-menge, "数量
END OF t_tab.
PERFORM init_fieldcat TABLES gt_fieldcat USING '1' .
FORM init_fieldcat TABLES g_alv_fieldcat USING p_flag.
REFRESH g_alv_fieldcat.
IF p_flag = '1'.
CLEAR gt_fieldcat . "勾选后MARK的值变为1
gt_fieldcat-fieldname = 'MARK' .
gt_fieldcat-outputlen = '5' .
gt_fieldcat-key = 'X'.
gt_fieldcat-edit = 'X'.
gt_fieldcat-checkbox = 'X'.
gt_fieldcat-seltext_s = '选择' .
APPEND gt_fieldcat TO g_alv_fieldcat.
ENDIF.
CLEAR gt_fieldcat.
gt_fieldcat-fieldname = 'MATNR'.
gt_fieldcat-seltext_s = '物料编码'.
gt_fieldcat-outputlen = 10.
gt_fieldcat-seltext_m = gt_fieldcat-seltext_s.
gt_fieldcat-seltext_l = gt_fieldcat-seltext_s.
gt_fieldcat-no_zero = 'X'.
APPEND gt_fieldcat.
CLEAR gt_fieldcat.
gt_fieldcat-fieldname = 'MAKTX'.
gt_fieldcat-seltext_s = '物料描述'.
gt_fieldcat-outputlen = 10.
gt_fieldcat-seltext_m = gt_fieldcat-seltext_s.
gt_fieldcat-seltext_l = gt_fieldcat-seltext_s.
gt_fieldcat-emphasize = 'C603'. "颜色,设置颜色时不可以与 关键值gt_fieldcat-key = 'X'. 一起使用
APPEND gt_fieldcat.
CLEAR gt_fieldcat.
gt_fieldcat-fieldname = 'MENGE'.
gt_fieldcat-seltext_s = '数量'.
gt_fieldcat-outputlen = 10.
gt_fieldcat-seltext_m = gt_fieldcat-seltext_s.
gt_fieldcat-seltext_l = gt_fieldcat-seltext_s.
* gt_fieldcat-key = 'X'.
gt_fieldcat-edit = 'X'. "可修改状态
gt_fieldcat-inttype = t_tab5-menge. " 修改的值
gt_fieldcat-ref_tabname = 'T001L'. "搜索帮助字段对应的表
gt_fieldcat-ref_fieldname = 'LGORT'. "搜索帮助的字段
gt_fieldcat-no_zero = 'X'.
APPEND gt_fieldcat.
ENDFORM. " INIT_FIELDCAT
FORM init_layout .
gs_layout-box_fieldname = 'SEL'.
* gs_layout-zebra = 'X'.
gs_layout-f2code = '&SEL'.
gs_layout-detail_popup = 'X'.
* gs_layout-colwidth_optimize = 'X'. “自动设置列宽,关闭后按 gt_fieldcat-outputlen 值设定
ENDFORM. " INIT_LAYOUT
FORM listado .
g_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = g_repid
is_layout = gs_layout
it_fieldcat = gt_fieldcat[]
i_save = 'A'
it_events = git_events[]
i_callback_pf_status_set = 'FRM_STATUS' "显示自定义toolbar
i_callback_user_command = 'USER_COMMAND' "调用命令
it_sort = it_sort[]
TABLES
t_outtab = t_tab5
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM. " LISTADO
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield. "响应ALV点击自定义按钮之后的事件
CASE r_ucomm.
WHEN 'TEST'.
PERFORM save_alv.
ENDCASE.
ENDFORM. "EXECUTE_COMMAND
FORM save_alv . "修改后的值保存到内表中
DATA: l_grid TYPE REF TO cl_gui_alv_grid.
*------------将ALV上修改的内容保存到内表---------------------------------*
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = l_grid.
CALL METHOD l_grid->check_changed_data.
ENDFORM. " SAVE_ALV