ALV面向对象方法研究:设定满足条件的单元格的颜色(四)
还是继续本话题。
本文讲解如何设定满足条件的单元格的颜色。比如在一张报表里,把成绩这一列小于60分的单元格设定为红色。这种功能很常见!
1、首先在定义内标的时候记得增加一个栏位放置颜色:
....
CELLCOLOR TYPE LVC_T_SCOL,
...
2、在内表修改的时候,将这个栏位附上内容:
DATA: W_CELLCOLOR TYPE LVC_S_SCOL.
IF IT_SFLIGHT-PRICE <= 1000. "数值小于1000的加红色
CLEAR IT_SFLIGHT-COLOR.
W_CELLCOLOR-FNAME = 'PRICE'. "加颜色的栏位
W_CELLCOLOR-COLOR-COL = '6'. "红色
W_CELLCOLOR-COLOR-INT = '1'. "颜色加深 0代表不加深
APPEND W_CELLCOLOR TO IT_SFLIGHT-CELLCOLOR.
ENDIF.
3、设定ALV格式的时候:
*&---------------------------------------------------------------------*
*& FORM PREPARE_LAYOUT
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* -->PS_LAYOUT TEXT
*----------------------------------------------------------------------*
FORM PREPARE_LAYOUT CHANGING PS_LAYOUT TYPE LVC_S_LAYO.
PS_LAYOUT-ZEBRA = 'X' .
PS_LAYOUT-GRID_TITLE = TITLE .
PS_LAYOUT-SMALLTITLE = 'X' .
PS_LAYOUT-SEL_MODE = 'A'.
PS_LAYOUT-INFO_FNAME = 'COLOR'.
PS_LAYOUT-CTAB_FNAME = 'CELLCOLOR'. "一定要大写
PS_LAYOUT-CWIDTH_OPT = 'X'.
PS_LAYOUT-DETAILINIT = 'X'.
ENDFORM. " PREPARE_LAYOUT
效果如下图:
-----------------------------------------------------------------------------------------------------------------------------
SAP ALL进行时...!
注:本文系原创,如要转载请务必保持原文一致并注明作者(SAP梦心)及出处(博客地址:http://www.cnblogs.com/saper/),违者将会被追究相关责任,谢谢!