2006 Nov 02 12:01 PM
Hai ,
I want Color the rows in the list based on some condition ..
Hope to get the helpful suggestion s on this asap
regards,
Hai ,
I want Color the rows in the list based on some condition ..
Hope to get the helpful suggestion s on this asap
regards,
2006 Nov 02 12:03 PM
Hi ,
Refer the Link:
http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_color.htm
Reward points if this Helps.
Manish
2006 Nov 02 12:03 PM
hi,
report zxyz_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.
rgds
anver
2006 Nov 02 12:03 PM
Hi shishupalreddy,
1. Not only the full row color,
we can also manipulate the color in each cell,
based upon conditions.
2.
IMPORTANT THINGS
a. Extra field in internal table
clr TYPE slis_t_specialcol_alv,
(this field will contain the colour codes)
b. assign fieldname to alv layout
alvly-coltab_fieldname = 'CLR'
c. work area for colour
DATA : clrwa TYPE slis_specialcol_alv.
d. Populating the color
Once again
Loop at ITAB.
*********logic
if itab-field < 0 "---negative
clrwa-fieldname = 'FIELDNAME'. "<--- FIELDNAME FOR COLOR
clrwa-color-col = 6. <------- COLOUR 0-9
APPEND clrwa TO itab-clr.
MODIFY ITAB.
endif.
ENDLOOP.
*----
5. just copy paste in new program
6.
REPORT abc .
*----
NECESSARY / MUST
TYPE-POOLS : slis.
DATA : alvfc TYPE slis_t_fieldcat_alv.
DATA : alvly TYPE slis_layout_alv.
*----
ITAB DECLARATION
DATA : prg TYPE sy-repid.
DATA : BEGIN OF itab OCCURS 0.
INCLUDE STRUCTURE t001.
DATA : clname(3) TYPE c,
clr TYPE slis_t_specialcol_alv,
END OF itab.
DATA : clrwa TYPE slis_specialcol_alv.
PARAMETERS : a TYPE c.
DATA : flname TYPE slis_fieldname.
*----
SELECT
START-OF-SELECTION.
SELECT * FROM t001
INTO CORRESPONDING FIELDS OF TABLE itab..
LOOP AT itab..
IF SY-TABIX <= 5.
itab-clname = 'C50'.
ELSE.
itab-clname = 'C30'.
ENDIF.
MODIFY itab.
ENDLOOP.
LOOP AT ITAB.
check itab-bukrs = '1000'
.
clrwa-fieldname = 'BUTXT'.
clrwa-color-col = 6.
APPEND clrwa TO itab-clr.
MODIFY ITAB.
clrwa-fieldname = 'LAND1'.
clrwa-color-col = 4.
APPEND clrwa TO itab-clr.
MODIFY ITAB.
ENDLOOP.
prg = sy-repid.
flname = 'CLNAME'.
alvly-info_fieldname = 'CLNAME'.
alvly-coltab_fieldname = 'CLR'.
LOOP AT ITAB.
if sy-tabix = 3.
clrwa-fieldname = 'BUTXT'.
clrwa-color-col = 6.
APPEND clrwa TO itab-clr.
MODIFY ITAB.
clrwa-fieldname = 'LAND1'.
clrwa-color-col = 1.
APPEND clrwa TO itab-clr.
MODIFY ITAB.
endif.
ENDLOOP
.
*
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = prg
i_internal_tabname = 'ITAB'
i_inclname = prg
CHANGING
ct_fieldcat = alvfc
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
*----
minimum
*CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
it_fieldcat = alvfc
TABLES
t_outtab = itab
EXCEPTIONS
program_error = 1
OTHERS = 2
*.
*----
extra
sy-uname = 'XYZAB'.
prg = sy-repid.
*----
Excluding
DATA : excl TYPE slis_t_extab.
DATA : exclwa TYPE slis_extab.
exclwa = '&OUP'.
APPEND exclwa TO excl.
exclwa = '&ODN'.
APPEND exclwa TO excl.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
it_fieldcat = alvfc
i_callback_program = sy-repid
is_layout = alvly
i_callback_user_command = 'ITAB_USER_COMMAND'
it_excluding =
excl
i_save = 'A'
TABLES
t_outtab = itab
EXCEPTIONS
program_error = 1
OTHERS = 2.
&----
*& Form itab_user_command
&----
text
----
-->WHATCOMM text
-->WHATROW text
----
FORM itab_user_command USING whatcomm TYPE sy-ucomm whatrow TYPE
slis_selfield.
BREAK-POINT.
ENDFORM. "itab_user_command
regards,
amit m.
2006 Nov 02 12:07 PM
Chk the sample code and link.
http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_color.htm
http://help.sap.com/saphelp_erp2004/helpdata/en/7f/e477e2fba211d2b48f006094192fe3/content.htm
Alco have a look at BCALV_TREE_ITEMLAYOUT. It is present in 4.7 I think.
report zxyz_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.
Best Regards,
Vibha
*Please mark all the helpful answers
2006 Nov 02 12:07 PM
refer to the belwo code
data: begin of i_item_data occurs 0,
targt like yfia_forex_tsclr-targt, "Target System
ldind like yfia_forex_dstdt-ldind, "Load Indicator
udate like yfia_forex_tsclr-udate, "Created/Changed on
dstdt like yfia_forex_dstdt-dstdt, "Date
frcur like yfia_forex_tsclr-frcur, "From Currency
tocur like yfia_forex_tsclr-tocur, "To Currency
dstgr like yfia_forex_dstdt-dstgr, "Distribution Group
actin like yfia_forex_tsclr-actin, "Action
valdt like yfia_forex_tsclr-valdt, "Validity Date
trtty like yfia_forex_caldt-rttyp, "Forex Rate Type
oldvl like yfia_forex_tsclr-oldvl, "Old value
newvl like yfia_forex_tsclr-newvl, "New value
msgtx like yfia_forex_lderr-msgtx, "Message text
reasn like yfia_forex_tsclr-reasn, "Change reason
uname like yfia_forex_tsclr-uname, "Created/Changed by
utime like yfia_forex_tsclr-utime, "Created/Changed at
aprvr like yfia_forex_tsclr-aprvr, "Approver
<b> color type slis_t_specialcol_alv, "</b>
end of i_item_data.
While populating the final internal table
To display the Load Indicator field in green color
clear: i_color_tab, i_color_tab[].
wa_color_tab-fieldname = gc_ldind.
wa_color_tab-color-col = gc_color5.
wa_color_tab-color-int = gc_int1.
append wa_color_tab to i_color_tab.
move i_color_tab to i_item_data-color.
Regards,
Satya.
2006 Nov 02 12:09 PM
Also refer to the sample program.
----
*- Setting Colors in ALV
----
REPORT YSIVAM_TEST
MESSAGE-ID ZZ
LINE-SIZE 170
LINE-COUNT 58(2)
NO STANDARD PAGE HEADING.
************************************************************
TABLES: T001W.
TYPE-POOLS: SLIS.
DATA: GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA: WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
DATA: GS_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA: WA_COLOR_TAB TYPE SLIS_SPECIALCOL_ALV.
DATA: G_CELL_COLOR TYPE SLIS_COLOR.
DATA: IT_COLOR_TAB TYPE SLIS_T_SPECIALCOL_ALV.
DATA: G_TABIX LIKE SY-TABIX.
DATA: BEGIN OF ITAB OCCURS 10,
WERKS LIKE T001W-WERKS,
NAME1 LIKE T001W-NAME1,
END OF ITAB.
DATA: BEGIN OF ITAB1 OCCURS 10,
WERKS LIKE T001W-WERKS,
NAME1 LIKE T001W-NAME1,
COLOR1 TYPE SLIS_T_SPECIALCOL_ALV,
END OF ITAB1.
PERFORM BUID_FIELDCATLOG.
*
CLEAR GS_LAYOUT.
GS_LAYOUT-COLTAB_FIELDNAME = 'COLOR1'.
*
PERFORM READ_DATA.
*
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IS_LAYOUT = GS_LAYOUT
IT_FIELDCAT = GT_FIELDCAT
TABLES
T_OUTTAB = ITAB1
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
*&----
*& Form buid_fieldcatlog
*&----
FORM BUID_FIELDCATLOG.
REFRESH GT_FIELDCAT.
*
CLEAR WA_FIELDCAT.
WA_FIELDCAT-FIELDNAME = 'WERKS'.
WA_FIELDCAT-REF_TABNAME = 'T001W'.
APPEND WA_FIELDCAT TO GT_FIELDCAT.
*
CLEAR WA_FIELDCAT.
WA_FIELDCAT-FIELDNAME = 'NAME1'.
WA_FIELDCAT-REF_TABNAME = 'T001W'.
APPEND WA_FIELDCAT TO GT_FIELDCAT.
ENDFORM. " buid_fieldcatlog
*&----
*& Form READ_DATA
*&----
FORM READ_DATA.
SELECT WERKS
NAME1
INTO
CORRESPONDING FIELDS OF TABLE ITAB
FROM T001W.
LOOP AT ITAB.
G_TABIX = SY-TABIX.
PERFORM SET_CELL_COLORS.
*
MOVE ITAB-WERKS TO ITAB1-WERKS.
MOVE ITAB-NAME1 TO ITAB1-NAME1.
MOVE IT_COLOR_TAB TO ITAB1-COLOR1.
APPEND ITAB1.
ENDLOOP.
ENDFORM. " READ_DATA
*&----
*& Form SET_CELL_COLORS
*&----
FORM SET_CELL_COLORS.
CLEAR IT_COLOR_TAB[].
*SETTING CELL COLOR
G_CELL_COLOR = G_TABIX MOD 7.
***********************************
*SETTING CELL COLOR
IF G_CELL_COLOR = 7.
G_CELL_COLOR = 0.
ELSE.
G_CELL_COLOR = G_CELL_COLOR + 1.
ENDIF.
***********************************
CLEAR WA_COLOR_TAB.
WA_COLOR_TAB-FIELDNAME = 'WERKS'.
WA_COLOR_TAB-COLOR-COL = G_CELL_COLOR.
APPEND WA_COLOR_TAB TO IT_COLOR_TAB.
***********************************
*SETTING CELL COLOR
IF G_CELL_COLOR = 7.
G_CELL_COLOR = 0.
ELSE.
G_CELL_COLOR = G_CELL_COLOR + 1.
ENDIF.
***********************************
CLEAR WA_COLOR_TAB.
WA_COLOR_TAB-FIELDNAME = 'NAME1'.
WA_COLOR_TAB-COLOR-COL = G_CELL_COLOR.
APPEND WA_COLOR_TAB TO IT_COLOR_TAB.
ENDFORM. " SET_CELL_COLORS
2006 Nov 02 12:17 PM
HAI all ,
thank you so much for the responce but the problem is with my final itab
DATA:BEGIN OF t_out OCCURS 0.
INCLUDE STRUCTURE typ_t_out.
DATA : clname(3) TYPE c,
clr TYPE slis_t_specialcol_alv,
END OF T_OUT.
.
here Im doing COLLECT on this itab and hence giving the error .
correct me if any error is there in the declaration of the itab with color field ..
regards,
2006 Nov 02 12:20 PM
Hi Ramreddy,
data : begin of it_final occurs 0,
ebeln like ekpo-ebeln,
ebelp like ekpo-ebelp,
matnr like ekpo-matnr,
menge like ekpo-menge,
meins like ekpo-meins,
netpr like ekpo-netpr,
netwr like ekpo-netwr,
<b> line_color(4) type c, "row color</b>
end of it_final.
loop at it_ekpo.
it_final-ebeln = it_ekpo-ebeln.
it_final-ebelp = it_ekpo-ebelp.
it_final-matnr = it_ekpo-matnr.
it_final-menge = it_ekpo-menge.
it_final-meins = it_ekpo-meins.
it_final-netpr = it_ekpo-netpr.
it_final-netwr = it_ekpo-netwr.
<b> on change of it_final-ebeln.
ld_color = 7.
concatenate 'C' ld_color '10' into it_final-line_color.
endon.</b> append it_final.
clear it_final.
endloop.
wa_layout-colwidth_optimize = 'X'. "OPTIMIZING FIELD WIDTH
wa_layout-zebra = 'X'. "PUTTING ZEBRA COLORS
wa_layout-totals_text = 'Total'.
wa_layout-subtotals_text = 'SUB TOTAL'.
<b>wa_layout-info_fieldname = 'LINE_COLOR'.</b>
Thanks
Vikranth Khimavath