2011年3月30日 星期三

[Code] ALV Colorful

The example code for how to fill color to alv list columns, lines and fields.

Columns

1. Only with your alv_field define.
*
  CLEAR alv_field.
  l_count = l_count + 1.
  alv_field-col_pos       = l_count.
  alv_field-fieldname     = 'XBLNR'.
  alv_field-EMPHASIZE     = 'X'.
  APPEND alv_field TO alv_t_field.
*
* EMPHASIZE:
*     SPACE, 'X' or 'Cxyz' (x:'1'-'9'; y,z: '0'=off '1'=on)
*
* If the field is set to 'X', the ALV uses a pre-defined color for highlighting the column. If the 
* character field begins with 'C' (color code), the remaining numbers have the following meaning:
* 
*     x: color number 
*     y: intensified display on/off
*     y: inverse display on/off
*

Lines

1. In your ALV Internal Table definition, you neet add a field names color.
        [......]
        color TYPE slis_t_specialcol_alv,
      END OF gt_itab.
2. Your can define a internal table with names linecolor.
DATA: linecolor TYPE slis_specialcol_alv.
3. Calculate color in loop at gt_itab like below.
    [......]
    IF gt_itab-profb < 0.
      CLEAR: linecolor.
      linecolor-color-col = 6.
      APPEND linecolor TO gt_itab-color.
    ENDIF.
*   Update
    MODIFY gt_itab.
  ENDLOOP.
4. Your need to set layout like below.
  alv_layout-coltab_fieldname  = 'COLOR'.

Fields

All same the Lines, except for step 3 to assign fieldname
    [......]
    IF gt_itab-profb < 0.
      CLEAR: linecolor.
      linecolor-fieldname = 'PROFB'.
      linecolor-color-col = 6.
      APPEND linecolor TO gt_itab-color.
    ENDIF.
*   Update
    MODIFY gt_itab.
  ENDLOOP.

Color mix

When you assign a row's color append to color field, further assign color to same row's field, then this field's color will mixed to unexpectedly color.

沒有留言:

張貼留言