登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

原来为了你

我的人生就是要一次次的超越

 
 
 

日志

 
 
 
 

alv 颜色  

2011-01-07 16:13:30|  分类: ALV |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

alv的颜色分为行的颜色、列的颜色和cell的颜色。

alv 颜色 - 2006057145 - 原来为了你 
*------- 行的颜色 --------------------------------------------------------
*  需要在要显示的内表中添加一个字段放置颜色信息,比如color(4) type c .
itab-color 'C700'.

*此外,还要根据采用的fm方式还是class方式设置一下显示颜色
*---fm方式: 
datals_layout type slis_layout_alv.
ls_layout-info_fieldname 'COLOR'.
call function 'REUSE_ALV_GRID_DISPLAY'
  exporting
    is_layout   ls_layout
    it_fieldcat lt_fieldcat
  tables
    t_outtab    itab.

*---class方式:  
sla-info_fname 'COLOR'.
call method go_grid->set_table_for_first_display
  exporting
    is_variant                    gs_variant
    i_save                        'A'
    is_layout                     sla
  changing
    it_outtab                     itab[]
    it_fieldcatalog               gt_fieldcat[]
  exceptions
    invalid_parameter_combination 1
    program_error                 2
    too_many_lines                3
    others                        4.


*------- 列颜色 ---------------------------------------------------------
很简单,如:
datait_fieldcat TYPE slis_t_fieldcat_alv.
it_fieldcat-EMPHASIZE 'C500'.

*------- 单元格颜色 -------------------------------------------------------

1在输出内表中添加字段   cellcolor TYPE lvc_t_scol 这是一个内表,用来存储单元格的颜色。

2在内表循环中给这个内表赋值,示例代码如下:
      DATA wa_cellcolor TYPE lvc_s_scol" 单元格颜色结构
      wa_cellcolor-fname 'TEXT_DECIMAL1'.
      wa_cellcolor-color-col '6'.
      wa_cellcolor-color-int '1'.
      wa_cellcolor-color-inv '0'.
      APPEND wa_cellcolor TO gt_output-cellcolor.

3最关键的一点,在layout结构中设定颜色字段的名字,代码如下:
      is_layout-coltab_fieldname 'CELLCOLOR'.  " 单元格颜色字段

总结:当同时设定了行颜色和列颜色后,行颜色会覆盖列颜色,有的时候用户不希望这种结果的出现,解决办法就是设定每行的单元格(当然不包括与设定列颜色的列相交叉的单元格)的颜色。

 
附录:ABAP颜色代码

ABAP中的颜色代码是由4位字都组成的 Cxyz
C:color的简写,颜色代码均以C开头
x:标准色代码,SAP中一共有7个标准色
y:反转颜色启用/关闭 1/0
z:增强颜色启用/关闭 1/0

标准色代码一览表:
------------------------------------
X     颜色          主要用处
------------------------------------
1      灰蓝色        抬头、标题栏
2      浅灰色        列表内容
3      黄色          汇总
4      蓝色          关键字
5      绿色          正确
6      红色          错误
7      橙色          控制
 

*------- An example --------------------------------------------------
report  z_barry_alv_cl_color2.

typesbegin of ilist_s ,
  name1(10),
  name2(10),
  name3(10),
  end of ilist_s.
datailist type standard table of ilist_s  with header line .

databegin of list occurs 0.
        include structure ilist .
datarowcolor(4type ,
      cellcolors type lvc_t_scol ,
      cellstyles type lvc_t_styl ,
      celltext   type alv_t_dtv .
dataend of list.

dataok_code like sy-ucomm.
datal_valid(1type c.
datago_grid type ref to cl_gui_alv_grid.

datagt_fieldcat type lvc_t_fcat,
      gs_fieldcat type lvc_s_fcat,
      sla         type lvc_s_layo.
datals_fieldcat type lvc_s_fcat.
data ls_style type lvc_s_styl .
data ls_cellcolor type lvc_s_scol .
data ls_celltext     type alv_s_dtv .

*----------------------------------------------------------------------*
*       CLASS lcl_event_receiver DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_event_receiver definition.
  public section.
    methods handle_button_click
    for event button_click of cl_gui_alv_grid importing es_col_id es_row_no.
endclass.                    "lcl_event_receiver DEFINITION
*----------------------------------------------------------------------*
*       CLASS lcl_event_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_event_receiver implementation.
  method handle_button_click.
    perform test using es_col_id es_row_no.
  endmethod.            "handle_f4ENDCLASS.
endclass.                    "lcl_event_receiver IMPLEMENTATION

dataevent_receiver type ref to lcl_event_receiver.
dataii type .

start-of-selection.
  clear ls_fieldcat.
  ls_fieldcat-fieldname     'NAME1'.
  ls_fieldcat-scrtext_l     'NAME1'.
  append ls_fieldcat to  gt_fieldcat.

  clear ls_fieldcat.
  ls_fieldcat-fieldname     'NAME2'.
  ls_fieldcat-scrtext_l     'NAME2'.
  ls_fieldcat-emphasize     'C610'."对NAME2这一列加颜色,值有:c100-c700,c110-c710,c101-c701.
  append ls_fieldcat to  gt_fieldcat.

  clear ls_fieldcat.
  ls_fieldcat-fieldname     'NAME3'.
  ls_fieldcat-scrtext_l     'NAME3'.
  append ls_fieldcat to  gt_fieldcat.

  list-name1 'A'.
  list-name2 'ARE'.
  ls_cellcolor-fname 'NAME1' .
  ls_cellcolor-color-col '5' .
  ls_cellcolor-color-int '1' .
  ls_cellcolor-color-inv '1' .
  append ls_cellcolor to list-cellcolors .
  append list.

  list-name1 'AA'.
  list-name2 'BB'.
  ls_cellcolor-fname 'NAME2' ."颜色应用在字段NAME2上
  ls_cellcolor-color-col '3' ."0,2,...,8,共9种颜色
  ls_cellcolor-color-int '1' .
  ls_cellcolor-color-inv '1' .
  append ls_cellcolor to list-cellcolors .
  append list.

  list-name1 'HOW'.
  list-name2 'ARE'.
  list-rowcolor 'C410'."对行加颜色
  ls_style-fieldname 'NAME3' .
  ls_style-style cl_gui_alv_grid=>mc_style_button .
  "ls_style-style = cl_gui_alv_grid=>mc_style_hotspot.
  append ls_style to list-cellstyles .
  ls_celltext-buttoncell 'TEST'.
  append ls_celltext to list-celltext.
  append list.

  sla-stylefname 'CELLSTYLES'.
  sla-ctab_fname 'CELLCOLORS'.
  sla-info_fname 'ROWCOLOR'.

  write 'a'."这个不能少,否则不能显示。?
  create object go_grid
    exporting
      i_parent cl_gui_container=>screen0.

  create object event_receiver.
  set handler event_receiver->handle_button_click for go_grid.

  call method go_grid->set_table_for_first_display
    exporting      "is_variant = gs_variant
      i_save                        'A'
      is_layout                     sla
    changing
      it_outtab                     list[]
      it_fieldcatalog               gt_fieldcat[]
    exceptions
      invalid_parameter_combination 1
      program_error                 2
      too_many_lines                3
      others                        4.

*&---------------------------------------------------------------------*
*&      Form  test
*&---------------------------------------------------------------------*
form test using p_es_col_id type lvc_s_col
       p_es_row_no type lvc_s_roid.
  message i899(fiwith p_es_col_id-fieldname p_es_row_no-row_id .
endform.                    "test
  评论这张
 
阅读(858)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018