这是一个十分有趣而且有用的程序,能得到ALV 单元格颜色代码,代码如下:
ABAP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | *&---------------------------------------------------------------------* *& Report ZCELL_COLORS *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------*
REPORT ZCELL_COLORS.
TYPES: BEGIN OF ts_data, col TYPE lvc_col, " color 1-7 int TYPE lvc_int, " intensified 0-1 inv TYPE lvc_inv, " inverse 0-1 scol TYPE lvc_t_scol, " table for cell coloring END OF ts_data, tt_data TYPE TABLE OF ts_data.
DATA: ls_data TYPE ts_data, lt_data TYPE tt_data, lv_index TYPE i, ls_color TYPE lvc_s_scol, lt_color TYPE lvc_t_scol, lo_table TYPE REF TO cl_salv_table, lo_columns TYPE REF TO cl_salv_columns_table, lo_column TYPE REF TO cl_salv_column_list.
* empty row with default color APPEND ls_data TO lt_data.
* rows with possible colors DO 7 TIMES.
ls_color-color-col = sy-index. " 1-7
DO 2 TIMES.
lv_index = sy-index - 1. ls_color-color-int = lv_index. " 0-1
DO 2 TIMES.
lv_index = sy-index - 1. ls_color-color-inv = lv_index. " 0-1
APPEND ls_color TO lt_color.
ls_data-col = ls_color-color-col. ls_data-int = ls_color-color-int. ls_data-inv = ls_color-color-inv.
ls_data-scol = lt_color. APPEND ls_data TO lt_data. CLEAR lt_color. ENDDO. ENDDO. ENDDO.
TRY. CALL METHOD cl_salv_table=>factory IMPORTING r_salv_table = lo_table CHANGING t_table = lt_data.
lo_columns = lo_table->get_columns( ).
* set descriptions of columns lo_column ?= lo_columns->get_column( 'COL' ). lo_column->set_short_text( 'COL' ).
lo_column ?= lo_columns->get_column( 'INT' ). lo_column->set_short_text( 'INT' ).
lo_column ?= lo_columns->get_column( 'INV' ). lo_column->set_short_text( 'INV' ).
* set the column with the information about colors of rows and fields lo_columns->set_color_column( 'SCOL' ).
lo_table->display( ).
CATCH cx_salv_msg. " cl_salv_table=>factory WRITE: / 'cx_salv_msg exception'. STOP.
CATCH cx_salv_data_error. " cl_salv_filters->add_filter() WRITE: / 'cx_salv_data_error'. STOP.
CATCH cx_salv_not_found. " cl_salv_columns_table->get_column() WRITE: / 'cx_salv_not_found exception'. STOP. ENDTRY. |