*&---------------------------------------------------------------------*
*& Include Y_ERIC_ALV_FUNCTION
*&---------------------------------------------------------------------*
*===============================ALV=====================
type-pools: slis.
data: i_fieldcat type slis_t_fieldcat_alv with header line.
data: i_events type slis_t_event.
data: i_layout type slis_layout_alv.
data: g_variant like disvariant.
data: l_ls_event type slis_alv_event,
l_title type lvc_title,
l_window_titlebar like sy-title,
ls_hype type lvc_s_hype,
gt_hypetab type lvc_t_hype.
* p_char(1).
*&---------------------------------------------------------*
define add_field.
i_fieldcat-tabname = &1. "内表名称
i_fieldcat-fieldname = &2. "字段名,大写
i_fieldcat-seltext_m = &3. "要显示的字段名
i_fieldcat-outputlen = &4. "长度
i_fieldcat-input = &5. "
i_fieldcat-hotspot = &6.
append i_fieldcat.
end-of-definition.
define display_data.
******启动命令功能********************************
refresh i_events.
call function 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = i_events.
read table i_events with key name = slis_ev_user_command
into l_ls_event.
if sy-subrc = 0.
move slis_ev_user_command to l_ls_event-form.
append l_ls_event to i_events.
endif.
********功能扩充**********************************
i_layout-zebra = 'X'. "颜色交替显示
i_layout-window_titlebar = l_window_titlebar. "抬头显示
i_layout-colwidth_optimize = 'X'. "优化
i_layout-group_change_edit = 'X'.
i_layout-f2code = &2.
call function 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_save = 'X'
is_variant = g_variant
i_grid_title = l_title "抬头
it_hyperlink = gt_hypetab
it_events = i_events "事件
it_fieldcat = i_fieldcat[] "显示的内容和描述
is_layout = i_layout
TABLES
t_outtab = &1 "数据表
EXCEPTIONS
program_error = 1
others = 2.
end-of-definition.
selection-screen skip 1.
二、使用定义的宏进行报表显示:
*三个add_filed,定义了三个要显示的行项目,gt_output是保存这些数据的内表
*格式:add_filed '内表' '字段名' '要显示的字段描述' 'L' 'CHAR'
add_filed 'gt_output' 'PERIO' '月份' 'L' 'CHAR'.
add_filed 'gt_output' 'SPART' '业务范围' 'L' 'CHAR'.
add_filed 'gt_output' 'BUKRS' '公司代码' 'L' 'CHAR'.
*完成字段添加后,加上下面一句:
*格式:display_data 内表名 ''.
display_data gt_output ''.
三、对上面功能的补充:
1、在字段上增加链接,以单击后链接到订单或进行其它处理
p_char = 'X'.
add_filed 'gt_output' 'KAUFN' '订单号' 'L' 'CHAR'.
p_char = ''.
2、在程序的任意位置增加下面的form
*这个form用来处理双击ALV报表时触发的动作,下面的示例是显示选择的定单
form user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
clear gt_output.
read table gt_output index rs_selfield-tabindex.
if sy-subrc = 0.
set parameter id 'AUN' field gt_output-kaufn.
call transaction 'VA03' and skip first screen.
endif.
endform. "user_command
也可以用下面的实现:
form user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
data: l_value type lvc_s_data-value.
import l_value from memory id 'l_value'.
data: c_vbeln like bseg-vbeln.
c_vbeln = l_value.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = c_vbeln
importing
output = c_vbeln.
set parameter id 'AUN' field c_vbeln.
call transaction 'VA03' and skip first screen.
endform. "user_command