最近意识到一个问题,就是我的记性越来越不好了,经常将做过的事情忘记掉。我这个人做事情还是比较极端的,大学的时候是记性最不好的时候,基本上每天都忘记一些事情,上课连教室都会找不到。在REMEC的时候也很糊涂。总的来说,来到这个公司之后记性变好了,有的时候发现自己记性还相当的不错 。不过现在做的事情比较难了,有些知识点是应该及时记下来的,做到大家共享,也为了让自己不要遗忘。
今天在金工的帮助之下完成了欠料分析报表的开发。现在记录一下怎样在ABAP的报表中加入自定义按钮。以加入刷新按钮为例:
1.WRITE报表:
这个比较简单:
(1)先要加入一句set pf-status 'TOOLBAR'.(这句加在哪里好像问题不大,我就加在了end-of-selection.之后了)
(2)双击TLLOBAR进入,定义标题栏。这里我将刷新按钮 返回值定义为;REFR; 这里其实和直接进入SE41的效果是一样的。
(3)然后还要加一个user-command语句。标明这个按钮的作用
at user-command.
case sy-ucomm.
when 'REFR'.
CLEAR hd_itab.
CLEAR hd_itab[].
perform getdata.
PERFORM DATA_OUTPUT.
ENDCASE.
2.ALV格式的
要有三个地方改动,这里将金工的小报表(试验程序贴上来了,我编的那个欠料情况表太长了,又慢,就算了吧 )
*&---------------------------------------------------------------------*
*& Report Z_TEST_CLASS
*& 描 述: 自定义按钮
*&---------------------------------------------------------------------*
*& 日 期:
*& 作 者:
*&---------------------------------------------------------------------*
REPORT Z_TEST_CLASS1.
tables: makt.
selection-screen begin of block b1.
select-options:
se_matnr for makt-matnr.
selection-screen end of block b1.
type-pools:
slis.
data:
i_fieldcat_alv type slis_t_fieldcat_alv, "定义列标题(属性/信息)
i_layout type slis_layout_alv, "alv格式
i_fieldcat type slis_fieldcat_alv, "
i_events type slis_t_event, "alv事件
w_events like line of i_events,
i_list_comments type slis_t_listheader, "alv表单标题区域设置
w_list_comments like line of i_list_comments,
w_repid like sy-repid. "当前程序
data:
begin of itab occurs 0,
matnr like rseg-matnr,
maktx like makt-maktx,
end of itab.
start-of-selection.
select matnr maktx from makt into table itab.
end-of-selection.
perform display_data.
*&---------------------------------------------------------------------*
*& Form fields_build 设置报表显示列属性信息
*&---------------------------------------------------------------------*
form fields_build .
refresh i_fieldcat_alv.
clear i_fieldcat.
data colnum type i.
colnum = colnum + 1.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = 'MATNR'.
i_fieldcat-seltext_s = '物料编号'.
i_fieldcat-seltext_m = '物料编号'.
i_fieldcat-seltext_l = '物料编号'.
i_fieldcat-outputlen = 10.
i_fieldcat-key = 'X'.
append i_fieldcat to i_fieldcat_alv.
clear i_fieldcat.
colnum = colnum + 1.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = 'MAKTX'.
i_fieldcat-seltext_s = '物料描述'.
i_fieldcat-seltext_m = '物料描述'.
i_fieldcat-seltext_l = '物料描述'.
i_fieldcat-outputlen = 20.
append i_fieldcat to i_fieldcat_alv.
clear i_fieldcat.
endform.
*&---------------------------------------------------------------------*
*& Form events_build
*&---------------------------------------------------------------------*
form events_build .
call function 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = i_events .
* read table i_events with key name = 'TOP_OF_PAGE'
* into w_events.
* if sy-subrc = 0.
* move 'ALV_TOP_OF_PAGE' to w_events-form.
* modify i_events from w_events index sy-tabix.
* endif.
READ TABLE i_events INTO w_events WITH KEY NAME = 'USER_COMMAND'.
IF SY-SUBRC EQ 0.
w_events-name = 'USER_COMMAND'.
MODIFY i_events FROM w_events index sy-tabix.
ENDIF.
endform. " events_build
*&---------------------------------------------------------------------*
*& Form display_data 显示报表内容
*&---------------------------------------------------------------------*
form display_data .
perform layout_build .
perform events_build .
perform fields_build .
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
I_CALLBACK_USER_COMMAND = 'USER_COMMAND' “这两个地方是一定要加上的
i_callback_pf_status_set = 'PF_STATUS_SET' 调用用户事件和按钮事件
i_callback_program = w_repid
is_layout = i_layout
it_fieldcat = i_fieldcat_alv[]
it_events = i_events[]
" i_grid_title = ''
I_SAVE = 'A'
tables
t_outtab = itab.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform. " display_data
*&---------------------------------------------------------------------*
*& Form layout_build 设置alv显示格式和属性
*&---------------------------------------------------------------------*
form layout_build .
i_layout-zebra = 'X'.
* i_layout-detail_popup = 'X'.
i_layout-no_vline = ' '.
i_layout-colwidth_optimize = 'X'.
* i_layout-detail_initial_lines = 'X'.
* i_layout-detail_titlebar = '详细内容'.
* i_layout-f2code = '&ETA'.
i_layout-no_colhead = ' '.
w_repid = sy-repid.
endform. "layout_build
*---------------------------------
FORM PF_STATUS_SET USING rt_extab TYPE slis_t_extab. ”调用的FORM
set pf-status 'TEST1'.
endform.
*&--------------------------------------------------------------------*
*& Form user_command
*&--------------------------------------------------------------------*
form user_command using i_ucomm like sy-ucomm “这段程序表明了自定义按钮是做什么用的。可以在SE41
is_selfield type slis_selfield. 中自定义返回值
case i_ucomm.
when '&IC1'.
message i888(sabapdocu) with '双击事件'.
when '&REFRE'.
message i888(sabapdocu) with '刷新事件'.
is_selfield-refresh = 'X'.
clear itab[].
endcase.
endform. "user_command