转自:http://www.baidusap.com/abap/alv/4967#2, 例子代码
下面介绍如何在ALV头中显示Logo图片的方法,其中ALV是调用函数REUSE_ALV_GRID_DISPLAY创建的。详细步骤如下:
1, OAER上载Logo
Tcode: OAER上载需要显示的LOGO图片,
输入Class name ’PICTURERS',Class type以及Object key ‘ZLOGO',这个ZLOGO就是logo的标识,会在ALV程序中用到。
运行后,双击screen上载logo
输入描述,
上载成功后会有如下提示信息:
2, 例子代码
代码逻辑:
1,从SPFLI中抽取数据
2,调用REUSE_ALV_GRID_DISPLAY创建ALV,需要指定 i_callback_top_of_page参数
3,在回调函数top_of_page中,调用 REUSE_ALV_COMMENTARY_WRITE指定显示logo的object ID 'ZLOGO'.
完整代码如下:
EPORT ztest_alv_logo.
TYPE-POOLS: slis.
*----------------------------------------------------------------------*
* Data Decalaration
*----------------------------------------------------------------------*
DATA: git_spfli TYPE TABLE OF spfli.
DATA: g_repid TYPE sy-repid.
DATA: git_listheader TYPE slis_t_listheader,
gwa_listheader TYPE slis_listheader.
*----------------------------------------------------------------------*
* START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
g_repid = sy-repid.
SELECT * FROM spfli INTO TABLE git_spfli.
PERFORM build_alv_header.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = g_repid
i_callback_top_of_page = 'TOP_OF_PAGE'
i_structure_name = 'SPFLI'
TABLES
t_outtab = git_spfli.
*&---------------------------------------------------------------------*
*& Form BUILD_ALV_HEADER
*&---------------------------------------------------------------------*
FORM build_alv_header .
* Type H is used to display headers i.e. big font
gwa_listheader-typ = 'H'.
gwa_listheader-info ='Flight Details'.
APPEND gwa_listheader TO git_listheader.
CLEAR gwa_listheader.
* Type S is used to display key and value pairs
gwa_listheader-typ = 'S'.
gwa_listheader-key = 'Date :' .
CONCATENATE sy-datum+6(2)
sy-datum+4(2)
sy-datum(4)
INTO gwa_listheader-info
SEPARATED BY '/'.
APPEND gwa_listheader TO git_listheader.
CLEAR gwa_listheader.
* Type A is used to display italic font
gwa_listheader-typ = 'A'.
gwa_listheader-key = 'Date :' .
gwa_listheader-info ='SAP ALV Report'.
APPEND gwa_listheader TO git_listheader.
CLEAR gwa_listheader.
ENDFORM. " BUILD_ALV_HEADER
*&---------------------------------------------------------------------*
*& Form top_of_page
*&---------------------------------------------------------------------*
FORM top_of_page.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = git_listheader
i_logo = 'ZLOGO'. "LOGO object key 大写
ENDFORM. "top_of_page
3, 运行结果
以上。