其他分享
首页 > 其他分享> > ALV双击弹出新ALV,并响应新ALV事件

ALV双击弹出新ALV,并响应新ALV事件

作者:互联网

一个需求,ALV展示后,双击某行,再弹出一个ALV 某些信息,然后,响应弹出ALV的事件。

然后做了个demo

执行显示spfli数据,双击某行,根据carrid 获取sflight 表数据,弹出alv 展示sflight数据,然后双击sflight数据,弹出message显示双击了第几行。

效果图

图片

其实没什么,太久不做这类的了,做个备份吧,以后方便copy

主要代码如下;

图片

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.

 

 

 

*&---------------------------------------------------------------------*
*&      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.

 

*&---------------------------------------------------------------------*
*&  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.

 

*&---------------------------------------------------------------------*
*&      Module  MDL_EXIT  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE MDL_EXIT INPUT.
  LEAVE PROGRAM.
ENDMODULE.




标签:SFLIGHT,GCL,SPFLI,GRID,EVENT,ALV,出新,双击
来源: https://blog.51cto.com/15057820/2628612