首页 > 其他分享 >SAP: ALV GRID 控制之 单元格按钮

SAP: ALV GRID 控制之 单元格按钮

时间:2024-05-28 21:22:42浏览次数:30  
标签:gt fieldcat TYPE sflight 单元格 GRID ls ALV DATA

工作区域(或内部表)“GT_SFLIGHT”不是扁平的,或者包含参考或内部表作为组件。Is not flat, or contains

Reference or internal tables as components or internal tables as components. As components.
解决方式:
将 SELECT * FROM SFLIGHT
INTO TABLE gt_sflight UP TO 40 ROWS .
改为:
SELECT * FROM SFLIGHT
INTO CORRESPONDING FIELDS OF TABLE gt_sflight UP TO 40 ROWS .

 

1、主程序 

*&---------------------------------------------------------------------*
*& Report  Z15_23
*& 可执行程序
*&---------------------------------------------------------------------*
*&
*& 创建 ALV GRID 容器
*& 注意每个程序都需要激活方可执行
*&  实现刷新按钮的 刷新事件。
*&  实现使用字段目录
*&  使用FIELD SYMBOL 功能设置字段显示背景颜色
*&  DATA: LIGHT TYPE C. 信号灯。
*&  COLORING ROWS: 颜色行
*&  CellBtn 单元格按钮
*&---------------------------------------------------------------------*

REPORT Z15_23.

TYPE-POOLS: icon. "" 声明图标

*& 内表结构类型 :开始
TYPES: BEGIN OF t_str.
        INCLUDE STRUCTURE sflight .
TYPES: company type c LENGTH 6.
TYPES: END OF t_str.
*& 内表结构类型  :结束

DATA: CON1_REF TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
" 定义容器, 参照 自定义控件"其中自定义控件命名为CON1

DATA: G_GRID TYPE REF TO CL_GUI_ALV_GRID. "定义ALV变量,
*& 参照 CL_GUI_ALV_GRID类"

DATA: GS_VARIANT like DISVARIANT, "" 列表变量
      gs_cs_variant like disvariant.
*& DATA: GT_SFLIGHT TYPE TABLE OF SFLIGHT.  " 要显示在屏幕上的内表
DATA: gs_layout  type lvc_s_layo .
DATA: gt_toolbar TYPE  ui_functions .
DATA: gt_sort TYPE lvc_t_sort.  " 排序

DATA: gt_fieldcat type lvc_t_fcat. " 声明字段目录变量

*DATA: gt_sflight TYPE  TABLE OF T_STR.
*DATA: gt_sflight like sflight occurs 0 WITH HEADER LINE.

*DATA: BEGIN OF gt_sflight OCCURS 0 .
*        INCLUDE STRUCTURE sflight.
*DATA: light TYPE c.  " 信号灯
*DATA: linecolor TYPE c.  " 行颜色
*DATA: END OF gt_sflight.

*DATA: BEGIN OF gt_sflight OCCURS 0 .
*        INCLUDE STRUCTURE sflight.
*DATA: cellcolor TYPE lvc_t_scol . "单元格颜色
*DATA: END OF gt_sflight.

TYPES: BEGIN OF ty_sflight .
        INCLUDE STRUCTURE sflight.
TYPES: cellcolor type lvc_t_scol.
types:END OF ty_sflight. "  ty_sflight

data: ls_sflight TYPE ty_sflight occurs 0.



DATA: BEGIN OF gt_sflight OCCURS 0.
        INCLUDE STRUCTURE sflight.
DATA: CHK TYPE c.
DATA: CELLBTN TYPE lvc_t_styl.  " 单元格按钮
* DATA: cellcolor TYPE lvc_t_scol . "单元格颜色
DATA: END OF gt_sflight. " gt_sflight .

data: gs_sflight like gt_sflight.

PARAMETERS: p_var like disvariant-variant.  " 参数变量


*& 设置GRID布局
PERFORM setting_layout CHANGING gs_layout .

*& 设置单元格
PERFORM setting_cell.

*& 根据用户显示或隐藏布局按钮
PERFORM setting_toolbar.

*& 排序
PERFORM setting_sort.

*& 获得字段目录
PERFORM getting_catalog.
*& 调用设置字段目录 setting_catalog
PERFORM setting_catalog.



*& 显示检索帮助
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_var.
*&
  gs_variant-report = sy-repid.
  CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
    EXPORTING
      IS_VARIANT    = gs_variant
*     I_TABNAME_HEADER          =
*     I_TABNAME_ITEM            =
*     IT_DEFAULT_FIELDCAT       =
      I_SAVE        = 'A'
*     I_DISPLAY_VIA_GRID        = ' '
    IMPORTING
*     E_EXIT        =
      ES_VARIANT    = gs_variant
    EXCEPTIONS
      NOT_FOUND     = 1
      PROGRAM_ERROR = 2
      OTHERS        = 3.
  IF SY-SUBRC <> 0.
* Implement suitable error handling here
    p_var = gs_variant-variant .
  ENDIF.



FORM setting_layout CHANGING p_layout type lvc_s_layo.
  p_layout-cwidth_opt = 'X' . "自动调节长度
  p_layout-grid_title = 'Cell Button Test'.  "标题栏"
  p_layout-sel_mode = 'D'.  " 选择模式:可选择多行"
  p_layout-zebra = 'X'.   "指定条纹(STRIPE)属性"

*  p_layout-excp_fname = 'LIGHT'. " 信号灯 字段
*  p_layout-info_fname = 'LINECOLOR'. "颜色行
*  p_layout-ctab_fname = 'CELLCOLOR'.  "单元格颜色
  p_layout-stylefname = 'CELLBTN'.  " 单元格按钮
ENDFORM. " setting_layout.


*& 根据用户显示或隐藏布局按钮
FORM setting_toolbar.
  DATA : l_exclude TYPE UI_FUNC.

  l_exclude = cl_gui_alv_grid=>mc_fc_save_variant.
  APPEND l_exclude TO gt_toolbar.

  l_exclude = cl_gui_alv_grid=>mc_fc_maintain_variant.
  APPEND l_exclude TO gt_toolbar.
ENDFORM.  " SETTING_TOOLBAR

*& 排序 子程序
FORM setting_sort.
  DATA: ls_sort TYPE lvc_s_sort.
  ls_sort-spos = '1'.  " 排序顺序 ,整形数字
  ls_sort-fieldname = 'CARRID'.  " 排序字段名称
  ls_sort-up = 'X' . "  升序  或  LS_SORT-DOWN = 'X'  "降序
  ls_sort-subtot = 'X' .   " 显示合计

  APPEND ls_sort to gt_sort .
ENDFORM. " setting_sort.

*& 获取字段目录的子程序
FORM getting_catalog.
  DATA: lt_fieldcat type kkblo_t_fieldcat.


*& 调用函数 (函数组:SKBH)
  CALL FUNCTION 'K_KKB_FIELDCAT_MERGE'
    EXPORTING
      I_CALLBACK_PROGRAM = SY-REPID
      I_TABNAME          = 'GT_SFLIGHT'
*     I_STRUCNAME        =
      I_INCLNAME         = SY-REPID
*     I_BYPASSING_BUFFER =
*     I_BUFFER_ACTIVE    =
    CHANGING
      CT_FIELDCAT        = LT_FIELDCAT[]
* EXCEPTIONS
*     INCONSISTENT_INTERFACE       = 1
*     OTHERS             = 2
    .
  IF SY-SUBRC <> 0.
* Implement suitable error handling here
  ENDIF.

  IF SY-SUBRC EQ 0.
    "调用函数,   函数组:SLVC"
    CALL FUNCTION 'LVC_TRANSFER_FROM_KKBLO'
      EXPORTING
*       I_TECH_COMPLETE   =
*       I_STRUCTURE_NAME  =
        IT_FIELDCAT_KKBLO = lt_fieldcat[]
*       IT_SORT_KKBLO     =
*       IT_FILTER_KKBLO   =
*       IT_SPECIAL_GROUPS_KKBLO         =
*       IT_FILTERED_ENTRIES_KKBLO       =
*       IT_GROUPLEVELS_KKBLO            =
*       IS_SUBTOT_OPTIONS_KKBLO         =
*       IS_LAYOUT_KKBLO   =
*       IS_REPREP_ID_KKBLO              =
*       I_CALLBACK_PROGRAM_KKBLO        =
*       IT_ADD_FIELDCAT   =
*       IT_EXCLUDING_KKBLO              =
*       IT_EXCEPT_QINFO_KKBLO           =
      IMPORTING
        ET_FIELDCAT_LVC   = gt_fieldcat[]
*       ET_SORT_LVC       =
*       ET_FILTER_LVC     =
*       ET_SPECIAL_GROUPS_LVC           =
*       ET_FILTER_INDEX_LVC             =
*       ET_GROUPLEVELS_LVC              =
*       ES_TOTAL_OPTIONS_LVC            =
*       ES_LAYOUT_LVC     =
*       ES_VARIANT_LVC    =
*       E_VARIANT_SAVE_LVC              =
*       ES_PRINT_INFO_LVC =
*       ES_REPREP_LVC     =
*       E_REPREP_ACTIVE_LVC             =
*       ET_EXCLUDING_LVC  =
*       ET_EXCEPT_QINFO_LVC             =
*     TABLES
*       IT_DATA           =
*     EXCEPTIONS
*       IT_DATA_MISSING   = 1
*       OTHERS            = 2
      .
    IF SY-SUBRC <> 0.
* Implement suitable error handling here
    ENDIF.

  ENDIF.


ENDFORM ." getting_catalog. "

*& 设置字段目录的子程序
FORM setting_catalog.
  DATA: ls_fieldcat type lvc_s_fcat.  " 声明 字段目录变更
  FIELD-SYMBOLS: <ls_fcat> TYPE lvc_s_fcat.

*  ls_fieldcat-fieldname = 'COMPANY'.
*  ls_fieldcat-coltext = 'Company Info'.
*  ls_fieldcat-just = 'C'.
*  ls_fieldcat-key = 'X'.
*  ls_fieldcat-outputlen = '6'.
*ls_fieldcat-no_out = 'X'.  " 不在ALV GRID
*中显示,注意在第一列设置不显示,而第二列以后的列需要显示,则需要在第二列
*&说明显示字段,否则后面字段不显示。
*  APPEND ls_fieldcat to gt_fieldcat.
*
*  ls_fieldcat-fieldname = 'CARRID'.  "" 字段名称
*  ls_fieldcat-coltext = 'Carrid ID'.  "" 字段显示名称  ,承运方
*  ls_fieldcat-just = 'L'.  "" 居左
*  ls_fieldcat-KEY = 'X'.  "" 主键标记
*  ls_fieldcat-outputlen = '2'.  "" 输出宽度
*  ls_fieldcat-no_out = ''. " 显示字段"
*  APPEND ls_fieldcat TO gt_fieldcat .
*
*  ls_fieldcat-fieldname = 'CONNID'.
*  ls_fieldcat-coltext = 'Flight Number'. ""航班号 (连接号)
*  ls_fieldcat-just = 'C'.  "" 居中
*  ls_fieldcat-KEY = 'X'.
*  ls_fieldcat-outputlen = '4'.
*  APPEND ls_fieldcat TO gt_fieldcat .
*
*  ls_fieldcat-fieldname = 'PRICE'.
*  ls_fieldcat-coltext = 'Airfare'."" 文本说明(即:字段说明)
*  ls_fieldcat-just = 'R'.  " 居右
*  ls_fieldcat-KEY = ''.
*  ls_fieldcat-outputlen = '15'.
*  APPEND ls_fieldcat TO gt_fieldcat .

*& 循环内表所有字段
*  LOOP AT gt_fieldcat INTO ls_fieldcat.
*    if ls_fieldcat-fieldname = 'PRICE'.
*      ls_fieldcat-coltext = 'AIR PRICE'.
*      ls_fieldcat-just = 'C'.
*      ls_fieldcat-emphasize = 'X'." 设置单元格背景色
*      MODIFY gt_fieldcat FROM ls_fieldcat.
*    ENDIF.
*  ENDLOOP.

*& 在ALV GRID中的前四个字段是主键,颜色指定为蓝色且固定了下面主键对应的
*&   滚动条。
  LOOP AT gt_fieldcat ASSIGNING <ls_fcat>.

    if <ls_fcat>-fieldname EQ 'PRICE'.
      <ls_fcat>-key = 'X'.  " 将单价字段 设置为主键
    ENDIF.

    IF <ls_fcat>-fieldname EQ 'FLDATE'.
      <ls_fcat>-edit_mask = '____/__/__' . "设置日期格式为: YYYY/MM/DD

    ENDIF.

    IF <ls_fcat>-fieldname EQ 'CURRENCY'.
      <ls_fcat>-fix_column = 'X'. "将 币种 字段设置为固定列
      <ls_fcat>-just = 'R'. " 设置对齐方式,R:右对齐,L:左对齐,C:中间对齐。
    ENDIF.
  endloop.


ENDFORM. " setting_catalog.

FORM setting_cell.
  DATA: lt_color TYPE lvc_t_scol,
        ls_color TYPE lvc_s_scol,   "  单元格颜色 "
        lt_cellbtn type lvc_t_styl,
        ls_cellbtn type lvc_s_styl,   "  单元按钮
        ls_fieldcat TYPE lvc_s_fcat,
        l_mode TYPE raw4,
        l_type(4) TYPE c,
        index TYPE i.
*
*    " Display cell as  单元格颜色  "
*  LOOP AT gt_sflight.
*    index = index + 1 .
*    CLEAR: lt_color[].
*    LOOP AT gt_fieldcat INTO ls_fieldcat.
*      CLEAR ls_color.
*      ls_color-fname = ls_fieldcat-FIELDNAME.
*      IF ls_color-fname EQ 'PLANETYPE'. " 飞机类型
*        CASE gt_sflight-planetype.
*          WHEN '747-400'.
*            ls_color-color-col = 5.
*            ls_color-color-int = 0.
*          WHEN 'A319'.
*            ls_color-color-col = 3.
*            ls_color-color-int = 0.
*          WHEN 'A310-300'.
*            ls_color-color-col = 6.
*            ls_color-color-int = 0.
*          WHEN OTHERS.
*        ENDCASE.
*        INSERT ls_color INTO TABLE lt_color.
*      ENDIF.
*    ENDLOOP.
*
*    CLEAR: gt_sflight-cellcolor[].
*    INSERT LINES OF lt_color
*    INTO TABLE gt_sflight-cellcolor.
*    MODIFY gt_sflight INDEX index.

*  ENDLOOP.  " gt_sflight

*&  显示单元格按钮
*  Display cell as PUSHBUTTON
  CLEAR index.
  LOOP AT gt_sflight .
    index = index + 1 .
    CLEAR: lt_cellbtn[], ls_cellbtn .
    LOOP AT gt_fieldcat INTO ls_fieldcat.
      ls_cellbtn-fieldname = ls_fieldcat-fieldname.

      IF ls_cellbtn-fieldname EQ 'CHK'.
        ls_cellbtn-fieldname = 'CHK'.
        ls_cellbtn-style = cl_gui_alv_grid=>mc_style_button.

      ENDIF.
      INSERT  ls_cellbtn INTO TABLE lt_cellbtn.
    ENDLOOP.

    INSERT LINES OF lt_cellbtn INTO TABLE gt_sflight-cellbtn.
    MODIFY gt_sflight INDEX index.
    CLEAR gt_sflight.


  ENDLOOP.

ENDFORM. " setting_cell

*& 设置 事件
*FORM setting_event.
*  CREATE OBJECT event_receiver.
*  SET HANDLER event_receiver->handle_button_click FOR g_grid.
*ENDFORM. " SETTING_EVENT

*&
*CLASS lcl_dragdrop DEFINITION.
*  PUBLIC SECTION.
*    DATA: wa type ty_sflight,
*          index type i.  " index of line to be move.
*ENDCLASS. " LCL_dragdrop DEFINITION

*&
CLASS lcl_event_receiver DEFINITION.
  PUBLIC SECTION.
    " 声明双击事件方法
    METHODS: handle_double_click
     FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
    IMPORTING e_row e_column.
    " 声明 工具栏事件方法
    METHODS: handle_toolbar
      FOR EVENT toolbar OF CL_GUI_ALV_GRID
      IMPORTING e_object  e_interactive .

    ""&声明工具栏的刷新按钮事件方法
    METHODS: handle_command
      FOR EVENT user_command OF CL_GUI_ALV_GRID
      IMPORTING e_ucomm.

    ""& 声明 拖放方法(Drag & Drop)
    METHODS:
     handle_alv_drag
     FOR EVENT ondrag OF CL_GUI_ALV_GRID
     IMPORTING e_row e_column e_dragdropobj,

     handle_alv_drop
      FOR EVENT ondrop OF CL_GUI_ALV_GRID
      IMPORTING e_row e_column e_dragdropobj.

    "  单元格按钮点击事件
    METHODS: handle_button_click
    FOR EVENT button_click OF CL_GUI_ALV_GRID
     IMPORTING es_col_id es_row_no.


  PRIVATE SECTION. "

ENDCLASS.

CLASS lcl_event_receiver IMPLEMENTATION.
  METHOD handle_double_click. "双击事件方法的实现"
    LEAVE TO SCREEN 0 .
  ENDMETHOD.

  " 工具栏事件方法的实现
  METHOD handle_toolbar .
    DATA: ls_toolbar TYPE stb_button.

    CLEAR ls_toolbar.
    ls_toolbar-butn_type = 3.
    APPEND ls_toolbar TO e_object->mt_toolbar.

    CLEAR ls_toolbar.
    ls_toolbar-function = 'RESH'.
    ls_toolbar-icon = icon_refresh.
    ls_toolbar-quickinfo = 'Refresh'.
    ls_toolbar-text = ''.
    ls_toolbar-disabled = ''.
    APPEND ls_toolbar TO e_object->mt_toolbar.  " 增加一个 刷新按钮

  ENDMETHOD.  "" handle_toolbar  ”


  "& 工具栏刷新按钮的刷新方法的实现
  METHOD handle_command.
    DATA: l_scroll type lvc_s_stbl.

    CASE e_ucomm.
      WHEN 'RESH'.
        SELECT * FROM SFLIGHT
          INTO CORRESPONDING FIELDS OF TABLE gt_sflight UP TO 40 ROWS .
        "" 刷新时全表查询
        l_scroll-row = 'X'.
        l_scroll-col = 'X'.

        CALL METHOD g_grid->refresh_table_display
          EXPORTING
            i_soft_refresh = ''
            is_stable      = l_scroll.
    ENDCASE.
  ENDMETHOD. " handle_command.

  METHOD handle_alv_drag.
*    DATA: l_dragdrop TYPE REF TO lcl_dragdrop.


  ENDMETHOD. " handle_alv_drag.

  METHOD handle_alv_drop.
*    DATA: l_dragdrop TYPE REF TO lcl_dragdrop,
*          l_drop_index type i,
*          l_scroll type lvc_s_stbl.

    " 刷新 ALV GRID 组件
*    l_scroll-row = 'X'.
*    l_scroll-col = 'X'.

*     CATCH SYSTEM-EXCEPTIONS move_cast_error = 1.
*       l_dragdrop ?= e_dragdropobj->object.
*       CALL METHOD g_grid->refresh_table_display
*       EXPORTING
*         i_soft_refresh = 'X'
*         is_stable = l_scroll.
*     ENDCATCH.
    IF sy-subrc <> 0.
      " if anything went wrong aborting the drap and drop operation:
      CALL METHOD e_dragdropobj->abort.
    ENDIF.
  ENDMETHOD. " handle_alv_drop


*  单元格按钮点击事件
  METHOD handle_button_click.
    CLEAR gt_sflight.
    READ TABLE gt_sflight INDEX es_row_no-row_id into gs_sflight.
    IF SY-SUBRC EQ 0.
      MESSAGE  gs_sflight-carrid TYPE 'I'.  " 弹窗显示信息
    ENDIF.
  ENDMETHOD. "  handle_button_click

ENDCLASS.      " LCL_event_receiver.


DATA: event_receiver type ref to lcl_event_receiver .



*& 查询数据,然后调用屏幕100.
START-OF-SELECTION.
  SELECT * FROM SFLIGHT
    INTO CORRESPONDING FIELDS OF TABLE GT_SFLIGHT UP TO 90 ROWS.
*  PERFORM SETTING_CELL. " 调用 设置单元格 子程序 "
*  "信号灯"
*  LOOP AT gt_sflight.
*    IF gt_sflight-seatsocc <= 30.
*      gt_sflight-light = '1'.   " 1: 红灯
*    ELSEIF gt_sflight-seatsocc <= 50.
*      gt_sflight-light = '2'.  "2: 黄灯
*    ELSE.
*      gt_sflight-light = '3'. ""3:绿灯
*
*    ENDIF.
*
*    "设置行颜色
*    CASE gt_sflight-carrid.
*      WHEN 'AA' .  " 蓝色
*        gt_sflight-linecolor = 'C100'.
*      WHEN 'AZ'. " 黄色
*        gt_sflight-linecolor = 'C300'.
*      WHEN 'DL' . " 绿色
*        gt_sflight-linecolor = 'C500'.
*    ENDCASE. "设置行颜色
*    MODIFY gt_sflight.
*  ENDLOOP.   " 信号灯
  "*& 设置单元格属性
  PERFORM SETTING_CELL.
  CALL SCREEN 100.

  gs_variant-report = sy-repid.
  gs_variant-username = sy-uname.

*& 输出前事件包含文件
*& 创建 AVL控件
  INCLUDE Z15_23_PBO.
*  INCLUDE Z15_22_PBO.


*& 输入后 事件包含文件
*&  PAI
  INCLUDE Z15_23_PAI.
*  INCLUDE Z15_22_PAI.

  

2、 包含子程序 PAI 

*&---------------------------------------------------------------------*
*&  包含                Z15_23_PAI
*&---------------------------------------------------------------------*
*& PAI
MODULE user_command_0100 INPUT.
  DATA: l_row type i,
        l_value type c,
        l_col type i,
        ls_row type lvc_s_row,
        ls_col type lvc_s_col,
        ls_roid type lvc_s_roid.

  DATA: ls_scroll type lvc_s_stbl.
  ls_scroll-row = 'X'.
  ls_scroll-col = 'X'.

*& 模式-> 选择:ABAP对象模式 ,(继续)-> 调用方法,
*&    在"实例"栏=G_GRID, 类/接口栏= CL_GUI_ALV_GRID,
*方法栏= get_current_cell
  CALL METHOD G_GRID->GET_CURRENT_CELL
    IMPORTING
      E_ROW     = l_row
      E_VALUE   = l_value
      E_COL     = l_col
      ES_ROW_ID = ls_row
      ES_COL_ID = ls_col
      ES_ROW_NO = ls_roid.

*&   重新查询已经显示在ALV的输出表时使用的方法。
  CALL METHOD G_GRID->REFRESH_TABLE_DISPLAY
    EXPORTING
      IS_STABLE      = ls_scroll
      I_SOFT_REFRESH = 'X'
*    EXCEPTIONS
*     FINISHED       = 1
*     others         = 2
    .
  IF SY-SUBRC <> 0.
*   Implement suitable error handling here
  ENDIF.


ENDMODULE. " user_command_0100.

  

2.1 包含子程序 PBO  

*----------------------------------------------------------------------*
***INCLUDE Z15_23_PBO.
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  INIT_CON  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE INIT_CON OUTPUT.
*& 1、创建容器对象
  IF CON1_REF IS INITIAL.  " 如果容器是空的,创建容器对象"
    CREATE OBJECT CON1_REF
      EXPORTING
        CONTAINER_NAME = 'CON1'.

*& 2、创建 ALV GRID 控件 对象
    CREATE OBJECT G_GRID
      EXPORTING
        I_PARENT = CON1_REF.
*      EXCEPTIONS
*        error_cnt1_create = 1
*        error_cnt1_init   = 2
*        error_cnt1_link   = 3
*        error_dp_create   = 4
*        OTHERS            = 5.
*    if sy-subrc <> 0.
*      MESSAGE ID sy-msgid TYPE sy-msgty number sy-msgno
*      with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 .
*    endif.
  ENDIF. "  CON1_REF"

*& #REGION: 注册事件
  CREATE OBJECT event_receiver.
* 注册事件Handler方法
  SET HANDLER event_receiver->handle_double_click FOR g_grid .
*&
*& 注册刷新按钮事件 方法
  SET HANDLER event_receiver->handle_toolbar FOR g_grid.

*& 注册工具栏刷新按钮的刷新事件 方法
  SET HANDLER event_receiver->handle_command FOR g_grid.

*& 注册 拖放事件 方法
  SET HANDLER event_receiver->handle_alv_drop for g_grid.
  SET HANDLER event_receiver->handle_alv_drag for g_grid.

*&   单元格按钮
*  CREATE OBJECT event_receiver.
  SET HANDLER event_receiver->handle_button_click FOR g_grid.



*& #ENDREGION: 注册事件

*& 模式-> 选择:ABAP对象模式 ,(继续)-> 调用方法, 在接口栏=G_GRID,
*&  类/接口栏= CL_GUI_ALV_GRID, 方法栏= SET_TABLE_FOR_FIRST_DISPLAY
*& 3、 ALV GRID显示数据方法
  CALL METHOD g_grid->set_table_for_first_display
    EXPORTING
      I_STRUCTURE_NAME     = 'SFLIGHT'
      i_save               = 'A'
      is_variant           = gs_variant
      i_default            = ' '
      is_layout            = gs_layout
      it_toolbar_excluding = gt_toolbar
    CHANGING
      It_OUTTAB            = GT_SFLIGHT[] " 若不带表头,则直接使用内表即可(即:GT_SFLGITH),
*& 定义内表时若带有表头,则调用ALV时需要传递表体。
      it_fieldcatalog      = gt_fieldcat   " 字段目录
      it_sort              = gt_sort.

ENDMODULE.                 " INIT_CON  OUTPUT

*CALL METHOD G_GRID->SET_TABLE_FOR_FIRST_DISPLAY
*  EXPORTING
*    I_BUFFER_ACTIVE               =
*    I_BYPASSING_BUFFER            =
*    I_CONSISTENCY_CHECK           =
*    I_STRUCTURE_NAME              =
*    IS_VARIANT                    =
*    I_SAVE                        =
*    I_DEFAULT                     = 'X'
*    IS_LAYOUT                     =
*    IS_PRINT                      =
*    IT_SPECIAL_GROUPS             =
*    IT_TOOLBAR_EXCLUDING          =
*    IT_HYPERLINK                  =
*    IT_ALV_GRAPHICS               =
*    IT_EXCEPT_QINFO               =
*    IR_SALV_ADAPTER               =
*  CHANGING
*    IT_OUTTAB                     =
*    IT_FIELDCATALOG               =
*    IT_SORT                       =
*    IT_FILTER                     =
*  EXCEPTIONS
*    INVALID_PARAMETER_COMBINATION = 1
*    PROGRAM_ERROR                 = 2
*    TOO_MANY_LINES                = 3
*    others                        = 4
*        .
*IF SY-SUBRC <> 0.
** Implement suitable error handling here
*ENDIF.

  

效果图:

 

标签:gt,fieldcat,TYPE,sflight,单元格,GRID,ls,ALV,DATA
From: https://www.cnblogs.com/samrv/p/18218943

相关文章

  • JVM调优维护常用工具之VisualVM 可视化优化工具
    VisualVM是一个工具,它提供了一个可视界面,用于查看Java虚拟机(JavaVirtualMachine,JVM)上运行的基于Java技术的应用程序(Java应用程序)的详细信息。VisualVM对JavaDevelopmentKit(JDK)工具所检索的JVM软件相关数据进行组织,并通过一种使您可以快速查看有关多个......
  • WPF DataGrid使用 自动显示行号、全选、三级联动、拖拽
    1.DataGrid的使用自动显示行号(修复删除行时行号显示不正确)  ViewCodedgTool.LoadingRow+=newEventHandler<DataGridRowEventArgs>(dgTool_LoadingRow);dgTool.UnloadingRow+=newEventHandler<DataGridRowEventArgs>(dgTool_UnloadingRow);voi......
  • Delphi CxGrid/CxDBTreeList等将排序筛选条件改为中文方法
    Delphi CxGrid/CxDBTreeList等将排序筛选条件改为中文方法一、加入cxLocalizer控件二、在FormCreate里加入以下代码procedureTForm1.FormCreate(Sender:TObject);begin cxLocalizer1.LoadFromResource(HInstance); cxLocalizer1.Language:='中文(简体,中国)';......
  • Excel工作表单元格单击选中事件,VBA动态数值排序
    Excel工作表单元格单击选中事件,VBA动态数值排序(WX公众号:Excel潘谆白说VBA)文章目录前言一、运行效果二、代码前言面对每月的消费账单,面对月底待还的信用卡或花呗,面对不足三位数的余额,你是否怀疑过账单自己的消费。你是否因此开始记账,每个月记流水,想知道当月......
  • Grid 布局-容器项
    grid网格布局是一个用于web的二维布局系统,多行多列.flex单行布局则更倾向于一维布局,一行或者一列.Grid重点只是用表格进行排版哈,横向内容直接无关联哦.容器项子项布局应用定义网格及fr单位显式与隐式网格叠加布局合并网格及命名基于线的元素放置......
  • EXCEL单元格,只有双击后才会变正常
    选中整列,“数据”--->“分列”--->“分隔符号”--->“下一步”--->“tab键”--->“下一步”--->“常规”--->“完成”如经过以上步骤后数值未能正常显示,选中整列,“设置单元格格式”---->“1234”---->小数位数改为“0”--->“确定”。......
  • .net 直接在DataGridView控件中修改单元格数据,并保存到数据库
    1.获取datagridview单元格修改的内容//单元格的值发生改变时触发事件privatevoiddataGridView1_CellValueChanged(objectsender,DataGridViewCellEventArgse){//获取当前行绑定的内容AppraisalBasesitem=(AppraisalBases)dataGridView1.Rows[e.RowIndex].Da......
  • SAP:ALV GRID 信号灯例子
    SAP: ALVGRID 信号灯 例子Exception 用图形分段显示阶段性数据。ALV 字段由信号灯显示且根据特定字段变更其颜色。这个属性可以使最终用户容易识别紧急性、重要性数据。例如,在库存管理中将安全库存时设置为绿色,危险时为花色,超过安全库存时为红色。 书中仅写出核心代......
  • DataGridView 控件入门
    常用属性和方法ContextMenuStrip属性:当用户点击鼠标右键时(设置和contextMenuStrip挂钩)MultiSelect属性是否可以多行选择SelectionMode属性:设置选中方式,比如是否选中一整行(设置为FullRowSelect)Dock属性:设置显示位置AllowUserToAddRows属性:取......
  • DataGridView treeview控件入门
    隐藏treeview相关联的线连接ShowLines设置为false设置行高:itemHeight设置在窗体的位置:Dock设置是否随窗体大小改变而改变:Anchor设置被选中后,是否占满整行:FullRowSelect被点击后的事件:AfterSelectprivatevoidtreeView_AfterSelec......