04-20-2009 10:23 AM
Hello Experts.
In my ALV report, I want to color particular cell where qty is less than zero.
Plz suggest where do i call this code.
**************************************
DATA SELECTION AND DISPLAY LOGIC.
**************************************
Data fetching, filtering and arranging.
START-OF-SELECTION.
PERFORM get_data.
PERFORM arrange_data.
Displaying the Data fetched.
END-OF-SELECTION.
PERFORM build_catlog.
PERFORM eventtab_field USING gt_events.
PERFORM set_cell_colours. <--- Help required
PERFORM comment_build USING gt_list_top_of_page[].
PERFORM display_alv.
&----
*
*& Form SET_CELL_COLOURS
&----
Set colour of individual ALV cell, field
----
FORM SET_CELL_COLOURS .
DATA: WA_CELLCOLOR TYPE LVC_S_SCOL.
DATA: ld_index TYPE SY-TABIX.
LOOP AT gt_final into gw_final.
LD_INDEX = SY-TABIX.
Set colour of QTY_6 field to color 6 if less than 0
if gw_final-QTY_6 LT 0.
WA_CELLCOLOR-FNAME = 'QTY_6'.
WA_CELLCOLOR-COLOR-COL = 6 . "color code 1-7, if outside rage defaults to 7
WA_CELLCOLOR-COLOR-INT = '0'. "1 = Intensified on, 0 = Intensified off
WA_CELLCOLOR-COLOR-INV = '0'. "1 = text colour, 0 = background colour
APPEND WA_CELLCOLOR TO gw_final-CELLCOLOR.
MODIFY gt_final from gw_final INDEX ld_index TRANSPORTING CELLCOLOR.
endif.
ENDLOOP.
ENDFORM. " SET_CELL_COLOURS
Thanks in advance .
Ravi.
04-20-2009 11:09 AM
Hi.. follow the steps...
Declare
DATA : ISO_CELL_COLOR TYPE LVC_T_SCOL, "Sorted table for cell coloring purpose
W_CELL_COLOR TYPE LVC_S_SCOL. "work area for cell coloring purpose.
Add following column in your internal table which u are using for fieldcatalog...
ISO_CELL_COLOR TYPE LVC_T_SCOL
Then Add following code....when filling the record in field catalog internal table...
LOOP AT ITAB_FINAL INTO WA_FINAL.
IF WA_FINAL-SKALAB EQ 0.
CLEAR W_CELL_COLOR.
W_CELL_COLOR-FNAME = 'SKALAB'.
W_CELL_COLOR-COLOR-COL = '6'.
W_CELL_COLOR-COLOR-INT = '1'.
W_CELL_COLOR-COLOR-INV = '1'.
APPEND W_CELL_COLOR TO ISO_CELL_COLOR.
WA_FINAL-ISO_CELL_COLOR = ISO_CELL_COLOR.
ENDIF.
MODIFY ITAB_FINAL FROM WA_FINAL TRANSPORTING ISO_CELL_COLOR SKALAB.
REFRESH ISO_CELL_COLOR.
ENDLOOP.
here Loop is for your internal table which u are using for field catalog...
WA_FINAL-SKALAB is ur field for which u want to put "0" value condition....
here red color will be displayed...
This will surly helpful to u....
Regards,
Chintan
Edited by: Chintan_SAP on Apr 20, 2009 3:40 PM
04-20-2009 10:35 AM
Refer below link
http://saplab.blogspot.com/2007/10/sample-abap-program-to-colour-cells-in.html
Hope this helps...
04-20-2009 10:40 AM
04-20-2009 10:43 AM
hi ,
Please refer to the following code :
REPORT ZALV_LIST4.
TABLES:
SPFLI.
TYPE-POOLS:
SLIS.
DATA:
T_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
FS_FIELDCAT LIKE LINE OF T_FIELDCAT,
FS_LAYOUT TYPE SLIS_LAYOUT_ALV ,
W_COLOR(3) ,
W_ROW TYPE I,
W_FIELDNAME(20),
W_PROG TYPE SY-REPID.
DATA:
BEGIN OF T_SPFLI OCCURS 0,
COLOR(3),
CHECKBOX ,
CELL TYPE SLIS_T_SPECIALCOL_ALV,
CARRID TYPE SPFLI-CARRID,
CONNID TYPE SPFLI-CONNID,
CITYFROM TYPE SPFLI-CITYFROM,
CITYTO TYPE SPFLI-CITYTO,
DISTANCE TYPE SPFLI-DISTANCE,
END OF T_SPFLI.
DATA:
FS_CELL LIKE LINE OF T_SPFLI-CELL.
SELECT *
FROM SPFLI
INTO CORRESPONDING FIELDS OF TABLE T_SPFLI.
FS_FIELDCAT-FIELDNAME = 'CARRID'.
FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
FS_FIELDCAT-COL_POS = 1.
FS_FIELDCAT-KEY = 'X'.
FS_FIELDCAT-HOTSPOT = 'X'.
APPEND FS_FIELDCAT TO T_FIELDCAT.
CLEAR FS_FIELDCAT .
FS_FIELDCAT-FIELDNAME = 'CONNID'.
FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
FS_FIELDCAT-COL_POS = 2.
FS_FIELDCAT-KEY = 'X'.
FS_FIELDCAT-HOTSPOT = 'X'.
APPEND FS_FIELDCAT TO T_FIELDCAT.
CLEAR FS_FIELDCAT .
FS_FIELDCAT-FIELDNAME = 'DISTANCE'.
FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
*FS_FIELDCAT-INPUT = 'X'.
FS_FIELDCAT-COL_POS = 3.
FS_FIELDCAT-KEY = ' '.
FS_FIELDCAT-EDIT = 'X'.
APPEND FS_FIELDCAT TO T_FIELDCAT.
CLEAR FS_FIELDCAT.
FS_FIELDCAT-FIELDNAME = 'CITYFROM'.
FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
FS_FIELDCAT-COL_POS = 4.
FS_FIELDCAT-KEY = ' '.
APPEND FS_FIELDCAT TO T_FIELDCAT.
LOOP AT T_SPFLI WHERE DISTANCE GT 600.
W_FIELDNAME = 'DISTANCE'.
FS_CELL-FIELDNAME = W_FIELDNAME .
FS_CELL-COLOR-COL = 5.
FS_CELL-NOKEYCOL = 'X'.
APPEND FS_CELL TO T_SPFLI-CELL.
MODIFY T_SPFLI TRANSPORTING CELL.
ENDLOOP.
FS_LAYOUT-INFO_FIELDNAME = 'COLOR'.
FS_LAYOUT-BOX_FIELDNAME = 'CHECKBOX'.
FS_LAYOUT-COLTAB_FIELDNAME = 'CELL'.
FS_LAYOUT-F2CODE = '&ETA'.
W_PROG = SY-REPID.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = W_PROG
IS_LAYOUT = FS_LAYOUT
IT_FIELDCAT = T_FIELDCAT
TABLES
T_OUTTAB = T_SPFLI
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.
Hope this is helpful to u .
Warm Regards,
Srilu.
04-20-2009 10:52 AM
Hi Ravi,
Please cehck the below mentioned links for your requirement.
http://www.sapdev.co.uk/reporting/alv/alvgrid_color.htm
http://www.sapfans.com/forums/viewtopic.php?t=52107
Hope this will help you.
Best Regards,
Deepa Kulkarni
04-20-2009 10:58 AM
Ravi,
Check the link below.
https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/coloringaRowandColumninALV+%2528OOPS%2529
Regards,
Murthy.
04-20-2009 10:59 AM
HI,
Check this link this will help you.
[http://yashtechiesabap.blogspot.com/2008/06/interactive-alv-and-colouring-cells.html]
Thanks and regards,
Priya
04-20-2009 11:03 AM
Hi,
Try below code
Add the below fields
cell TYPE slis_t_specialcol_alv,
color(3) . to the final table
&---------------------------------------------------------------------*
*& Form SET_CELL_COLOURS
&---------------------------------------------------------------------
* Set colour of individual ALV cell, field
----------------------------------------------------------------------
FORM SET_CELL_COLOURS .
DATA: fs_cell LIKE LINE OF gt_final-cell.
LOOP AT gt_final INTO gw_final WHERE qty_6 EQ '0'.
ld_index = sy-tabix.
w_fieldname = 'QTY_6'.
fs_cell-fieldname = w_fieldname .
fs_cell-color-col = 6.
fs_cell-nokeycol = 'X'.
APPEND fs_cell TO gw_final-cell.
MODIFY gt_final INDEX ld_index FROM gw_final TRANSPORTING cell.
ENDLOOP.
ENDFORM. " SET_CELL_COLOURS
Regards
Bala Krishna
Edited by: Bala Krishna on Apr 20, 2009 3:34 PM
04-20-2009 12:35 PM
Hello Bala,
Actually my problem is I want to add this in some other code.
In which he following steps,
1. Fetching data in internal table.
2.Creating the field catalog ( Names of ALV columns)
4 PERFORM fill_fieldcat USING:
'MATNR' 'Material',
'MAKTX' 'Material Descript
5.FORM fill_fieldcat USING iv_fieldname
iv_seltext.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname = iv_fieldname.
gs_fieldcat-seltext_l = iv_seltext.
APPEND gs_fieldcat TO gt_fieldcat.
My query is where i add the code.
04-20-2009 11:09 AM
Hi.. follow the steps...
Declare
DATA : ISO_CELL_COLOR TYPE LVC_T_SCOL, "Sorted table for cell coloring purpose
W_CELL_COLOR TYPE LVC_S_SCOL. "work area for cell coloring purpose.
Add following column in your internal table which u are using for fieldcatalog...
ISO_CELL_COLOR TYPE LVC_T_SCOL
Then Add following code....when filling the record in field catalog internal table...
LOOP AT ITAB_FINAL INTO WA_FINAL.
IF WA_FINAL-SKALAB EQ 0.
CLEAR W_CELL_COLOR.
W_CELL_COLOR-FNAME = 'SKALAB'.
W_CELL_COLOR-COLOR-COL = '6'.
W_CELL_COLOR-COLOR-INT = '1'.
W_CELL_COLOR-COLOR-INV = '1'.
APPEND W_CELL_COLOR TO ISO_CELL_COLOR.
WA_FINAL-ISO_CELL_COLOR = ISO_CELL_COLOR.
ENDIF.
MODIFY ITAB_FINAL FROM WA_FINAL TRANSPORTING ISO_CELL_COLOR SKALAB.
REFRESH ISO_CELL_COLOR.
ENDLOOP.
here Loop is for your internal table which u are using for field catalog...
WA_FINAL-SKALAB is ur field for which u want to put "0" value condition....
here red color will be displayed...
This will surly helpful to u....
Regards,
Chintan
Edited by: Chintan_SAP on Apr 20, 2009 3:40 PM
04-20-2009 11:42 AM
Hi,
step 1)declare a field in the final internal table that you will provide to FM resue_alv_grid_display as shown below.
data :begin of t_final occurs 0,
cell type lvc_t_scol,
end of t_final.
data:fs_cell type lvc_s_scol,
x_layout type slis_layout_alv.
step 2)procedure to populate the color
fs_cell-fname = fieldname----
> for which field you want to put the color
fs_cell-color-col = 5.----
>you have to give colors in numbers
ex:- 5---green
6---red
append fs_cell to t_final-cell.
step 3) settings we need to do for the layout.
x_layout-coltab_fieldname = 'CELL'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = g_repid
i_callback_user_command = 'HANDLE_USER_COMMAND'
I_callback_top_of_page = 'TOP-OF-PAGE1'
is_layout = x_layout
it_fieldcat = fieldcatalog[]
i_default = 'X'
i_save = 'A'
TABLES
t_outtab = t_final
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.