1)顏色含義web
1:海藍;2:淺清;3:黃色;4:淺藍;5:青色;6:紅色;7:橙色。
(1)首位爲主顏色;
(2)次位爲輔助顏色;
(3)末位爲0時,表示首位數字表爲表格的底色;
末位爲1時,則表示以1爲底色,首位數字則表爲表格字體的顏色;
末位爲其它顏色時,則表示底色爲ALV的默認顏色;
以上三條是本人大概總結出來的規律,本人發現的現象基本如上,但也不必定所有正確。
其中C200與系統標準ALV底色比較類似;C410與系統標準關鍵字顏色比較類似。app
2)列顏色:
在 slis_t_fieldcat_alv-emphasize 中,寫入須要的顏色代碼。
Eg:
DATA: fc TYPE slis_t_fieldcat_alv WITH HEADER LINE.
fc-tabname = 'ITAB'.
fc-fieldname = 'COL'. "列名
fc-emphasize = 'C100'."顏色
append fc.oop
設置ALV字段fieldcat屬性:i_fieldcat-emphasize = &3. "顏色
把fieldcat屬性寫入屬性內表allfields:alv_append_field 'WERKS' '工廠' 'C110'.
C110:爲顏色代碼;字體
data: i_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINEui
i_fieldcat-emphasize = 'C100'. "顏色代碼spa
3)行顏色:
(1)在內表itab定義一個字段style來存儲顏色;loop內表itab,在須要顯示顏色的行爲其值賦爲顏色'C110';
(2)在定義alv顯示格式定義:
設置ALV顯示layout屬性:i_layout-info_fieldname = 'STYLE',STYLE爲內表定義的存儲顏色的列名。3d
a.在要輸出的 itab 中,加入 color 列,類型爲C(4),記錄須要的顏色代碼。
b.設置 layout。alv_layout-info_fieldname = 'COLOR'.orm
Eg: DATA: BEGIN OF itab OCCURS 0.
INCLUDE STRUCTURE itab.
DATA: color(4) TYPE c.
DATA: END OF itab.blog
DATA: alv_layout TYPE slis_layout_alv.
"內表賦值
itab-matnr = '123'.
itab-color = 'C200'.
APPEND itab.事件
alv_layout-info_fieldname = 'COLOR'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = alv_layout
TABLES
it_outtab = itab.
4)單元格顏色
單元格顏色屬性:LVC_S_SCOL(類方式) ,該屬性爲一結構,含三個字段:FNAME(30)、COLOR(顏色結構,含三個字段:col(10)、int(3)、inv(10))、NOKEYCOL(1)(覆蓋碼顏色)
單元格顏色屬性:slis_t_specialcol_alv,該屬性爲一結構,含三個字段:FIELDNAME(30)、COLOR(顏色結構,含三個字段:col(10)、int(3)、inv(10))、NOKEYCOL(1)(覆蓋碼顏色)
eg:
定義內表itab含字段FLDNAME type LVC_S_SCOL;
定義內表itab含字段FLDNAME type slis_t_specialcol_alv;
ALV列屬性:coltab_fieldname = 'FLDNAME'.
DATA: BEGIN OF itab_test3 OCCURS 0.
INCLUDE STRUCTURE itab_test.
DATA: FLDNAME TYPE slis_t_specialcol_alv.
DATA: END OF itab_test3.
定義單元格顏色結構內表cellcolor type slis_t_specialcol_alv with header line;
循環內表,當要設置單元格顏色所在的列字段colname要設置顏色時
refresh cellcolor.
cellcolor-FIELDNAME =‘COLNAME’. "列名
cellcolor-COLOR-col =‘2’.(顏色代碼)
cellcolor-COLOR-int =‘1’.
cellcolor-COLOR-inv =‘0’.
APPEND cellcolor.
CONCATENATE '2' '10' INTO itab_test3-colname. "把顏色值賦給該列
" 更新內表對應存放字段
itab_test3-fldname[] = cellcolor[].
APPEND itab_test3.
" 顯示單元格顏色
DATA: alv_layout TYPE slis_layout_alv.
alv_layout-coltab_fieldname = 'FLDNAME'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = alv_layout
TABLES
it_outtab = itab_test3.
*&---------------------------------------------------------------------*
*& Report YLPY_ALV004
*&
*&---------------------------------------------------------------------*
*& ALV 行、列、單元格顏色設置
*&
*&---------------------------------------------------------------------*
REPORT ylpy_alv004.
TYPE-POOLS: slis.
*一共定義3個內表.
*itab1 :設置列顏色,
*itab2 :設置行顏色.
*itab3 :設置單元格顏色.
DATA: BEGIN OF itab_test OCCURS 0,
col1(4) TYPE c,
col2(4) TYPE c,
col3(4) TYPE c,
col4(4) TYPE c,
col5(4) TYPE c,
col6(4) TYPE c,
END OF itab_test .
* 顯示行顏色
DATA: BEGIN OF itab_test2 OCCURS 0.
INCLUDE STRUCTURE itab_test.
DATA: color(4) TYPE c. "定義行顏色字段
DATA: END OF itab_test2.
* 顯示單元格顏色
DATA: BEGIN OF itab_test3 OCCURS 0.
INCLUDE STRUCTURE itab_test.
DATA: color TYPE slis_t_specialcol_alv.
DATA: END OF itab_test3.
DATA: fc TYPE slis_t_fieldcat_alv WITH HEADER LINE,
fc2 TYPE slis_t_fieldcat_alv WITH HEADER LINE,
fc3 TYPE slis_t_fieldcat_alv WITH HEADER LINE.
START-OF-SELECTION.
PERFORM create_data. "構建內表數據
END-OF-SELECTION.
PERFORM fieldcat_build. "構建列表頭
PERFORM show_alv.
*&---------------------------------------------------------------------*
*& Form create_data
*&---------------------------------------------------------------------*
* 構建內表數據
*----------------------------------------------------------------------*
FORM create_data.
DATA: l_color(4) TYPE c,
l_char TYPE c,
i TYPE i.
DATA: color_wa TYPE slis_t_specialcol_alv WITH HEADER LINE."單元格顏色屬性內表
REFRESH itab_test.
REFRESH itab_test2.
REFRESH itab_test3.
REFRESH fc.
REFRESH fc2.
REFRESH fc3.
WHILE sy-index < 8.
* 內表 1
itab_test-col1 = ( sy-index - 1 ) * 6 + 1.
itab_test-col2 = ( sy-index - 1 ) * 6 + 2.
itab_test-col3 = ( sy-index - 1 ) * 6 + 3.
itab_test-col4 = ( sy-index - 1 ) * 6 + 4.
itab_test-col5 = ( sy-index - 1 ) * 6 + 5.
itab_test-col6 = ( sy-index - 1 ) * 6 + 6.
APPEND itab_test.
* 內表 2
MOVE-CORRESPONDING itab_test TO itab_test2.
l_char = sy-index.
i = sy-index MOD 2. "根據奇偶數構建行顏色值
IF i = 0.
CONCATENATE 'C' l_char '01' INTO l_color.
ELSE.
CONCATENATE 'C' l_char '10' INTO l_color.
ENDIF.
itab_test2-color = l_color.
APPEND itab_test2.
* 內表 3
MOVE-CORRESPONDING itab_test TO itab_test3. "轉移數據到itab_test3內表
REFRESH color_wa.
" 第一列顏色
color_wa-color-col = l_char.
color_wa-color-int = '0'.
color_wa-color-inv = '0'.
color_wa-fieldname = 'COL1'.
APPEND color_wa.
CONCATENATE l_char '00' INTO itab_test3-col1.
" 第二列顏色
color_wa-color-int = '0'.
color_wa-color-inv = '1'.
color_wa-fieldname = 'COL2'.
APPEND color_wa.
CONCATENATE l_char '01' INTO itab_test3-col2.
" 第三列顏色
color_wa-color-int = '1'.
color_wa-color-inv = '0'.
color_wa-fieldname = 'COL3'.
APPEND color_wa.
CONCATENATE l_char '10' INTO itab_test3-col3.
itab_test3-color[] = color_wa[].
APPEND itab_test3.
ENDWHILE.
ENDFORM. "create_data
************************************************************************
FORM fieldcat_build.
DATA: BEGIN OF fc_struct,
tabname(10),
fieldname(5),
seltext_m(5),
emphasize(4),
END OF fc_struct.
DEFINE ac.
clear: fc,fc2,fc_struct.
fc_struct = &1.
fc-tabname = fc_struct-tabname. "內表名
fc-fieldname = fc_struct-fieldname. "字段名
fc-seltext_m = fc_struct-seltext_m. "字段描述
fc-emphasize = fc_struct-emphasize. "列顏色
append fc.
fc2-tabname = fc_struct-tabname. "內表名
fc2-fieldname = fc_struct-fieldname. "字段名
fc2-seltext_m = fc_struct-seltext_m. "字段描述
append fc2.
if fc3-fieldname < 'COL4'. "只顯示前四列
fc3-tabname = fc_struct-tabname. "內表名
fc3-fieldname = fc_struct-fieldname. "字段名
fc3-seltext_m = fc_struct-seltext_m. "字段描述
append fc3.
endif.
END-OF-DEFINITION.
" 第一個內表顯示列顏色效果
ac 'ITAB_TEST COL1 COL1 C100'.
ac 'ITAB_TEST COL2 COL2 C200'.
ac 'ITAB_TEST COL3 COL3 C300'.
ac 'ITAB_TEST COL4 COL4 C400'.
ac 'ITAB_TEST COL5 COL5 C500'.
ac 'ITAB_TEST COL6 COL6 C600'.
ENDFORM. "fieldcat_build
*&---------------------------------------------------------------------*
*& Form show_alv
*&---------------------------------------------------------------------*
* 顯示內表 1
*----------------------------------------------------------------------*
FORM show_alv.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
it_fieldcat = fc[]
i_callback_user_command = 'PROCESS_USER_COMMAND_1' "響應雙擊事件
i_save = 'A'
TABLES
t_outtab = itab_test
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. "show_alv
*&---------------------------------------------------------------------*
*& Form PROCESS_USER_COMMAND_1
*&---------------------------------------------------------------------*
* 當用戶雙擊時顯示下層內容
*----------------------------------------------------------------------*
* -->UCOMM text
* -->RS_SELFIELD text
*----------------------------------------------------------------------*
FORM process_user_command_1 USING ucomm
rs_selfield TYPE slis_selfield.
IF rs_selfield-fieldname <> space AND rs_selfield-tabindex > 0. "這句頗有用
PERFORM show_alv_2.
ENDIF.
ENDFORM. "PROCESS_USER_COMMAND_1
*&---------------------------------------------------------------------*
*& Form show_alv_2
*&---------------------------------------------------------------------*
* 顯示內表 2 行顏色效果
*----------------------------------------------------------------------*
FORM show_alv_2.
DATA: alv_layout TYPE slis_layout_alv.
alv_layout-info_fieldname = 'COLOR'. "顯示行顏色
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
it_fieldcat = fc2[]
i_callback_user_command = 'PROCESS_USER_COMMAND_2' "下層雙擊事件內容
is_layout = alv_layout
i_save = 'U'
TABLES
t_outtab = itab_test2
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. "show_alv_2
*&---------------------------------------------------------------------*
*& Form PROCESS_USER_COMMAND_2
*&---------------------------------------------------------------------*
* 第三層報表內容
*----------------------------------------------------------------------*
* -->UCOMM text
* -->RS_SELFIELD text
*----------------------------------------------------------------------*
FORM process_user_command_2 USING ucomm
rs_selfield TYPE slis_selfield.
IF rs_selfield-fieldname <> space AND rs_selfield-tabindex > 0.
PERFORM show_alv_3.
ENDIF.
ENDFORM. "PROCESS_USER_COMMAND_2
*&---------------------------------------------------------------------*
*& Form show_alv_3
*&---------------------------------------------------------------------*
* 顯示內表 3 單元格顏色
*----------------------------------------------------------------------*
FORM show_alv_3.
DATA: alv_layout TYPE slis_layout_alv.
alv_layout-coltab_fieldname = 'COLOR'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
it_fieldcat = fc3[]
is_layout = alv_layout
i_save = 'U'
TABLES
t_outtab = itab_test3
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM. "show_alv_3