06-11-2009 2:30 PM
Hi,
I have a requirement to color those fields having Negative values in ALV Grid .I am using (cl_gui_alv_grid) . The row number and column name will be known to me only at runtime since any field in the grid may have negative values .Guide me on this .
Regards.,
S.Sivakumar
06-11-2009 2:53 PM
Hi,
Basically you will have to make use of LVC_S_SCOL.
You internal table should contain an additional column. Incase you want to color cell wise then the field of this column will be a table with structure LVC_S_SCOL.
In your Layout structure which you pass to the method SET_TABLE_FOR_FIRST_DISPLAY;
you should pass the column name in the field CTAB_FNAME.
To color the particular cell ; pass the fieldname in the field FNAME of LVC_S_SCOL and the color in teh field COLOR. Note that the value of color will be as follows:-
gray_blue VALUE '1',
light_gray VALUE '2',
yellow VALUE '3',
blue_green VALUE '4',
green VALUE '5',
red VALUE '6',
violet VALUE '7',
Consider the example as follows:-
Suppose your internal table has 2 field MATNR and MAKTX then your internal table after adding the new column for color will be as follows
MATNR MAKTX COLOR_COLUMN
1 Mat1 MATNR 3
MAKTX 3
2 Mat2 MATNR 6
MAKTX 6
So now when you display your grid.
The first material and its description will have a color yellow and the 2nd will have a color red.
Please see the example coding to prepare your internal table.
TYPES : BEGIN OF t_itab,
matnr TYPE matnr,
maktx TYPE maktx,
color TYPE lvc_t_scol,
END OF t_itab.
DATA : itab TYPE STANDARD TABLE OF t_itab,
color_tab TYPE lvc_t_scol.
DATA : wa TYPE t_itab,
color_wa TYPE lvc_s_scol.
color_wa-fname = 'MATNR'.
color_wa-color-col = '2'.
APPEND color_wa TO color_tab.
color_wa-fname = 'MAKTX'.
color_wa-color-col = '6'.
APPEND color_wa TO color_tab.
wa-matnr = '1'.
wa-maktx = 'Mat1'.
wa-color = color_tab.
APPEND wa TO itab.
So now the LAYOUT should contain the column name 'COLUMN' in the field CTAB_FNAME.
Regards,
Ankur Parab
Edited by: Ankur Parab on Jun 11, 2009 7:33 PM
06-11-2009 9:31 PM
You can Highlighting a cell in ALV Grid by giving a color. Copy the standard program BCALV_DEMO_TOOLTIP to a u2018Zu2019 program and make the following modifications:
Insert the following code after the code line ls_layout-ctab_fname = 'TABCOL' and before the code line clear ls_fcat.
ls_layout-SEL_MODE = 'D'.
Just go through this program. I hope it will help you. If not able, let me know.
-
Ravi
06-12-2009 5:00 AM
Hello Sivakumar
You may have a look at the link:
https://wiki.sdn.sap.com/wiki/display/Snippets/ALV+Cell+Colouring+and+Special+Styles
Regards
Uwe
06-12-2009 8:00 AM
Hi everybody,
Thanks for your replies . My problem is , i doesn't know the column name and rowid of a particular field . I am having ten quantity columns . In any of these columns and in any row, i may get a negative value . So i want to color that particular field. Is there any logic to find that particular field based on its contentd .
Regards.,
S.Sivakumar
06-12-2009 1:16 PM
Hello Sivakumar
You may try the following approach:
CONSTANTS:
gc_style_bold TYPE int4 VALUE '00000121',
gc_style_red TYPE int4 VALUE '00000087',
gc_style_cursive TYPE int4 VALUE '00008700',
gc_style_underline_faint TYPE int4 VALUE '00008787',
gc_style_underline TYPE int4 VALUE '00008707',
gc_style_underline_red TYPE int4 VALUE '00008007'.
DATA:
ld_idx TYPE i,
lt_celltab TYPE lvc_t_styl,
ls_style TYPE lvc_s_styl.
FIELD-SYMBOLS:
<ld_quantity> TYPE any.
LOOP AT gt_outtab INTO ls_outtab.
ld_idx = syst-tabix.
REFRESH: lt_celltab.
LOOP AT gt_fcat INTO ls_fcat.
CASE ls_fcat-fieldname.
WHEN 'QUANTITY1' OR
'QUANTITY2' OR
...
ASSIGN COMPONENT ls_fcat-fieldname OF STRUCTURE ls_outtab
TO <ld_quantity>.
IF ( <ld_quantity> < 0 ).
clear: ls_style.
ls_style-fname = ls_fcat-fieldname..
ls_style-style = gc_style_underline_red.
INSERT ls_style INTO TABLE lt_celltab.
ENDIF.
WHEN OTHERS.
ENDCASE.
ENDLOOP.
ls_outtab-celltab = lt_celltab.
MODIFY gt_outtab FROM ls_outtab INDEX ld_idx
TRANSPORTING celltab.
ENDLOOP.
Regards
Uwe
06-15-2009 12:16 PM