实战ALV OO技术实现双击
REPORT Z_ALV_ERIC.
DATA: OK_CODE TYPE SY-UCOMM,
SAVE_OK LIKE OK_CODE.
data wa_spfli type table of spfli.
SELECT * INTO TABLE WA_SPFLI FROM SPFLI.
*定义窗口定制控制,定义ALV对象
DATA: WA_CONTAINER TYPE SCRFNAME VALUE 'ALVDATA',
ALV_GRID TYPE REF TO CL_GUI_ALV_GRID,
WA_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
* 定义事件类型
class lcl_event_receiver definition deferred.
*定义事件
data event_receiver TYPE REF TO lcl_event_receiver.
CALL SCREEN 1001.
* 定义事件属性跟方法
CLASS LCL_EVENT_RECEIVER DEFINITION.
*公共事件
PUBLIC SECTION.
METHODS:
* 双击方法
handle_double_click
for event double_click of cl_gui_alv_grid
IMPORTING e_row e_column.
* HANDLE_TOOLBAR
* FOR EVENT TOOLBAR OF CL_GUI_ALV_GRID
* IMPORTING E_OBJECT E_INTERACTIVE,
** 用户交互事件处理
* HANDLE_USER_COMMAND
* FOR EVENT USER_COMMAND OF CL_GUI_ALV_GRID
* IMPORTING E_UCOMM.
** PRIVATE SECTION.
ENDCLASS. "LCL_EVENT_RECEIVER DEFINITION
*实现方法
CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.
* 双击方法实现
METHOD handle_double_click.
data: li_spfli like LINE OF wa_spfli.
READ TABLE wa_spfli index e_row-index into li_spfli.
*将行列等信息合并到字符串
data: s1(100).
concatenate '行:' E_ROW-INDEX ' 列名:' E_COLUMN-FIELDNAME
INTO S1.
CONCATENATE S1 ' CONNID:' LI_SPFLI-CONNID INTO S1.
CONCATENATE S1 ' CARRID:' LI_SPFLI-CARRID INTO S1.
* 在状态条显示单击的行与列信息
* 信息00 在IDS中已经定义好,208带一个参数的信息
MESSAGE s208(00) with S1.
ENDMETHOD.
ENDCLASS. "LCL_EVENT_RECEIVER IMPLEMENTATION
* PBO 定义状态条,包括菜单,工具条按钮,系统按钮等
MODULE STATUS_1001 OUTPUT.
SET PF-STATUS 'STATUS1'.
* SET TITLEBAR ''.
* 如果窗口还没创建ALV对象则创建
IF WA_CUSTOM_CONTAINER IS INITIAL.
CREATE OBJECT WA_CUSTOM_CONTAINER
EXPORTING
CONTAINER_NAME = WA_CONTAINER.
CREATE OBJECT ALV_GRID
EXPORTING
I_PARENT = WA_CUSTOM_CONTAINER.
CALL METHOD ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_STRUCTURE_NAME = 'SPFLI'
CHANGING
IT_OUTTAB = WA_SPFLI.
* ALV 对象分配双击事件
create OBJECT event_receiver.
set HANDLER event_receiver->handle_double_click
for alv_grid.
ENDIF.
ENDMODULE. " STATUS_1001 OUTPUT
* PAI
MODULE USER_COMMAND_1001 INPUT.
SAVE_OK = OK_CODE.
CLEAR OK_CODE.
CASE SAVE_OK.
WHEN 'EXT'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " USER_COMMAND_1001 INPUT