11-15-2007 7:55 PM
Hi , in my ALV grid using ABAP objects, I want to color specific rows only. How can I achieve this.
Thank you
11-15-2007 7:59 PM
11-15-2007 7:59 PM
Hi Krish,
Go through this link
http://www.sapfans.com/forums/viewtopic.php?t=52107
Reward Points if it helps,
Satish
11-15-2007 7:59 PM
11-15-2007 8:01 PM
Krish,
Create an executable program and paste in the code below.
Then use SE51 and create a screen '0100' for program ZR_COLORS. Place a custom container on it. Give the custom container the name of 'CUSTOM_GRID_CONTAINER'.
Save and activate all... and there you go.
REPORT ZR_Colors.
data: begin of i_vbak2 occurs 0.
include structure vbak.
data: end of i_vbak2.
data: begin of i_vbak occurs 0.
include structure vbak.
data: cellcolors type lvc_t_scol. " note that is an int table within
data: end of i_vbak. " an int table !!!
types: begin of r_vbak.
include structure vbak.
types: cellcolors type lvc_t_scol.
types: end of r_vbak.
data: i_vbak_out type table of r_vbak.
data: cellcolor type lvc_s_scol.
data: layout type LVC_S_LAYO.
data: grid1 type ref to cl_gui_alv_grid,
field_catalog type lvc_t_fcat,
grid1_container type ref to cl_gui_custom_container.
data: lt_fieldcat type LVC_T_FCAT.
data: wa_fieldcat type LVC_s_FCAT.
start-of-selection.
select * from vbak into table i_vbak2
where erdat > '20041201'
and erdat < '20070630'.
loop at i_vbak2.
move-corresponding i_vbak2 to i_vbak.
append i_vbak.
endloop.
layout-zebra = 'X'.
layout-cwidth_opt = 'X'.
Set first cell in Net value column.
read table i_vbak index 2.
cellcolor-fname = 'NETWR'.
cellcolor-color-col = '3'.
cellcolor-color-int = '1'.
cellcolor-NOKEYCOL = 'X'.
append cellcolor to i_vbak-cellcolors.
modify i_vbak index 2.
Set 2nd cell in Net value column.
read table i_vbak index 4.
cellcolor-fname = 'NETWR'.
cellcolor-color-col = '6'.
cellcolor-color-int = '1'.
cellcolor-NOKEYCOL = 'X'.
append cellcolor to i_vbak-cellcolors.
modify i_vbak index 4.
Identify the internal table name with the colors reference.
layout-CTAB_FNAME = 'CELLCOLORS'.
Instantiate the grid container.
create object grid1_container
exporting
container_name = 'CUSTOM_GRID_CONTAINER'.
Instantiate the grid itself within the container.
create object grid1
exporting
i_parent = grid1_container
i_appl_events = 'X'.
i_vbak_out[] = i_vbak[].
layout-frontend = 'E'.
Call method of grid1 class object to build/display the grid.
call method grid1->set_table_for_first_display
EXPORTING i_structure_name = 'VBAK'
is_layout = layout
changing
it_outtab = i_vbak_out.
it_fieldcatalog = lt_fieldcat.
call screen '0100'.
&----
*& Module STATUS_0100 OUTPUT
&----
text
----
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'E100'.
SET TITLEBAR '100'.
ENDMODULE. " STATUS_0100 OUTPUT
&----
*& Module USER_COMMAND_0100 INPUT
&----
text
----
MODULE USER_COMMAND_0100 INPUT.
case sy-ucomm.
when 'EXIT' or 'BACK' or 'CANCEL'.
leave program.
endcase.
ENDMODULE. " USER_COMMAND_0100 INPUT
11-15-2007 8:43 PM