**********************************************************************数据声明
TYPE-POOLS : SLIS. "ALV使用必须声明的
DATA: i_events type slis_t_event,
w_events like line of i_evenets,
i_list type slis_t_listheader,
w_list like line of i_list.
Define mc_add_fieldcat.
clear l_wa_fieldcat.
l_wa_fieldcat-fieldname = &1.
l_wa_fieldcat-seltext_l = &2.
l_wa_fieldcat-key = &3.
l_wa_fieldcat-outputlen = &4.
l_wa_fieldcat-no_zero = &5.
l_wa_fieldcat-just = &6.
append l_wa_fieldcat to lt_fieldcat.
End-of-definition.
Data: l_wa_fieldcat type slis_fieldcat_alv,
l_wa_layout type slis_layout_alv,
lt_fieldcat TYPE TABLE OF slis_t_fieldcat_alv.
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_top_of_page
into w_events.
if sy-subrc = 0.
move 'ALV_TOP_OF_PAGE' to w_events-form. "ALV表头
modify i_events from w_events index sy-tabix.
endif.
read table i_events
with key name = slis_ev_end_of_list
into w_events.
if sy-subrc = 0.
move 'ALV_END_OF_LIST' to w_events-form. "ALV表尾
modify i_events from w_events index sy-tabix.
endif.
mc_add_fieldcat: 'CARRNAME' '航班名称' '' '20' '' 'L' , "ALV的显示字段
'FLDATE' '航班日期' '' '20' '' 'L' ,
'CITYFROM' '起飞城市' '' '20' '' 'L' ,
'AIRPFROM' '起飞机场' '' '20' '' 'L' ,
'CITYTO' '目标城市' '' '20' '' 'L' ,
'AIRPTO' '目的机场' '' '20' '' 'L' ,
'DEPTIME' '启程时间' '' '20' '' 'C' ,
'ARRTIME' '到达时间' '' '20' '' 'C' ,
'PAYMENTSUM' '当前预定总数' '' '20' '' 'R' .
l_wa_layout-colwidth_optimize = 'X'. "宽度自动优化
l_wa_layout-box_fieldname = 'SEL'. "必须大写
l_wa_layout-edit_mode = 'X'. "
l_wa_layout-zebra = 'X'.
l_wa_layout-f2code = '&ETA'. " 双击事件(明细事件)
* l_wa_layout-detail_popup = 'X'. "双击事件
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = sy-repid
i_callback_pf_status_set = 'SET_STATUS'
i_callback_user_command = 'USER_COMMAND'
is_layout = l_wa_layout
i_save = 'A'
it_fieldcat = lt_fieldcat
it_events = i_events
i_grid_title = ' 航班信息表--子标题'
tables
t_outtab = t_alvdata " 用于显示ALV数据的显示内表
exceptions
program_error = 1
others = 2.
form alv_top_of_page. "ALV表头设计
user_name = sy-uname.
perform get_user_name changing user_name.
clear: i_list[].
w_list-typ = 'H'. "H=Header, S=Selection, A=Action
w_list-key = ''.
concatenate '航班信息表' '' into w_list-info.
append w_list to i_list.
w_list-typ = 'S'. "H=Header, S=Selection, A=Action
w_list-key = ''.
w_list-info = '查 询 人:'.
concatenate w_list-info user_name into w_list-info.
w_list-typ = 'S'. "H=Header, S=Selection, A=Action
w_list-key = ''.
concatenate w_list-info ' 查询日期:' sy-datum+0(4) '/' sy-datum+4(2) '/'
sy-datum+6(2) into w_list-info.
append w_list to i_list.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = i_list.
endform.
form alv_end_of_list. "ALV表尾设定
data count type i.
describe table t_data lines count.
clear: i_list[].
w_list-typ = 'S'.
w_list-info = count.
condense w_list-info.
concatenate '查询结果:总记录数为 ' w_list-info into w_list-info.
append w_list to i_list.
clear w_list_.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = i_list
.
endform.
form get_user_name changing p_name. "获取使用者姓名
select single * from usr21 where bname = p_name.
select single * from adrp where persnumber = usr21-persnumber.
check sy-subrc = 0.
concatenate adrp-name_last adrp-name_first into p_name. "名字连在一起
condense p_name no-gaps. "除去空格
endform.
form get_data.
endform.
FORM set_status USING rt_extab TYPE slis_t_extab. "对应ALV调用方法时的set_status参数设置
SET PF-STATUS 'ZBUTTON'.
ENDFORM.
FORM user_command USING ok_code TYPE sy-ucomm rs_selfield TYPE slis_selfield.
CASE ok_code.
WHEN 'BACK'.
SUBMIT zalv_fm.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'EXPORT'.
WHEN 'PRINT'.
ENDCASE.
ENDFORM.