二维码

[fmalv] ALV中行、列、单元格颜色控制小案例

Twilight发表于 2015-09-18 11:07Twilight 最后回复于 2015-09-18 11:07 [复制链接] 10791 0

ALV颜色控制可以分为:行颜色、列颜色、单元格颜色

程序代码:
  1. *&---------------------------------------------------------------------*
  2. *& Create: 蜡笔小彭 by 2010.01.05
  3. *&
  4. *&---------------------------------------------------------------------*
  5. TYPE-POOLS:slis.

  6. TYPES:
  7.   BEGIN OF typ_main,
  8.     color1(10)  TYPE c,
  9.     color2(10)  TYPE c,
  10.     color3(10)  TYPE c,
  11.     color4(10)  TYPE c,
  12.     color5(10)  TYPE c,
  13.     color6(10)  TYPE c,
  14.     color7(10)  TYPE c,
  15.     color8(10)  TYPE c,
  16.     color9(10)  TYPE c,
  17.     color10(10) TYPE c,
  18.     color11(10) TYPE c,
  19.     color12(10) TYPE c,
  20.     color13(10) TYPE c,
  21.     color14(10) TYPE c,
  22.     color15(10) TYPE c,
  23.     color16(10) TYPE c,
  24.     color17(10) TYPE c,
  25.     color18(10) TYPE c,
  26.     color19(10) TYPE c,
  27.     color20(10) TYPE c,
  28.     color21(10) TYPE c,
  29.     color22(10) TYPE c,
  30.     color23(10) TYPE c,
  31.     color24(10) TYPE c,
  32.     color25(10) TYPE c,
  33.     color26(10) TYPE c,
  34.     color27(10) TYPE c,
  35.     color28(10) TYPE c,
  36.     rowcolor(4) TYPE c,
  37.     cellcolors  TYPE lvc_t_scol,  " 单元格颜色
  38.   END OF typ_main.
  39. DATA: w_main TYPE typ_main.
  40. DATA: t_main TYPE TABLE OF typ_main.

  41. DATA: l_line(2) TYPE c .
  42. DATA: l_column(2) TYPE c .

  43. DATA: l_mod TYPE c.
  44. DATA: l_int TYPE c.
  45. DATA: l_num TYPE n LENGTH 2.
  46. DATA: fieldname TYPE string .
  47. DATA: ls_cellcolor TYPE lvc_s_scol.

  48. DATA: w_fcat TYPE slis_fieldcat_alv,            "ALV显示字段结构
  49.       w_layo TYPE slis_layout_alv,              "ALV显示风格结构
  50.       i_fcat TYPE slis_t_fieldcat_alv.

  51. SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
  52. PARAMETERS: p_line   RADIOBUTTON GROUP grp1 DEFAULT 'X',
  53.             p_column RADIOBUTTON GROUP grp1,
  54.             p_cell   RADIOBUTTON GROUP grp1.
  55. SELECTION-SCREEN END OF BLOCK b1.

  56. START-OF-SELECTION .
  57.   CLEAR: l_line,l_column .
  58.   FIELD-SYMBOLS:<fs>.

  59.   DO 28 TIMES.
  60. *    CLEAR: w_main.
  61.     l_int = l_line DIV 4 . " 整数
  62.     l_int = l_int + 1 .
  63.     l_mod = l_line MOD 4 . " 余数
  64.     l_num+0(1) = l_mod DIV 2 .
  65.     l_num+1(1) = l_mod MOD 2 .
  66.     CONCATENATE 'C' l_int l_num INTO w_main-rowcolor.

  67.     l_line = l_line + 1 .
  68.     CLEAR: l_column.
  69.     DO 28 TIMES.
  70.       l_column = l_column + 1.
  71.       CONCATENATE 'W_MAIN-COLOR' l_column INTO fieldname .
  72.       ASSIGN (fieldname) TO <fs>.
  73.       CONCATENATE '第' l_line '行' '第' l_column '列' INTO <fs> .
  74.       IF l_line = l_column .
  75.         CLEAR: ls_cellcolor.
  76.         CONCATENATE 'COLOR' l_column INTO fieldname.
  77.         ls_cellcolor-fname = fieldname .
  78.         ls_cellcolor-color-col = w_main-rowcolor+1(1).
  79.         ls_cellcolor-color-int = w_main-rowcolor+2(1).
  80.         ls_cellcolor-color-inv = w_main-rowcolor+3(1).
  81.         APPEND ls_cellcolor TO w_main-cellcolors[] .
  82.       ENDIF.
  83.     ENDDO.
  84.     APPEND w_main TO t_main .
  85.   ENDDO.

  86. END-OF-SELECTION .
  87.   CLEAR: i_fcat,w_fcat,l_line .
  88.   DO 28 TIMES.
  89.     IF p_column = 'X'.
  90.       l_int = l_line DIV 4 . " 整数
  91.       l_int = l_int + 1 .
  92.       l_mod = l_line MOD 4 . " 余数
  93.       l_num+0(1) = l_mod DIV 2 .
  94.       l_num+1(1) = l_mod MOD 2 .
  95.       CONCATENATE 'C' l_int l_num INTO w_fcat-emphasize.
  96.     ENDIF.

  97.     l_line = l_line + 1.
  98.     CONCATENATE 'COLOR' l_line INTO fieldname .
  99.     w_fcat-fieldname = fieldname .
  100.     w_fcat-seltext_l = fieldname .
  101.     w_fcat-outputlen = 10.
  102.     APPEND w_fcat TO i_fcat.
  103.   ENDDO.

  104.   IF p_line = 'X'.
  105.     w_layo-info_fieldname = 'ROWCOLOR'.
  106.   ELSEIF p_cell = 'X'.
  107.     w_layo-coltab_fieldname = 'CELLCOLORS'.
  108.   ENDIF.


  109.   CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  110.     EXPORTING
  111.       i_callback_program = sy-repid
  112.       is_layout          = w_layo
  113.       it_fieldcat        = i_fcat
  114.       i_default          = 'X'
  115.       i_save             = 'U'
  116.     TABLES
  117.       t_outtab           = t_main
  118.     EXCEPTIONS
  119.       program_error      = 1
  120.       OTHERS             = 2.
复制代码


程序测试:
ALV单元格颜色.jpg
回复

使用道具 举报

快速回帖

本版积分规则
您需要登录后才可以回帖 登录 | 注册有礼

快速回复 返回顶部 返回列表