12-19-2006 4:03 PM
I have created a List with ALV_GRID and here I want to change the color in a
cell.
It is no problem to change the color in a line, but how can I make it in only one
cell, if it is filled?
Sabine
12-20-2006 6:17 AM
Hi,
1. Define a column as follows in output table type
TYPES : BEGIN OF ty_output.
INCLUDE STRUCTURE MARA.
TYPES :
For cell coloring
cellcolor TYPE lvc_t_scol,
END OF ty_output.
data : w_cellcolor TYPE lvc_s_scol, "For cell color
Final output table
itab2 TYPE STANDARD TABLE OF ty_output,
wa2 TYPE ty_output,
w_layout TYPE lvc_s_layo.
2. Colouring cell
CLEAR wa2.
READ TABLE itab2 INTO wa2 INDEX 7.
IF sy-subrc EQ 0.
w_cellcolor-fname = 'ERSDA'.
w_cellcolor-color-col = '7'.
w_cellcolor-color-int = '1'.
w_cellcolor-color-inv = '1'.
APPEND w_cellcolor TO wa2-cellcolor.
MODIFY itab2 FROM wa2 TRANSPORTING cellcolor WHERE matnr = wa2-matnr.
ENDIF.
3.
w_layout-ctab_fname = 'CELLCOLOR'."For cell coloring
4.
CALL METHOD o_grid->set_table_for_first_display
EXPORTING
I_STRUCTURE_NAME = 'MARA'
IS_VARIANT = w_variant
I_SAVE = 'A'
it_toolbar_excluding = i_exclude
is_layout = w_layout
CHANGING
it_outtab = itab2
it_fieldcatalog = i_fieldcat.
12-19-2006 4:09 PM
Here is a sample program for use with the FM ALV Grid.
report zrich_0004
no standard page heading.
type-pools slis.
data: fieldcat type slis_t_fieldcat_alv.
data: begin of imara occurs 0,
matnr type mara-matnr,
mtart type mara-mtart,
maktx type makt-maktx,
color_line(4) type c,
tcolor type slis_t_specialcol_alv, "cell
end of imara.
data: xcolor type slis_specialcol_alv.
start-of-selection.
perform get_data.
perform write_report.
************************************************************************
* Get_Data
************************************************************************
form get_data.
imara-matnr = 'ABC'.
imara-mtart = 'ZCFG'.
imara-maktx = 'This is description for ABC'.
append imara.
imara-matnr = 'DEF'.
imara-mtart = 'ZCFG'.
imara-maktx = 'This is description for DEF'.
append imara.
imara-matnr = 'GHI'.
imara-mtart = 'ZCFG'.
imara-maktx = 'This is description for GHI'.
append imara.
loop at imara.
if sy-tabix = 1.
imara-color_line = 'C410'. " color line
endif.
if sy-tabix = 2. "color CELL
clear xcolor.
xcolor-fieldname = 'MTART'.
xcolor-color-col = '3'.
xcolor-color-int = '1'. "Intensified on/off
xcolor-color-inv = '0'.
append xcolor to imara-tcolor.
endif.
modify imara.
endloop.
endform.
************************************************************************
* WRITE_REPORT
************************************************************************
form write_report.
data: layout type slis_layout_alv.
layout-coltab_fieldname = 'TCOLOR'.
layout-info_fieldname = 'COLOR_LINE'.
perform build_field_catalog.
* CALL ABAP LIST VIEWER (ALV)
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
is_layout = layout
it_fieldcat = fieldcat
tables
t_outtab = imara.
endform.
************************************************************************
* BUILD_FIELD_CATALOG
************************************************************************
form build_field_catalog.
data: fc_tmp type slis_t_fieldcat_alv with header line.
clear: fieldcat. refresh: fieldcat.
clear: fc_tmp.
fc_tmp-reptext_ddic = 'Material Number'.
fc_tmp-fieldname = 'MATNR'.
fc_tmp-tabname = 'IMARA'.
fc_tmp-outputlen = '18'.
append fc_tmp to fieldcat.
clear: fc_tmp.
fc_tmp-reptext_ddic = 'Material Type'.
fc_tmp-fieldname = 'MTART'.
fc_tmp-tabname = 'IMARA'.
fc_tmp-outputlen = '4'.
append fc_tmp to fieldcat.
clear: fc_tmp.
fc_tmp-reptext_ddic = 'Material'.
fc_tmp-fieldname = 'MAKTX'.
fc_tmp-tabname = 'IMARA'.
fc_tmp-outputlen = '40'.
fc_tmp-emphasize = 'C610'. " color column
append fc_tmp to fieldcat.
endform.
I have one for the class ALV grid also, if you need that.
Regards,
Rich Heilman
12-19-2006 4:10 PM
You can do that.
Add a column of the type LVC_T_STYL to the internal table which has the data.
This becomes a nested internal table. For each row of data, fill in the data in the STYLE column, with the column name and the style name.
Regards,
Ravi
Note - Please mark all the helpful answers
12-20-2006 6:03 AM
Hi Sabine
try this ...
DATA : gs_color TYPE lvc_s_scol,
gt_color TYPE TABLE OF lvc_s_scol.
Declare this in ALV layout .
MOVE 'COLOR_CELL' TO ps_layout-ctab_fname.
Declare this as a field in the internal table whose cell you want to colour.
color_cell TYPE lvc_t_scol.
Give the below statements in the IF condition for which you want to get the cell coloured .
In the first MOVE statement below replace FIELDNAME with the name of field in internal table.
MOVE 'FIELDNAME' TO gs_color-fname.
MOVE ' 5' TO gs_color-color-col.
MOVE '1' TO gs_color-color-int.
MOVE '1' TO gs_color-color-inv.
APPEND gs_color TO gt_color.
wa_display-color_cell[] = gt_color[].
Modify i_display FROM wa_display.
wa_display is the workarea of the internal table passed in the ALV.
The numbers 5 ,1 , 1 can be changed according to the colour required.
12-20-2006 6:17 AM
Hi,
1. Define a column as follows in output table type
TYPES : BEGIN OF ty_output.
INCLUDE STRUCTURE MARA.
TYPES :
For cell coloring
cellcolor TYPE lvc_t_scol,
END OF ty_output.
data : w_cellcolor TYPE lvc_s_scol, "For cell color
Final output table
itab2 TYPE STANDARD TABLE OF ty_output,
wa2 TYPE ty_output,
w_layout TYPE lvc_s_layo.
2. Colouring cell
CLEAR wa2.
READ TABLE itab2 INTO wa2 INDEX 7.
IF sy-subrc EQ 0.
w_cellcolor-fname = 'ERSDA'.
w_cellcolor-color-col = '7'.
w_cellcolor-color-int = '1'.
w_cellcolor-color-inv = '1'.
APPEND w_cellcolor TO wa2-cellcolor.
MODIFY itab2 FROM wa2 TRANSPORTING cellcolor WHERE matnr = wa2-matnr.
ENDIF.
3.
w_layout-ctab_fname = 'CELLCOLOR'."For cell coloring
4.
CALL METHOD o_grid->set_table_for_first_display
EXPORTING
I_STRUCTURE_NAME = 'MARA'
IS_VARIANT = w_variant
I_SAVE = 'A'
it_toolbar_excluding = i_exclude
is_layout = w_layout
CHANGING
it_outtab = itab2
it_fieldcatalog = i_fieldcat.