*&---------------------------------------------------------------------*
*& 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