ALVは標準ボタンにカスタムボタンを追加し、テキストと機能の切り替えを実現する

4542 ワード

  • ボタン追加とボタン応答を実現するクラスメソッドを作成する:
    *&---------------------------------------------------------------------*
    *&                   ZSDF011_CLASS
    *&---------------------------------------------------------------------*
    CLASS lcl_handle_cell_events DEFINITION DEFERRED.
    *---------------------------------------------------------------------*
    *       CLASS lcl_handle_events DEFINITION
    *---------------------------------------------------------------------*
    * define a local class for handling events of cl_salv_table
    *---------------------------------------------------------------------*
    CLASS lcl_handle_cell_events DEFINITION.
      PUBLIC SECTION.
        METHODS:
          on_double_cell_click FOR EVENT double_click OF cl_gui_alv_grid
            IMPORTING e_row e_column es_row_no.
        METHODS:mt_toolbar_add FOR EVENT toolbar OF cl_gui_alv_grid
            IMPORTING e_object.
        METHODS:mt_func_event FOR EVENT user_command OF cl_gui_alv_grid
            IMPORTING e_ucomm.
    ENDCLASS.
    *---------------------------------------------------------------------*
    *       CLASS lcl_handle_events IMPLEMENTATION
    *---------------------------------------------------------------------*
    * implement the events for handling the events of cl_salv_table
    *---------------------------------------------------------------------*
    CLASS lcl_handle_cell_events IMPLEMENTATION.
      METHOD on_double_cell_click.
        DATA ls_yck TYPE zsds087.
        CLEAR:gv_kunag,gv_kunrg,ls_yck,gv_mark.
        READ TABLE gt_alv_yck INTO ls_yck INDEX es_row_no-row_id. " 
        gv_kunag = ls_yck-kunag.
        gv_kunrg = ls_yck-kunrg.
        PERFORM frm_get_czjldata USING gv_kunag gv_kunrg.
        PERFORM frm_get_djqddata USING gv_kunag gv_kunrg.
        PERFORM frm_diaplay_alv_refresh.
      ENDMETHOD.
      METHOD mt_toolbar_add.
        DATA ls_button TYPE stb_button.
        IF gv_mark = 'X'.
          CLEAR ls_button.
          ls_button-butn_type = '3'.
          APPEND ls_button TO e_object->mt_toolbar.
          CLEAR ls_button.
          ls_button-function = 'CHANGE'.
          ls_button-icon     = '@BB@'.
          ls_button-text     = ' '.
          APPEND ls_button TO e_object->mt_toolbar.
        ELSE.
          CLEAR ls_button.
          ls_button-butn_type = '3'.
          APPEND ls_button TO e_object->mt_toolbar.
          CLEAR ls_button.
          ls_button-function = 'ECHANGE'.
          ls_button-icon     = '@BB@'.
          ls_button-text     = ' '.
          APPEND ls_button TO e_object->mt_toolbar.
        ENDIF.
      ENDMETHOD.
      METHOD mt_func_event.
        DATA:lv_kunag TYPE kna1-kunnr,
             lv_kunrg TYPE kna1-kunnr.
        CASE e_ucomm.
          WHEN 'CHANGE'.
            CLEAR:lv_kunag,lv_kunrg,gt_alv_czjl[],gt_alv_djqd,gv_mark.
            lv_kunag = gv_kunag.
            lv_kunrg = gv_kunrg.
            PERFORM frm_get_czjldata USING lv_kunag lv_kunrg.
            PERFORM frm_get_djqddata USING lv_kunag lv_kunrg.
            PERFORM frm_diaplay_alv_refresh.
          WHEN 'ECHANGE'.
            CLEAR:lv_kunag,lv_kunrg,gt_alv_czjl[],gt_alv_djqd[],gv_mark.
            gv_mark = 'X'.
            lv_kunag = gv_kunag.
            PERFORM frm_get_czjldata USING lv_kunag lv_kunrg.
            PERFORM frm_get_djqddata USING lv_kunag lv_kunrg.
            PERFORM frm_diaplay_alv_refresh.
          WHEN OTHERS.
        ENDCASE.
      ENDMETHOD.
    ENDCLASS.
    
    DATA gr_events TYPE REF TO lcl_handle_cell_events." 
  • クラスおよびメソッドで使用されるグローバル変数を定義する:
    DATA: gt_container TYPE REF TO cl_gui_custom_container,
          gt_container1 TYPE REF TO cl_gui_container,
          gt_container2 TYPE REF TO cl_gui_container,
          gt_container3 TYPE REF TO cl_gui_container.
    DATA: gt_alv_grid1 TYPE REF TO cl_gui_alv_grid,
          gt_alv_grid2 TYPE REF TO cl_gui_alv_grid,
          gt_alv_grid3 TYPE REF TO cl_gui_alv_grid.
    
    DATA:gv_kunag      TYPE kna1-kunnr,     " 
         gv_kunrg      TYPE kna1-kunnr,     " 
         gv_mark(1)    TYPE c.
  • 定義されたクラスメソッドをクラスに割り当てる使用:
      CLEAR gwa_layout_lvc-grid_title.
      gwa_layout_lvc-grid_title = ' ' .
    
      CREATE OBJECT gr_events.
      SET HANDLER gr_events->mt_toolbar_add  FOR gt_alv_grid2.
      SET HANDLER gr_events->mt_func_event  FOR gt_alv_grid2.
    
      CALL METHOD gt_alv_grid2->set_table_for_first_display
        EXPORTING
          is_layout            = gwa_layout_lvc
          it_toolbar_excluding = gt_exclude
          i_save               = 'A'
        CHANGING
          it_outtab            = gt_alv_czjl
          it_fieldcatalog      = gt_fieldcat_czjllvc.
  • このようにカスタマイズボタンおよびその機能は
  • を実現する.