[REUSE_ALV_GRID_DISPLAY]如何指定单元格颜色详解编程语言

下面简单介绍一下使用REUSE_ALV_GRID_DISPLAY函数时,如何设定单元格颜色,方法比较简单,直接上代码:

REPORT ztest_cell_color_grid_alv. 
TYPE-POOLS: slis. 
DATA: BEGIN OF git_flight OCCURS 0, 
        carrid   LIKE sflight-carrid, 
        connid   LIKE sflight-connid, 
        fldate   LIKE sflight-fldate, 
        seatsmax LIKE sflight-seatsmax, 
        seatsocc LIKE sflight-seatsocc, 
        color    TYPE lvc_t_scol,  "保存颜色的字段 
      END OF git_flight. 
DATA: git_fieldcat TYPE  slis_t_fieldcat_alv, 
      gwa_layout   TYPE  slis_layout_alv. 
DATA: gwa_col    TYPE lvc_s_scol, 
      git_coltab TYPE lvc_t_scol, 
      gwa_color  TYPE lvc_s_colo. 
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' 
  EXPORTING 
    i_program_name         = sy-repid 
    i_internal_tabname     = 'GIT_FLIGHT' 
    i_inclname             = sy-repid 
  CHANGING 
    ct_fieldcat            = git_fieldcat 
  EXCEPTIONS 
    inconsistent_interface = 1 
    program_error          = 2. 
 
SELECT carrid 
       connid 
       fldate 
       seatsmax 
       seatsocc 
FROM sflight 
INTO CORRESPONDING FIELDS OF TABLE git_flight 
UP TO 20 ROWS. 
 
* 设定颜色 
gwa_color-col = '5'. 
gwa_color-int = '0'. 
gwa_color-inv = '0'. 
LOOP AT git_flight. 
* 指定第一行 SEATSOCC列单元格颜色 
  IF sy-tabix = 1. 
    gwa_col-fname = 'SEATSOCC'. 
    gwa_col-color = gwa_color. 
    APPEND gwa_col TO git_coltab. 
    CLEAR gwa_col. 
    git_flight-color = git_coltab. 
    MODIFY  git_flight. 
  ENDIF. 
ENDLOOP. 
gwa_layout-coltab_fieldname = 'COLOR'. 
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' 
  EXPORTING 
    i_callback_program = sy-repid 
    is_layout          = gwa_layout 
    it_fieldcat        = git_fieldcat 
  TABLES 
    t_outtab           = git_flight 
  EXCEPTIONS 
    program_error      = 1.

测试结果:

第一行的最后一列单元格颜色变为浅绿色。

[REUSE_ALV_GRID_DISPLAY]如何指定单元格颜色详解编程语言

以上。

原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/19294.html

(0)
上一篇 2021年7月19日
下一篇 2021年7月19日

相关推荐

发表回复

登录后才能评论