一個需求,ALV展現後,雙擊某行,再彈出一個ALV 某些信息,而後,響應彈出ALV的事件。ide
而後作了個demoui
執行顯示spfli數據,雙擊某行,根據carrid 獲取sflight 表數據,彈出alv 展現sflight數據,而後雙擊sflight數據,彈出message顯示雙擊了第幾行。spa
效果圖orm
其實沒什麼,過久不作這類的了,作個備份吧,之後方便copyblog
主要代碼以下;事件
9001空白屏幕圖片
*&---------------------------------------------------------------------*
*& Include ZLM_TEST_001_TOP
*&---------------------------------------------------------------------*
*--global data
DATA:
GT_SPFLI TYPE TABLE OF SPFLI,
GT_SFLIGHT TYPE TABLE OF SFLIGHT.
*---alv data
DATA:
GCL_GRID_SPFLI TYPE REF TO CL_GUI_ALV_GRID, "ALV控件
GCL_GRID_SFLIGHT TYPE REF TO CL_GUI_ALV_GRID, "ALV控件
GCL_DOC_SPFLI TYPE REF TO CL_GUI_DOCKING_CONTAINER,
GCL_DOC_SFLIGHT TYPE REF TO CL_GUI_DIALOGBOX_CONTAINER. "第二個彈出框alv 容器
*---the first alv event class
CLASS LCL_EVENT_SPFLI_RECEIVER DEFINITION.
PUBLIC SECTION.
METHODS HANDLE_DOUBLE_CLICK
FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
IMPORTING E_ROW E_COLUMN.
METHODS HANDLE_CLOSE
FOR EVENT CLOSE OF CL_GUI_DIALOGBOX_CONTAINER
IMPORTING SENDER.
ENDCLASS.
CLASS LCL_EVENT_SPFLI_RECEIVER IMPLEMENTATION.
METHOD HANDLE_DOUBLE_CLICK.
DATA:LS_SPFLI TYPE SPFLI.
READ TABLE GT_SPFLI INTO LS_SPFLI INDEX E_ROW.
SELECT * FROM SFLIGHT INTO TABLE GT_SFLIGHT
WHERE CARRID = LS_SPFLI-CARRID.
PERFORM FRM_SHOW_SFLIGHT.
ENDMETHOD.
METHOD HANDLE_CLOSE.
CALL METHOD SENDER->SET_VISIBLE
EXPORTING
VISIBLE = SPACE.
ENDMETHOD.
ENDCLASS.
*---event calss for the second alv
CLASS LCL_EVENT_SFLIGHT_RECEIVER DEFINITION.
PUBLIC SECTION.
METHODS HANDLE_DOUBLE_CLICK
FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
IMPORTING E_ROW E_COLUMN.
ENDCLASS.
CLASS LCL_EVENT_SFLIGHT_RECEIVER IMPLEMENTATION.
METHOD HANDLE_DOUBLE_CLICK.
DATA:LS_SFLIGHT TYPE SFLIGHT.
DATA:LV_MSG TYPE STRING.
READ TABLE GT_SFLIGHT INTO LS_SFLIGHT INDEX E_ROW.
IF SY-SUBRC = 0.
LV_MSG = E_ROW.
CONCATENATE 'Row:' LV_MSG INTO LV_MSG SEPARATED BY SPACE.
MESSAGE LV_MSG TYPE 'I'.
ENDIF.
ENDMETHOD.
ENDCLASS.
*---event
DATA: EVENT_SPFLI_RECEIVER TYPE REF TO LCL_EVENT_SPFLI_RECEIVER.
DATA: EVENT_SFLIGHT_RECEIVER TYPE REF TO LCL_EVENT_SFLIGHT_RECEIVER.it
*&---------------------------------------------------------------------*
*& Form FRM_ALV_SPFLI
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_ALV_SPFLI .
IF GCL_GRID_SPFLI IS INITIAL.
CREATE OBJECT GCL_DOC_SPFLI
EXPORTING
REPID = SY-REPID
DYNNR = '9001'
* side = cl_gui_docking_container=>dock_at_right "ALV貼屏幕右邊,從屏幕右邊開始算寬度
SIDE = CL_GUI_DOCKING_CONTAINER=>DOCK_AT_LEFT "ALV貼屏幕左邊,從左邊算屏幕寬度,
EXTENSION = 900 "屏幕寬度
STYLE = CL_GUI_CONTROL=>WS_CHILD "可選參數,設置ALV是否可用手動拖動大小
EXCEPTIONS
CNTL_ERROR = 1
CNTL_SYSTEM_ERROR = 2
CREATE_ERROR = 3
LIFETIME_ERROR = 4
LIFETIME_DYNPRO_DYNPRO_LINK = 5
OTHERS = 6.
IF SY-SUBRC <> 0.
MESSAGE S001(00) WITH '屏幕初始化失敗'.
LEAVE LIST-PROCESSING.
ENDIF.
CREATE OBJECT GCL_GRID_SPFLI
EXPORTING
I_PARENT = GCL_DOC_SPFLI.
* event 綁定事件
CREATE OBJECT EVENT_SPFLI_RECEIVER.
"雙擊某一單元格事件
SET HANDLER EVENT_SPFLI_RECEIVER->HANDLE_DOUBLE_CLICK FOR GCL_GRID_SPFLI.
* "顯示內表數據
CALL METHOD GCL_GRID_SPFLI->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_STRUCTURE_NAME = 'SPFLI'
CHANGING
IT_OUTTAB = GT_SPFLI[].
ELSE.
CALL METHOD CL_GUI_CFW=>FLUSH.
ENDIF.
ENDFORM. " ZFORM_ALV_SHOW
*&---------------------------------------------------------------------*
*& Form FRM_SHOW_SFLIGHT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_SHOW_SFLIGHT .
IF GCL_GRID_SFLIGHT IS INITIAL.
CREATE OBJECT EVENT_SFLIGHT_RECEIVER.
CREATE OBJECT GCL_DOC_SFLIGHT
EXPORTING
TOP = 150
LEFT = 150
LIFETIME = CNTL_LIFETIME_DYNPRO
CAPTION = 'SFLIGHT'
WIDTH = 800
HEIGHT = 200.
CREATE OBJECT GCL_GRID_SFLIGHT
EXPORTING
I_PARENT = GCL_DOC_SFLIGHT.
SET HANDLER EVENT_SPFLI_RECEIVER->HANDLE_CLOSE FOR GCL_DOC_SFLIGHT.
SET HANDLER EVENT_SFLIGHT_RECEIVER->HANDLE_DOUBLE_CLICK FOR GCL_GRID_SFLIGHT.
CALL METHOD GCL_GRID_SFLIGHT->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_STRUCTURE_NAME = 'SFLIGHT'
CHANGING
IT_OUTTAB = GT_SFLIGHT.
CALL METHOD CL_GUI_CONTROL=>SET_FOCUS
EXPORTING CONTROL = GCL_GRID_SFLIGHT.
ELSE.
CALL METHOD GCL_DOC_SFLIGHT->SET_VISIBLE
EXPORTING
VISIBLE = 'X'.
CALL METHOD GCL_GRID_SFLIGHT->REFRESH_TABLE_DISPLAY.
ENDIF.
ENDFORM.event
*&---------------------------------------------------------------------*
*& Include ZLM_TEST_001_PBO
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module STATUS_9001 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_9001 OUTPUT.
SET PF-STATUS 'TEST_STATUS'.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module MDL_SHOW OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE MDL_SHOW OUTPUT.
PERFORM frm_alv_spfli.
ENDMODULE.class
*&---------------------------------------------------------------------*
*& Module MDL_EXIT INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE MDL_EXIT INPUT.
LEAVE PROGRAM.
ENDMODULE.