SAP技术干货SAP

ALV回车事件

2017-11-16  本文已影响49人  Mmm_余安

ALV不能直接在GUI 状态里响应回车事件,需要自己定义,写代码。

REUSE_ALV_GRID_DISPLAY_LVC.png

data定义:

DATA:GT_EVENT TYPE SLIS_T_EVENT WITH HEADER LINE.
DATA STBL TYPE LVC_S_STBL.
DATA: REF_GRID TYPE REF TO CL_GUI_ALV_GRID.

选择屏幕前写:

CLASS LCL_EVENT_RECEIVER DEFINITION.
  PUBLIC SECTION.
    METHODS HANDLE_MODIFY
                  FOR EVENT DATA_CHANGED_FINISHED OF CL_GUI_ALV_GRID
      IMPORTING E_MODIFIED ET_GOOD_CELLS.
ENDCLASS.
DATA GT_EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER .

定义一个方法

CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.
  METHOD HANDLE_MODIFY.

    LOOP AT   IT_TAB INTO WA_TAB .
     *要处理的逻辑*
      MODIFY IT_TAB FROM WA_TAB.

    ENDLOOP.

    IF E_MODIFIED = 'X'.
      STBL-ROW = 'X'." 基于行的稳定刷新
      STBL-COL = 'X'." 基于列稳定刷新
      CALL METHOD REF_GRID->REFRESH_TABLE_DISPLAY
        EXPORTING
          IS_STABLE = STBL.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

在调ALV展示之前写一个单独的perform,类似layout 的 perform中写:

  DATA: I_GRID_SETTINGS TYPE LVC_S_GLAY.
  GT_EVENT-NAME = 'CALLER_EXIT'.
  GT_EVENT-FORM = 'FM_BUTTON'.
  APPEND GT_EVENT.
*&---------------------------------------------------------------------*
*&    FRM_BUTTON
*&---------------------------------------------------------------------*
*      ALV输出
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FM_BUTTON USING E_GRID TYPE SLIS_DATA_CALLER_EXIT.

  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      E_GRID = REF_GRID.
* 设置enter事件
  CALL METHOD REF_GRID->REGISTER_EDIT_EVENT
    EXPORTING
      I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_ENTER
    EXCEPTIONS
      ERROR      = 1
      OTHERS     = 2.


  CREATE OBJECT GT_EVENT_RECEIVER.
  SET HANDLER   GT_EVENT_RECEIVER->HANDLE_MODIFY FOR REF_GRID.


ENDFORM.
上一篇下一篇

猜你喜欢

热点阅读