07-23-2007 11:52 PM
Kindly help me to change Color of the cell in ALV report for the negative value not the entire line.
Eg.
Qty1 Qty2 Qty3
1 -10 -2
1 2 -4
4 -8 9
The output of ALV List display should dispaly all the negative values in CELL in green color. Sample code will be helpful..
Thanks
07-24-2007 12:41 PM
im providing a sample piece of code...hope so u will understand it....
before assigning field catalog
include this field in your internal table which is u r final one as below
data:begin of it_wk_clr occurs 0,
matnr like marc-matnr,
maktx like makt-maktx,
dispo like marc-dispo,
fevor like marc-fevor,
plan type i value 0,
day1 type i value 0,
day2 type i value 0,
day3 type i value 0,
day4 type i value 0,
day5 type i value 0,
day6 type i value 0,
day7 type i value 0,
tprd type i value 0,
rework type i value 0,
var type i value 0,
prd_per type p value 0,
quan type p decimals 0 value 0 ,
scrap type p decimals 0 value 0,
cellcolor type lvc_t_scol, "this field
end of it_wk_clr.
please note if ur doing any collect statements in this internal table it wont work...so you copy the data of final itab to a new table and include this field.
also declare
data: wk_layout type slis_layout_alv.
then before assigning field catalog.
loop at that final itab.
for example if i want to print the var field in different colors
loop at temp.
if temp-var > 0.
move 'VAR' to wa_color-fname.
move '6' to wa_color-color-col.
move '0' to wa_color-color-int.
move '1' to wa_color-color-inv.
append wa_color to temp-cellcolor.
modify temp transporting cellcolor.
elseif temp-var < 0.
move 'VAR' to wa_color-fname.
move '5' to wa_color-color-col.
move '0' to wa_color-color-int.
move '1' to wa_color-color-inv.
append wa_color to temp-cellcolor.
modify temp transporting cellcolor.
endif.
endloop.
then include
wk_layout-coltab_fieldname = 'CELLCOLOR'.
and at last in the alv functional module include
is_layout = wk_layout
if it helps do reward points
07-24-2007 12:45 PM
Hi
1. add one more field to ur final internal table say COLOR(4)
2. in layout wa_layout-style_fname = 'COLOR'. " if its grid
wa_layout-style_fieldname = 'COLOR'. "if its list
3. read table itab index 3.
itab-color = 'C410'.
modify itab index 3
4. see program SHOWCOLO for all color codes
1. Add a field of data type CHAR(3) to the internal output table.
2. Enter the color code in the appropriate field of the row to be colored in the internal
output table:
Code: 'Cxy'
C = Color (all codes begin with 'C')
x = color number ('1' - '9')
y = highlight ('0' = off, '1' = on)
3. Assign the internal output table color code field name to the IS_LAYOUT importing
structure IS_LAYOUT-INFO_FIELDNAME field and pass this structure in the ALV call
interface.
To enable row coloring, you should add an additional field to your list data table. It should be of character type and length at least 4. This field will contain the color code for the row. So, lets modify declaration of our list data table gt_list.
you should fill the color code to this field. Its format will be the same as explained before at section C.6.3. But how will ALV Grid know that you have loaded the color data for the row to this field. So, you make it know this by passing the name of the field containing color codes to the field INFO_FNAME of the layout structure.
e.g.
ps_layout-info_fname = <field_name_containing_color_codes>. e.g. ROWCOLOR
You can fill that field anytime during execution. But, of course, due to the flow logic of screens, it will be reflected to your list display as soon as an ALV refresh occurs.
You can color an entire row as described in the next section. However, this method is less time consuming.
Coloring Individual Cells
This is the last point about coloring procedures for the ALV Grid. The procedure is similar to coloring an entire row. However, since an individual cell can be addressed with two parameters we will need something more. What is meant by more is a table type structure to be included into the structure of the list data table. It seems strange, because including it will make our list data structure deep. But anyhow ALV Grid control handles this.
The structure that should be included must be of type LVC_T_SCOL. If you want to color the entire row, this inner table should contain only one row with field fname is set to space, some color value at field col, 0 or 1 at fields int (intensified) and inv (inverse).
If you want to color individual cells, then for each cell column, append a line to this inner table which also contains the column name at field fname. It is obvious that you can color an entire column by filling this inner table with a row for that column for each row in the list data table.
Check this
http://www.sapfans.com/forums/viewtopic.php?t=52107
<b>Reward points if useful</b>
Regards
Ashu
07-24-2007 12:46 PM
07-24-2007 12:46 PM
Hello,
Here is a short example program which shows how to color a row, column, or cell.
report zrich_0002 .
*****************************************************************
* Use of colours in ALV grid (cell, line and column) *
*****************************************************************
* Table
tables : mara.
* Type
types : begin of ty_mara,
matnr like mara-matnr,
matkl like mara-matkl,
counter(4) type n,
free_text(15) type c,
color_line(4) type c, " Line color
color_cell type lvc_t_scol, " Cell color
end of ty_mara.
* Structures
data : wa_mara type ty_mara,
wa_fieldcat type lvc_s_fcat,
is_layout type lvc_s_layo,
wa_color type lvc_s_scol.
* Internal table
data : it_mara type standard table of ty_mara,
it_fieldcat type standard table of lvc_s_fcat,
it_color type table of lvc_s_scol.
* Variables
data : okcode like sy-ucomm,
w_alv_grid type ref to cl_gui_alv_grid,
w_docking_container type ref to cl_gui_docking_container.
parameters : p_column as checkbox,
p_line as checkbox,
p_cell as checkbox.
at selection-screen output.
perform get_data.
perform fill_catalog.
if w_docking_container is initial.
perform create_objects.
endif.
*&--------------------------------------------------------------*
*& Form create_objects
*&--------------------------------------------------------------*
form create_objects.
create object w_docking_container
exporting
ratio = 60
exceptions
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
others = 6.
create object w_alv_grid
exporting
i_parent = w_docking_container.
* Field that identify color line in internal table
move 'COLOR_LINE' to is_layout-info_fname.
* Field that identify cell color in inetrnal table
move 'COLOR_CELL' to is_layout-ctab_fname.
call method w_alv_grid->set_table_for_first_display
exporting
is_layout = is_layout
changing
it_outtab = it_mara
it_fieldcatalog = it_fieldcat
exceptions
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
others = 4.
endform.
*&--------------------------------------------------------------*
*& Form get_data
*&--------------------------------------------------------------*
form get_data.
select * from mara up to 5 rows.
clear : wa_mara-color_line, wa_mara-color_cell.
move-corresponding mara to wa_mara.
add 1 to wa_mara-counter.
move 'Blabla' to wa_mara-free_text.
if wa_mara-counter = '0002'
and p_line = 'X'.
* Color line
move 'C410' to wa_mara-color_line.
elseif wa_mara-counter = '0004'
and p_cell = 'X'.
* Color cell
move 'FREE_TEXT' to wa_color-fname.
move '6' to wa_color-color-col.
move '1' to wa_color-color-int.
move '1' to wa_color-color-inv.
append wa_color to it_color.
wa_mara-color_cell[] = it_color[].
endif.
append wa_mara to it_mara.
endselect.
endform.
*&--------------------------------------------------------------*
*& Form fill_catalog
*&--------------------------------------------------------------*
form fill_catalog.
*****************************************************************
* Colour code : *
* Colour is a 4-char field where : *
* - 1st char = C (color property) *
* - 2nd char = color code (from 0 to 7) *
* 0 = background color *
* 1 = blue *
* 2 = gray *
* 3 = yellow *
* 4 = blue/gray *
* 5 = green *
* 6 = red *
* 7 = orange *
* - 3rd char = intensified (0=off, 1=on) *
* - 4th char = inverse display (0=off, 1=on) *
* *
* Colour overwriting priority : *
* 1. Line *
* 2. Cell *
* 3. Column *
*****************************************************************
data : w_position type i value '1'.
clear wa_fieldcat.
move w_position to wa_fieldcat-col_pos.
move 'MATNR' to wa_fieldcat-fieldname.
move 'MARA' to wa_fieldcat-ref_table.
move 'MATNR' to wa_fieldcat-ref_field.
append wa_fieldcat to it_fieldcat.
add 1 to w_position.
clear wa_fieldcat.
move w_position to wa_fieldcat-col_pos.
move 'MATKL' to wa_fieldcat-fieldname.
move 'MARA' to wa_fieldcat-ref_table.
move 'MATKL' to wa_fieldcat-ref_field.
* Color column
if p_column = 'X'.
move 'C610' to wa_fieldcat-emphasize.
endif.
append wa_fieldcat to it_fieldcat.
add 1 to w_position.
clear wa_fieldcat.
move w_position to wa_fieldcat-col_pos.
move 'COUNTER' to wa_fieldcat-fieldname.
move 'N' to wa_fieldcat-inttype.
move '4' to wa_fieldcat-intlen.
move 'Counter' to wa_fieldcat-coltext.
append wa_fieldcat to it_fieldcat.
add 1 to w_position.
clear wa_fieldcat.
move w_position to wa_fieldcat-col_pos.
move 'FREE_TEXT' to wa_fieldcat-fieldname.
move 'C' to wa_fieldcat-inttype.
move '20' to wa_fieldcat-intlen.
move 'Text' to wa_fieldcat-coltext.
append wa_fieldcat to it_fieldcat.
endform.
Regards,
Deepu.K
07-24-2007 12:47 PM
Hi,
WA_COLOR-FIELDNAME = 'MEINS'.
WA_COLOR-COLOR-COL = 6. " Color form 0 to 7
WA_COLOR-COLOR-INT = 1. " for background color
WA_COLOR-COLOR-INV = 1. " for font color
but, COLOR-INT & COLOR-INV will not work at a same time. Only color-int will be displayed.
Regards,
Omkar.
07-24-2007 12:48 PM
Hi,
In the below mentioned link a topic Color of ALV output, columns, and cells has been mentioned in the section '4.17.3 Appearance of ALV Output'.
Regards,
Padmam.
07-24-2007 12:48 PM
Hi
In your output table you have to insert a field (for color) as SLIS_T_SPECIALCOL_ALV.
DATA: BEGIN OF T_OUTPUT OCCURS 0,
.......
TCOLOR TYPE SLIS_T_SPECIALCOL_ALV,
END OF
DATA: GT_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA: LT_COLOR TYPE slis_specialcol_alv.
In the layout structure you have to indicate the name of field color:
gt_layout-coltab_fieldname = 'TCOLOR'.
When you're appending the record to show, you have to fill the data for cells color:
Values
T_OUTPUT-FIELD1 = ....
T_OUTPUT-FIELD2 = ....
T_OUTPUT-FIELD3 = ....
Color
REFRESH T_OUTPUT-TCOLOR.
CLEAR LT_COLOR.
LT_COLOR-FIELDNAME = 'FIELD1'.
IF T_OUTPUT-FIELD1 =....
LT_COLOR-COLOR-COL = '2'. "Number of color
ELSE.
LT_COLOR-COLOR-COL = '2'.
LT_COLOR-COLOR-INT = '1'. "Intensified on/off
ENDIF.
APPEND LT_COLOR TO T_OUTPUT-TCOLOR.
CLEAR LT_COLOR.
LT_COLOR-FIELDNAME = 'FIELD2'.
IF T_OUTPUT-FIELD2 =....
LT_COLOR-COLOR-COL = '3'. "Number of color
ELSE.
LT_COLOR-COLOR-COL = '3'.
LT_COLOR-COLOR-INT = '1'. "Intensified on/off
ENDIF.
APPEND LT_COLOR TO T_OUTPUT-TCOLOR.
...........
APPEND T_OUTPUT.
Plz Refer this link..
http://www.geocities.com/mpioud/Z_ALV_CELL_COLOR.html
http://www.sap-img.com/abap/line-color-in-alv-example.htm
http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_color.htm
<b>Reward points</b>
Regards
07-26-2007 8:04 PM
07-20-2011 12:32 PM
Please kindly go through the following sample report for your problem..
TYPE-POOLS : slis .
TYPES : BEGIN OF type_vbrk ,
vbeln TYPE vbrk-vbeln ,
netwr TYPE vbrk-netwr ,
cellcolor TYPE lvc_t_scol ,
END OF type_vbrk .
TYPES : type_t_vbrk TYPE STANDARD TABLE OF type_vbrk .
DATA : wa_vbrk TYPE type_vbrk ,
it_vbrk TYPE type_t_vbrk ,
it_fieldcat TYPE slis_t_fieldcat_alv ,
wa_fieldcat TYPE slis_fieldcat_alv ,
wa_layout TYPE slis_layout_alv .
START-OF-SELECTION .
CLEAR wa_vbrk .
wa_vbrk-vbeln = '121212' .
wa_vbrk-netwr = '12.22' .
APPEND wa_vbrk TO it_vbrk .
CLEAR wa_vbrk .
wa_vbrk-vbeln = '121213' .
wa_vbrk-netwr = '-12.22' .
APPEND wa_vbrk TO it_vbrk .
CLEAR wa_vbrk .
wa_vbrk-vbeln = '10001' .
wa_vbrk-netwr = '-16.22' .
APPEND wa_vbrk TO it_vbrk .
CLEAR wa_vbrk .
wa_vbrk-vbeln = '10002' .
wa_vbrk-netwr = '36.22' .
APPEND wa_vbrk TO it_vbrk .
CLEAR wa_vbrk .
wa_vbrk-vbeln = '101012' .
wa_vbrk-netwr = '-32.22' .
APPEND wa_vbrk TO it_vbrk .
CLEAR wa_vbrk .
wa_vbrk-vbeln = '121219' .
wa_vbrk-netwr = '-45.00' .
APPEND wa_vbrk TO it_vbrk .
CLEAR wa_vbrk .
wa_vbrk-vbeln = '1125212' .
wa_vbrk-netwr = '92.22' .
APPEND wa_vbrk TO it_vbrk .
*-- SETTING THE CELL COLOR
DATA: wa_cellcolor TYPE lvc_s_scol ,
ld_index TYPE sy-tabix.
LOOP AT it_vbrk INTO wa_vbrk .
ld_index = sy-tabix.
IF wa_vbrk-netwr < 0 .
wa_cellcolor-fname = 'NETWR'.
wa_cellcolor-color-col = 6 . "color code 1-7, if outside rage defaults to 7
wa_cellcolor-color-int = '1' . "1 = Intensified on, 0 = Intensified off
wa_cellcolor-color-inv = '0' . "1 = text colour, 0 = background colour
APPEND wa_cellcolor TO wa_vbrk-cellcolor.
MODIFY it_vbrk FROM wa_vbrk INDEX ld_index TRANSPORTING cellcolor.
ENDIF.
ENDLOOP .
CLEAR wa_fieldcat .
wa_fieldcat-col_pos = 1 .
wa_fieldcat-fieldname = 'VBELN' .
wa_fieldcat-tabname = 'IT_VBRK' .
wa_fieldcat-seltext_m = 'Invoice Number' .
APPEND wa_fieldcat TO it_fieldcat .
CLEAR wa_fieldcat .
wa_fieldcat-col_pos = 2 .
wa_fieldcat-fieldname = 'NETWR' .
wa_fieldcat-tabname = 'IT_VBRK' .
wa_fieldcat-seltext_m = 'Net Value' .
APPEND wa_fieldcat TO it_fieldcat .
wa_layout-zebra = 'X' .
wa_layout-colwidth_optimize = 'X' .
wa_layout-coltab_fieldname = 'CELLCOLOR'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_grid_title = 'Supress Negative Values'
I_GRID_SETTINGS =
is_layout = wa_layout
it_fieldcat = it_fieldcat
TABLES
t_outtab = it_vbrk
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.
Thanks & Regards ,
Mallikarjun S Patil