ALV GRID 响应回车事件修改内容

*&---------------------------------------------------------------------*
*& Report  ZTEST_008
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZTEST_008.
TYPE-POOLS: slis.

DATA: gs_fcat TYPE lvc_s_fcat,
      gt_fcat TYPE lvc_t_fcat,
      gs_layo TYPE lvc_s_layo,
      gs_grid TYPE lvc_s_glay.
DATA: gt_event TYPE slis_t_event WITH HEADER LINE,
      gt_event_exit TYPE slis_t_event_exit WITH HEADER LINE.

DATA:  ref_grid TYPE REF TO cl_gui_alv_grid..

DATA: BEGIN OF gt_itab OCCURS 0,
        aa TYPE c,
        bb TYPE i,
        cc TYPE p,
     style TYPE lvc_t_styl,
    END OF gt_itab.
DATA: wa_itab LIKE gt_itab.

*----------------------------------------------------------------------*
*       CLASS lcl_event_receiver DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
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.                    "LCL_EVENT_RECEIVER DEFINITION *----------------------------------------------------------------------* * CLASS LCL_EVENT_RECEIVER IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS lcl_event_receiver IMPLEMENTATION. METHOD handle_modify. DATA stbl TYPE lvc_s_stbl. LOOP AT gt_itab INTO wa_itab. wa_itab-cc = wa_itab-bb * 2 . MODIFY gt_itab FROM wa_itab. ENDLOOP. * 稳定刷新 stbl-row = 'X'." 基于行的稳定刷新 stbl-col = 'X'." 基于列稳定刷新 CALL METHOD ref_grid->refresh_table_display EXPORTING is_stable = stbl. ENDMETHOD. "HANDLE_MODIFY
ENDCLASS.                    "LCL_EVENT_RECEIVER IMPLEMENTATION DATA gt_event_receiver TYPE REF TO lcl_event_receiver . START-OF-SELECTION. gt_itab-aa = 'aa'.
  gt_itab-bb = 1.
  gt_itab-cc = '1.2'.
  APPEND gt_itab.


  gt_itab-aa = 'aa'.
  gt_itab-bb = 1.
  gt_itab-cc = '1.2'.
  APPEND gt_itab.

  gt_itab-aa = 'aa'.
  gt_itab-bb = 1.
  gt_itab-cc = '1.2'.
  APPEND gt_itab.

  PERFORM display_data .


*&---------------------------------------------------------------------*
*&      Form  display_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM display_data .
  PERFORM set_fcat.
  PERFORM set_layout.
  PERFORM show_alv  TABLES gt_fcat  gt_itab[]
                     USING  gs_layo.
ENDFORM.                    " DISPLAY_DATA *&---------------------------------------------------------------------* FORM set_fcat . PERFORM csalv_set_fcat USING: " 'Field' 'Text' 'Edit' 'Zero' 'Type' 'Qfieldname' 'Key' 'Hostspot' 'Emphasize' 'Checkbox'
        'AA'  'AA'  ''  ''  ''  ''  ''  ''  ''  '',
        'BB'  'BB'  'X'  ''  ''  ''  ''  ''  ''  '',
        'CC'  'CC'  ''  ''  ''  ''  ''  ''  ''  ''.
*        'DD'  'DD'  'X'  ''  ''  ''  ''  'X'  ''  'X',
*        'EE'  'EE'  ''  ''  ''  ''  ''  ''  ''  'X'  .

ENDFORM.                    " SET_FCAT *&---------------------------------------------------------------------* FORM set_layout . gs_layo-zebra = 'X'.
*  gs_layout-stylefname     = 'FIELD_STYLE'.
*  gs_layo-CWIDTH_OPT        =  'X'.
ENDFORM.                    " SET_LAYOUT *&---------------------------------------------------------------------* FORM csalv_set_fcat USING p_name p_text p_edit p_zero p_type p_qfieldname p_key p_hotspot p_emphasize p_checkbox. gs_fcat-fieldname = p_name. * gs_fcat-reptext_l = * gs_fcat-selddictxt = gs_fcat-reptext = p_text. gs_fcat-edit = p_edit. gs_fcat-no_zero = p_zero. gs_fcat-datatype = p_type. gs_fcat-qfieldname = p_qfieldname. gs_fcat-key = p_key. gs_fcat-hotspot = p_hotspot. gs_fcat-emphasize = p_emphasize. gs_fcat-checkbox = p_checkbox. APPEND gs_fcat TO gt_fcat. ENDFORM. "csalv_set_fcat

*&---------------------------------------------------------------------*

FORM show_alv TABLES  pt_fcat
                      pt_tab
              USING   ps_layout.
*  gs_grid-edt_cll_cb = 'X'.
  gt_event-name = 'CALLER_EXIT'.   "slis_ev_caller_exit_at_start事件 gt_event-FORM = 'FM_BUTTON'.
  APPEND gt_event .

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
  EXPORTING
    i_callback_program                  = sy-repid
*    i_callback_user_command            = 'USER_COMMAND'
*    i_grid_settings                    = gs_grid
    is_layout_lvc                       = gs_layo
    it_fieldcat_lvc                     = pt_fcat[]
     it_events                          = gt_event[]
*     it_event_exit                     = gt_event_exit[]
  TABLES
    t_outtab                            = pt_tab
*   EXCEPTIONS
*     PROGRAM_ERROR                     = 1
*     OTHERS                            = 2
    .
ENDFORM.                    "csalv_set_fcat *&---------------------------------------------------------------------* *& Form user_command *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_UCOMM text * -->PS_SELFIELD text *----------------------------------------------------------------------* FORM user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield. CASE r_ucomm. WHEN '&DATA_SAVE'.

    WHEN ' ' .
    WHEN OTHERS.
  ENDCASE.

ENDFORM.                    "user_command *&---------------------------------------------------------------------* *& Form SET_PF_STATUS *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->RT_EXTAB text *----------------------------------------------------------------------* FORM set_pf_status USING rt_extab TYPE slis_t_extab.. * SET PF-STATUS '100'. ENDFORM. "SET_PF_STATUS
*&---------------------------------------------------------------------*
*&      Form  fm_button
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->E_GRID     text
*----------------------------------------------------------------------*
FORM fm_button USING e_grid TYPE slis_data_caller_exit.

  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
*   EXPORTING
*     IR_SALV_FULLSCREEN_ADAPTER       =
  IMPORTING
*     ET_EXCLUDING                     =
*     E_REPID                          =
*     E_CALLBACK_PROGRAM               =
*     E_CALLBACK_ROUTINE               =
    e_grid                           = ref_grid
*     ET_FIELDCAT_LVC                  =
*     ER_TRACE                         =
*     E_FLG_NO_HTML                    =
*     ES_LAYOUT_KKBLO                  =
*     ES_SEL_HIDE                      =
*     ET_EVENT_EXIT                    =
*     ER_FORM_TOL                      =
*     ER_FORM_EOL                      =
    .

*   CALL METHOD ref_grid->check_changed_data.
* 设置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.                    "FM_BUTTON

你可能感兴趣的:(ALV GRID 响应回车事件修改内容)