二维码

[fmalv] 在alv中对列符合条件的特定字段的值进行着色

Twilight发表于 2014-07-17 16:11Twilight 最后回复于 2014-07-17 16:11 [复制链接] 3344 0

在这个程序中DISTANCE 字段满足一个条件被着色(如:DISTANCE值>600),下面是输出结果
spfli-distance.png

程序代码:
  1. TABLES: spfli.
  2. TYPE-POOLS:slis.

  3. DATA:
  4. t_fieldcat TYPE slis_t_fieldcat_ALV,
  5. fs_fieldcat LIKE LINE OF t_fieldcat,
  6. fs_layout TYPE slis_layout_alv ,
  7. w_color(3) ,
  8. w_fieldname(20),
  9. w_prog TYPE sy-repid.

  10. DATA:
  11. BEGIN OF t_spfli OCCURS 0,
  12. color(3),
  13. *checkbox ,
  14. cell TYPE slis_t_specialcol_alv,
  15. carrid TYPE spfli-carrid,
  16. connid TYPE spfli-connid,
  17. cityfrom TYPE spfli-cityfrom,
  18. cityto TYPE spfli-cityto,
  19. distance TYPE spfli-distance,
  20. END OF t_spfli.

  21. DATA:
  22. fs_cell LIKE LINE OF t_spfli-cell.

  23. SELECT *
  24. FROM spfli
  25. INTO CORRESPONDING FIELDS OF TABLE t_spfli.

  26. fs_fieldcat-fieldname = 'CARRID'.
  27. fs_fieldcat-ref_tabname = 'SPFLI'.
  28. fs_fieldcat-col_pos = 1.
  29. fs_fieldcat-key = 'X'.
  30. fs_fieldcat-hotspot = 'X'.
  31. APPEND fs_fieldcat TO t_fieldcat.

  32. CLEAR fs_fieldcat .
  33. fs_fieldcat-fieldname = 'CONNID'.
  34. fs_fieldcat-ref_tabname = 'SPFLI'.
  35. fs_fieldcat-col_pos = 2.
  36. fs_fieldcat-key = 'X'.
  37. fs_fieldcat-hotspot = 'X'.
  38. APPEND fs_fieldcat TO t_fieldcat.

  39. CLEAR fs_fieldcat .
  40. fs_fieldcat-fieldname = 'DISTANCE'.
  41. fs_fieldcat-ref_tabname = 'SPFLI'.
  42. fs_fieldcat-col_pos = 3.
  43. fs_fieldcat-key = ' '.
  44. fs_fieldcat-edit = 'X'.
  45. APPEND fs_fieldcat TO t_fieldcat.

  46. CLEAR fs_fieldcat.
  47. fs_fieldcat-fieldname = 'CITYFROM'.
  48. fs_fieldcat-ref_tabname = 'SPFLI'.
  49. fs_fieldcat-col_pos = 4.
  50. fs_fieldcat-key = ' '.
  51. APPEND fs_fieldcat TO t_fieldcat.

  52. LOOP AT t_spfli WHERE distance GT 600.
  53.   w_fieldname = 'DISTANCE'.
  54.   fs_cell-fieldname = w_fieldname .
  55.   fs_cell-color-col = 5.
  56.   fs_cell-nokeycol = 'X'.
  57.   APPEND fs_cell TO t_spfli-cell.
  58.   MODIFY t_spfli TRANSPORTING cell.
  59. ENDLOOP.

  60. fs_layout-info_fieldname = 'COLOR'.
  61. *fs_layout-box_fieldname = 'CHECKBOX'.
  62. fs_layout-coltab_fieldname = 'CELL'.
  63. fs_layout-f2code = '&ETA'.  "&ETA:细节  &IC1:双击

  64. w_prog = sy-repid.
  65. CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
  66.   EXPORTING
  67.     i_callback_program = w_prog
  68.     is_layout          = fs_layout
  69.     it_fieldcat        = t_fieldcat
  70.   TABLES
  71.     t_outtab           = t_spfli
  72.   EXCEPTIONS
  73.     program_error      = 1
  74.     OTHERS             = 2.
  75. IF sy-subrc <> 0.
  76. *MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  77. *WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  78. ENDIF.
复制代码
回复

使用道具 举报

快速回帖

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

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