1.进行ALV全局变量声明
DATA : l_pos TYPE i.
DATA : it_fieldcat_lvc TYPE lvc_t_fcat,
wa_fieldcat_lvc TYPE lvc_s_fcat,
wa_layout_lvc TYPE lvc_s_layo.
2.设置字段属性,布局属性,显示数据
FORM frm_display_data .
PERFORM frm_alv_setfield.
PERFORM frm_alv_setlayout.
PERFORM frm_alv_display.
ENDFORM.
首先设置字段属性:
FORM frm_alv_setfield .
l_pos = l_pos + 1.
wa_fieldcat_lvc-col_pos = l_pos.
wa_fieldcat_lvc-fieldname = 'MATKL'.
wa_fieldcat_lvc-scrtext_l = '物理组'.
wa_fieldcat_lvc-scrtext_m = '物理组'.
wa_fieldcat_lvc-scrtext_s = '物理组'.
wa_fieldcat_lvc-just = 'L'.
APPEND wa_fieldcat_lvc TO it_fieldcat_lvc.
CLEAR wa_fieldcat_lvc.
l_pos = l_pos + 1.
wa_fieldcat_lvc-col_pos = l_pos.
wa_fieldcat_lvc-fieldname = 'WGBEZ'.
wa_fieldcat_lvc-scrtext_l = '物料组描述'.
wa_fieldcat_lvc-scrtext_m = '物料组描述'.
wa_fieldcat_lvc-scrtext_s = '物料组描述'.
wa_fieldcat_lvc-just = 'L'.
APPEND wa_fieldcat_lvc TO it_fieldcat_lvc.
CLEAR wa_fieldcat_lvc.
...
...
...
ENDFORM.
其次设置布局属性:
FORM frm_alv_setlayout .
wa_layout_lvc-zebra = 'X'.
wa_layout_lvc-sel_mode = 'A'.
wa_layout_lvc-cwidth_opt = 'X'.
ENDFORM.
最后就是显示数据:
FORM frm_alv_display .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid " 当前程序
i_callback_pf_status_set = 'FRM_SET_PF_STATUS_10016'
i_callback_user_command = 'FRM_USER_COMMAND_10016'
is_layout_lvc = wa_layout_lvc " 属性内表
it_fieldcat_lvc = it_fieldcat_lvc[] " 列明内表
i_save = 'X' " 是否保存布局
TABLES
t_outtab = gt_mara " 数据内表
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM. " FRM_ALV_DISPLAY
套路就是这样!!!