二维码

[fmalv] 在alv中着色行、列、单元格

Twilight发表于 2014-07-17 17:34Twilight 最后回复于 2014-07-17 17:34 [复制链接] 3917 0

选择屏幕
Color 1.jpg
在选择屏幕仅仅输入Column Number and color,整列被着色
Color 2.jpg
在选择屏幕仅仅输入the row Number and color,整行被着色
Color 3.jpg
在选择屏幕,输入行、列、颜色,定位到特定位置被着色
Color 4.jpg

NOTE:color的表示方法'Cxyz'
                X: Color Number(1~7)
                Y: Bold 加粗(1表示打开,0表示关闭)
                Z: Inverse 反色(1表示打开,0表示关闭)

程序代码:
  1. TABLES:spfli.

  2. TYPE-POOLS:slis.

  3. PARAMETERS:
  4. p_col TYPE i,
  5. p_row TYPE i,
  6. p_color(4) TYPE c.

  7. DATA:
  8. t_fieldcat TYPE slis_t_fieldcat_ALV,
  9. fs_fieldcat LIKE LINE OF t_fieldcat,
  10. fs_layout TYPE slis_layout_alv ,
  11. w_color(4) ,
  12. w_row TYPE i,
  13. w_fieldname(20),
  14. w_prog TYPE sy-repid.

  15. DATA:
  16. BEGIN OF t_spfli OCCURS 0,
  17. color(4),
  18. checkbox ,
  19. cell TYPE slis_t_specialcol_alv,"复杂单元格颜色特殊的结构 有三个字段
  20. carrid TYPE spfli-carrid,
  21. connid TYPE spfli-connid,
  22. cityfrom TYPE spfli-cityfrom,
  23. cityto TYPE spfli-cityto,
  24. distance TYPE spfli-distance,
  25. END OF t_spfli.

  26. DATA:
  27. fs_cell LIKE LINE OF t_spfli-cell.

  28. SELECT *
  29. FROM spfli
  30. INTO CORRESPONDING FIELDS OF TABLE t_spfli.

  31. w_color = p_color.

  32. t_spfli-color = p_color.
  33. IF p_col IS INITIAL AND p_row GT 0.
  34.   MODIFY t_spfli INDEX p_row TRANSPORTING color.
  35. ENDIF.

  36. fs_fieldcat-fieldname = 'CARRID'.
  37. fs_fieldcat-ref_tabname = 'SPFLI'.
  38. fs_fieldcat-col_pos = 1.
  39. fs_fieldcat-key = 'X'.
  40. fs_fieldcat-hotspot = 'X'.
  41. APPEND fs_fieldcat TO t_fieldcat.

  42. CLEAR fs_fieldcat .
  43. fs_fieldcat-fieldname = 'CONNID'.
  44. fs_fieldcat-ref_tabname = 'SPFLI'.
  45. fs_fieldcat-col_pos = 2.
  46. fs_fieldcat-key = 'X'.
  47. fs_fieldcat-hotspot = 'X'.
  48. APPEND fs_fieldcat TO t_fieldcat.

  49. CLEAR fs_fieldcat .
  50. fs_fieldcat-fieldname = 'DISTANCE'.
  51. fs_fieldcat-ref_tabname = 'SPFLI'.

  52. fs_fieldcat-col_pos = 3.
  53. fs_fieldcat-key = ' '.
  54. fs_fieldcat-edit = 'X'.
  55. APPEND fs_fieldcat TO t_fieldcat.

  56. CLEAR fs_fieldcat.
  57. fs_fieldcat-fieldname = 'CITYFROM'.
  58. fs_fieldcat-ref_tabname = 'SPFLI'.
  59. fs_fieldcat-col_pos = 4.
  60. fs_fieldcat-key = ' '.
  61. APPEND fs_fieldcat TO t_fieldcat.

  62. LOOP AT t_fieldcat INTO fs_fieldcat.
  63.   IF fs_fieldcat-col_pos EQ p_col.
  64.     fs_fieldcat-emphasize = p_color.
  65.     w_fieldname = fs_fieldcat-fieldname.
  66.     IF p_row IS INITIAL AND p_col GT 0.
  67.       MODIFY t_fieldcat FROM fs_fieldcat TRANSPORTING emphasize.
  68.     ENDIF.
  69.   ENDIF.
  70. ENDLOOP.

  71. fs_cell-fieldname = w_fieldname ."需要着色字段名称
  72. fs_cell-color-col = 6."颜色(1~7)
  73. fs_cell-nokeycol = 'X'."是否显示主键颜色
  74. APPEND fs_cell TO t_spfli-cell.

  75. IF p_row IS NOT INITIAL AND p_col IS NOT INITIAL.
  76.   MODIFY t_spfli INDEX p_row TRANSPORTING cell.
  77. ENDIF.

  78. fs_layout-info_fieldname = 'COLOR'."简单的单行颜色控制
  79. fs_layout-box_fieldname = 'CHECKBOX'."多选框
  80. fs_layout-coltab_fieldname = 'CELL'.“复杂的单元格颜色控制,需要内表结构
  81. fs_layout-f2code = '&ETA'."单击显示明细

  82. w_prog = sy-repid.
  83. CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
  84.   EXPORTING
  85.     i_callback_program = w_prog
  86.     is_layout          = fs_layout
  87.     it_fieldcat        = t_fieldcat
  88.   TABLES
  89.     t_outtab           = t_spfli
  90.   EXCEPTIONS
  91.     program_error      = 1
  92.     OTHERS             = 2.
  93. IF sy-subrc <> 0.
  94. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  95. * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  96. ENDIF.
复制代码
回复

使用道具 举报

快速回帖

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

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