Row color in ALV
Hi all,
I am trying to display some selected rows in my report in a different color.
But its not working.
I have .....
i_gs_layout-info_fieldname = 'COLOR_LINE'.
my internal table to be displayed is...
DATA: BEGIN OF T_DISPLAY OCCURS 0,
MATNR TYPE MARA-MATNR,
LOSMENGE TYPE QALS-LOSMENGE,
SLMENGE TYPE MSEG-MENGE,
SL_PPM TYPE P DECIMALS 2,
COLOR_LINE(4) TYPE C,
END OF T_DISPLAY.
On some conditions I am filling the field COLOR_LINE with 'C610'.
The following function module is used for display.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = i_g_repid
i_callback_user_command = ''
i_callback_pf_status_set = ''
i_grid_title = l_title
is_layout = i_gs_layout
it_events = i_gt_events[]
it_fieldcat = i_gt_fieldcat[]
it_sort = i_gt_sort[]
i_save = 'A'
TABLES
t_outtab = T_DISPLAY.
Here everything is working fine except the color.
Eventhough I have the value C610 in my internal table in most of the rows, no row is getting displayed in this color.
Should I use some other function module or am I missing something in this code..?
Hi,
Check this link..
http://www.sap-img.com/abap/line-color-in-alv-example.htm
Check this simple example..
Macro definition
DEFINE m_fieldcat.
add 1 to ls_fieldcat-col_pos.
ls_fieldcat-fieldname = &1.
ls_fieldcat-ref_tabname = &2.
append ls_fieldcat to lt_fieldcat.
END-OF-DEFINITION.
TYPE-POOLS: slis. " ALV Global types
TYPES:
BEGIN OF ty_vbak,
vkorg TYPE vbak-vkorg, " Sales organization
kunnr TYPE vbak-kunnr, " Sold-to party
vbeln TYPE vbak-vbeln, " Sales document
netwr TYPE vbak-netwr, " Net Value of the Sales Order
line_color(4), " Line color
END OF ty_vbak.
DATA:
Data displayed
gt_vbak TYPE TABLE OF ty_vbak.
START-OF-SELECTION.
PERFORM f_read_data.
PERFORM f_fill_color.
PERFORM f_display_data.
Form f_read_data
FORM f_read_data.
SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_vbak
FROM vbak UP TO 100 ROWS.
ENDFORM. " F_READ_DATA
Form f_fill_color
FORM f_fill_color.
DATA l_rnd_value TYPE integer2.
FIELD-SYMBOLS <vbak> TYPE ty_vbak.
LOOP AT gt_vbak ASSIGNING <vbak>.
Random value
CALL FUNCTION 'RANDOM_I2'
EXPORTING
rnd_min = 0
rnd_max = 3
IMPORTING
rnd_value = l_rnd_value.
CASE l_rnd_value.
WHEN 0.
<vbak>-line_color = 'C100'. " Blue.
WHEN 1.
<vbak>-line_color = 'C300'. " Yellow.
WHEN 2.
<vbak>-line_color = 'C500'. " Green.
WHEN 3.
<vbak>-line_color = 'C600'. " Red.
ENDCASE.
ENDLOOP.
ENDFORM. " F_FILL_COLOR
Form f_display_data
FORM f_display_data.
DATA:
ls_layout TYPE slis_layout_alv,
ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv.
Build the field catalog
m_fieldcat 'VKORG' 'VBAK'.
m_fieldcat 'KUNNR' 'VBAK'.
m_fieldcat 'VBELN' 'VBAK'.
m_fieldcat 'NETWR' 'VBAK'.
Fill Layout - Name of the field with color
ls_layout-info_fieldname = 'LINE_COLOR'.
Display the list
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = ls_layout
it_fieldcat = lt_fieldcat
TABLES
t_outtab = gt_vbak.
ENDFORM. " F_DISPLAY_DATA
Thanks,
Naren
Similar Messages
-
hi
how can i change row color on alv.Hi
thanks your answer Uday Gubbala
i was examinated this link [https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/abapWebDynproALV-ChangeCellColourbasedonContent]
but i don't do this row wd_this->m_alv_model = lo_value. error message : m_alv_model unknow.
and this sample change column color but i want to row
Thanks. -
To change the subtotals row color in ALV(Grid / List ) .
I am trying to change the color of a row which gives the subtotal...in ALV report...
but it is not working....
I have used the following code but not getting where i m wrong
I have u sed the following code wih the help of our forum only...
<CODE>
TYPE-POOLS: SLIS.
*& Internal Table Delcaration
DATA : BEGIN OF IT_SCALE OCCURS 0,
DATUM LIKE ZSCALE-DATUM,
MCOD1 LIKE ZSCALE-MCOD1,
MATNR LIKE ZSCALE-MATNR,
MAKTG LIKE ZSCALE-MAKTG,
MEINS LIKE ZSCALE-MEINS,
RATE LIKE ZSCALE-RATE,
TOTAL LIKE ZSCALE-TOTAL,
LI_COLOR(4),
END OF IT_SCALE.
DATA : INDEX LIKE SY-TABIX.
*& ALV Data Declaration
DATA: IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA: WA_FIELDCAT LIKE LINE OF IT_FIELDCAT.
DATA : T_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.
DATA : IT_EVENTS TYPE SLIS_T_EVENT WITH HEADER LINE.
DATA : G_SAVE(1) TYPE C VALUE 'A',
GX_SAVE(1) TYPE C VALUE 'A',
GX_VARIANT LIKE DISVARIANT,
G_VARIANT LIKE DISVARIANT,
GS_LAYOUT TYPE SLIS_LAYOUT_ALV,
T_FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE',
T_I_EVENT TYPE SLIS_ALV_EVENT.
DATA : L_LIST(105) TYPE C, "Store the Top-of-page headings
L_DATEFROM(10) TYPE C, "Store date in top-of-page
L_DATETO(10) TYPE C. "Store date in top-of-page
<code>
START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM ALV_FIELDCAT.
PERFORM GET_EVENTS.
PERFORM SUB_COMMENT_BUILD USING T_LIST_TOP_OF_PAGE.
PERFORM ALV_DISPLAY.
FORM GET_DATA .
DATA : LINE_COLOR.
SELECT DATUM MCOD1 MATNR MAKTG MEINS RATE TOTAL
FROM ZSCALE INTO CORRESPONDING FIELDS OF TABLE IT_SCALE
WHERE DATUM IN S_DATE
AND LIFNR IN S_LIFNR
AND MATNR IN S_MATNR.
loop at IT_SCALE.
LINE_color = LINE_color + 2.
if LINE_color < 7.
LINE_color = 1.
endif.
concatenate 'C' lINE_color '00' into IT_SCALE-li_color.
modify it_SCALE TRANSPORTING LI_COLOR.
endloop.
FORM ALV_FIELDCAT.
DATA: COUNTER TYPE I.
COUNTER = COUNTER + 1.
WA_FIELDCAT-COL_POS = COUNTER.
WA_FIELDCAT-FIELDNAME = 'DATUM'.
WA_FIELDCAT-TABNAME = 'IT_SCALE'.
WA_FIELDCAT-SELTEXT_L = 'Date'.
WA_FIELDCAT-JUST = 'C'.
WA_FIELDCAT-NO_ZERO = 'X'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.
.endform.
FORM ALV_DISPLAY .
GS_LAYOUT-ZEBRA = 'X'.
GS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
GS_LAYOUT-INFO_FIELDNAME = 'LINE_COLOR'.
gS_layout-no_input = 'X'.
gS_layout-totals_text = 'Totals'(201).
gS_layout-subtotals_text = 'Subtotal'.
IF IT_SCALE[] IS INITIAL.
MESSAGE I001(38) WITH 'No Data to Display'.
ELSE.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT = GS_LAYOUT
IT_FIELDCAT = IT_FIELDCAT
I_SAVE = G_SAVE
IS_VARIANT = GX_VARIANT
TABLES
T_OUTTAB = IT_SCALE[].
ENDIF.
ENDFORM. " ALV_DISPLAY
ThanX in Adavance....Hi Prasad,
I provided some code snippets for you. Please go through.
Hope this proves to be helpful to you.
The steps for coloring a line i the grid is much the same as making a traffic light.
To color a line the structure of the table must include a Char 4 field for color properties
TYPES: BEGIN OF st_sflight.
INCLUDE STRUCTURE zsflight.
Field for line color
types: line_color(4) type c.
TYPES: END OF st_sflight.
TYPES: tt_sflight TYPE STANDARD TABLE OF st_sflight.
DATA: gi_sflight TYPE tt_sflight.
Loop trough the table to set the color properties of each line. The color properties field is
Char 4 and the characters is set as follows:
Char 1 = C = This is a color property
Char 2 = 6 = Color code (1 - 7)
Char 3 = Intensified on/of = 1 = on
Char 4 = Inverse display = 0 = of
LOOP AT gi_sflight INTO g_wa_sflight.
IF g_wa_sflight-paymentsum < 100000.
g_wa_sflight-line_color = 'C610'.
ENDIF.
MODIFY gi_sflight FROM g_wa_sflight.
ENDLOOP.
Name of the color field
gs_layout-info_fname = 'LINE_COLOR'.
Grid setup for first display
CALL METHOD go_grid->set_table_for_first_display
EXPORTING i_structure_name = 'SFLIGHT'
is_layout = gs_layout
CHANGING it_outtab = gi_sflight.
Heres another Example for you:
& Report Z_ALV_COLOURS &
& This report shows how to use colours in REUSE_ALV_GRID_DISPLAY &
& C = Colour (all codes must start with 'C') &
& X = Colour number (1-9) &
& Y = Intensified (0 = off, 1 = on) &
& Z = Inverse (0 = off, 1 = on) &
report z_alv_colours.
data count_1(1) type c.
ALV definitions
type-pools: slis.
data i_fieldcat type slis_t_fieldcat_alv with header line.
data i_layout type slis_layout_alv.
types: begin of t_alv,
f1(4) type c,
f2(15) type c,
f3(4) type c,
f4(4) type c,
f5(4) type c,
f6(4) type c,
colour(4) type c,
coltab type slis_t_specialcol_alv,
end of t_alv.
data: i_alv type standard table of t_alv with header line.
data l_alvcolor type slis_specialcol_alv.
& create table entries for LINE colours &
do 9 times.
count_1 = sy-index.
clear i_alv.
concatenate 'C' count_1 '0' '0' into i_alv-f1.
concatenate 'C' count_1 '0' '0' into i_alv-colour.
i_alv-f2 = 'Line colour'.
i_alv-f3 = 'X'.
append i_alv.
Intensified
clear i_alv.
concatenate 'C' count_1 '1' '0' into i_alv-f1.
concatenate 'C' count_1 '1' '0' into i_alv-colour.
i_alv-f2 = 'Line colour'.
i_alv-f4 = 'X'.
append i_alv.
Inverse
clear i_alv.
concatenate 'C' count_1 '0' '1' into i_alv-f1.
concatenate 'C' count_1 '0' '1' into i_alv-colour.
i_alv-f2 = 'Line colour'.
i_alv-f5 = 'X'.
append i_alv.
Intensified & Inverse
clear i_alv.
concatenate 'C' count_1 '1' '1' into i_alv-f1.
concatenate 'C' count_1 '1' '1' into i_alv-colour.
i_alv-f2 = 'Line colour'.
i_alv-f6 = 'X'.
append i_alv.
enddo.
create table entries for CELL colours
do 9 times.
count_1 = sy-index.
concatenate 'C' count_1 '0' '0' into i_alv-f1.
i_alv-f2 = 'Cell colour'.
concatenate 'C' count_1 '0' '0' into i_alv-f3.
concatenate 'C' count_1 '1' '0' into i_alv-f4.
concatenate 'C' count_1 '0' '1' into i_alv-f5.
concatenate 'C' count_1 '1' '1' into i_alv-f6.
append i_alv.
enddo.
& Create table entries for CELL colours &
loop at i_alv where f2 = 'Cell colour'.
Colour cells
clear l_alvcolor.
l_alvcolor-fieldname = 'F3'.
l_alvcolor-color-col = i_alv-f3+1(1).
l_alvcolor-color-int = i_alv-f3+2(1).
l_alvcolor-color-inv = i_alv-f3+3(1).
l_alvcolor-nokeycol = 'X'.
append l_alvcolor to i_alv-coltab.
clear l_alvcolor.
l_alvcolor-fieldname = 'F4'.
l_alvcolor-color-col = i_alv-f4+1(1).
l_alvcolor-color-int = i_alv-f4+2(1).
l_alvcolor-color-inv = i_alv-f4+3(1).
l_alvcolor-nokeycol = 'X'.
append l_alvcolor to i_alv-coltab.
clear l_alvcolor.
l_alvcolor-fieldname = 'F5'.
l_alvcolor-color-col = i_alv-f5+1(1).
l_alvcolor-color-int = i_alv-f5+2(1).
l_alvcolor-color-inv = i_alv-f5+3(1).
l_alvcolor-nokeycol = 'X'.
append l_alvcolor to i_alv-coltab.
clear l_alvcolor.
l_alvcolor-fieldname = 'F6'.
l_alvcolor-color-col = i_alv-f6+1(1).
l_alvcolor-color-int = i_alv-f6+2(1).
l_alvcolor-color-inv = i_alv-f6+3(1).
l_alvcolor-nokeycol = 'X'.
append l_alvcolor to i_alv-coltab.
modify i_alv.
endloop.
& Configure ALV settings &
Create field catalog
perform create_field_catalog using 'F1' 'T_ALV' 'Colour name'.
perform create_field_catalog using 'F2' 'T_ALV' 'Description'.
perform create_field_catalog using 'F3' 'T_ALV' 'BaseColour'.
perform create_field_catalog using 'F4' 'T_ALV' 'Intensified'.
perform create_field_catalog using 'F5' 'T_ALV' 'Inverse'.
perform create_field_catalog using 'F6' 'T_ALV' 'Both Inv/Int'.
perform create_field_catalog using 'COLOUR' 'T_ALV' 'Colour'.
Layout
clear i_layout.
i_layout-colwidth_optimize = 'X'.
i_layout-info_fieldname = 'COLOUR'. " for line colour
i_layout-coltab_fieldname = 'COLTAB'. " for cell colour
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = sy-cprog
i_callback_user_command = 'USER_COMMAND'
is_layout = i_layout
it_fieldcat = i_fieldcat[]
i_default = 'X'
i_save = 'A'
tables
t_outtab = i_alv.
& Form CREATE_FIELD_CATALOG &
form create_field_catalog using p_fieldname
p_tabname
p_text.
i_fieldcat-fieldname = p_fieldname.
i_fieldcat-tabname = p_tabname.
i_fieldcat-seltext_l = p_text.
append i_fieldcat.
endform. " CREATE_FIELD_CATALOG
For more information about Coloring in ALV, Please refer :
Coloring Rows in ALV
Hope this helps you in solving your issue.
Please Reward Points if any of the above points are helpful to you.
Regards,
Kalyan Chakravarthy -
ALV rows coloring based on condition
Hai ,
I want Color the rows in the list based on some condition ..
Hope to get the helpful suggestion s on this asap
regards,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. -
Color individual rows in an ALV Grid
Hello,
in an ALV grid I have to distinguish between certain values in the rows so I wanted to use different colors. I see how to change the color of the columns but cannot work out how to change individual row color. I don´t see any values for this in 'Fieldcat'.
Can anybody help?
Thank you,
KevinHere is a sample, program, implement it, it will show you what you need to do.
* 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 *
report zrich_0001
no standard page heading.
* 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"
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_check 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.
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.
data: this_color(10) type c.
data: index(3) type c.
select * from mara up to 5 rows.
clear wa_mara-color_line.
move-corresponding mara to wa_mara.
add 1 to wa_mara-counter.
move 'Blabla' to wa_mara-free_text.
* Color line, differnt color for each line
index = sy-tabix.
concatenate 'C' index '10' into this_color.
condense this_color no-gaps.
wa_mara-color_line = this_color.
append wa_mara to it_mara.
endselect.
endform.
*& Form fill_catalog
form fill_catalog.
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.
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,
Rich HEilman
Updated the code a bit
Message was edited by: Rich Heilman -
Adding a color to row of a alv grid using function modules
Can anybody clearly explains me how to add a color to a row to an alv grid using function module reuse_alv_grid_display.
thanks in advance
regards
anil.hi,
chk this ample pgm
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.
<b>anil , pls chk this link also.
http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_color.htm
very hlpful.</b>
rgds
anver
<b>pls mark points if ur issue solved</b>
Message was edited by: Anversha s
Message was edited by: Anversha s -
Can we change row colors according to the values in ALV LIST
Reg,
Archanahai Archana,
REPORT zcuitest_alv_07.
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.
START-OF-SELECTION.
PERFORM get_data.
END-OF-SELECTION.
PERFORM fill_catalog.
PERFORM fill_layout.
CALL SCREEN 2000.
*& Module status_2000 OUTPUT
text
MODULE status_2000 OUTPUT.
SET PF-STATUS '2000'.
ENDMODULE. " status_2000 OUTPUT
*& Module user_command_2000 INPUT
text
MODULE user_command_2000 INPUT.
DATA : w_okcode LIKE sy-ucomm.
MOVE okcode TO w_okcode.
CLEAR okcode.
CASE w_okcode.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " user_command_2000 INPUT
*& Module alv_grid OUTPUT
text
MODULE alv_grid OUTPUT.
IF w_docking_container IS INITIAL.
PERFORM create_objects.
PERFORM display_alv_grid.
ENDIF.
ENDMODULE. " alv_grid OUTPUT
*& Form create_objects
text
--> p1 text
<-- p2 text
FORM create_objects.
Ratio must be included in [5..95]
CREATE OBJECT w_docking_container
EXPORTING
ratio = 95
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.
ENDFORM. " create_objects
*& Form display_alv_grid
text
--> p1 text
<-- p2 text
FORM display_alv_grid.
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. " display_alv_grid
*& Form get_data
text
--> p1 text
<-- p2 text
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 '5' 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. " get_data
*& Form fill_catalog
text
--> p1 text
<-- p2 text
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. " fill_catalog
*& Form fill_layout
text
--> p1 text
<-- p2 text
FORM fill_layout.
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.
ENDFORM. " fill_layout
Regards.
Eshwar. -
Hi All
I would be greatful if someone could please help...
I am still attempting to get cells painted within a WDA ALV grid display.
I have tried to use the method stated in the WDA sap press book - but this method is for use with TABLE element and I am using a ViewContainerUIElement for my table. There are mentions of wonderful ways to color cells in a list display - but I cannot understand how this can be achieved. I currently have this working appart from the numeric numbers of the design being set into the relavant column cell.
If anyone could help that would be great...
Please see: http://picasaweb.google.co.uk/dave.alexander69/Pictures#5244800978549492338
LOOP AT lt_zdata INTO ls_zdata.
lv_index = sy-tabix.
* set column values
* loop at row data and set colour attributes of individual cells
LOOP AT lt_columns ASSIGNING <fs_column>.
lr_col_header = <fs_column>-r_column->get_header( ).
lr_col_header->set_ddic_binding_field( ).
CREATE OBJECT lr_input_field EXPORTING value_fieldname = <fs_column>-id.
lr_column = lr_column_settings->get_column( <fs_column>-id ).
* for the date columns only...
IF <fs_column>-id(4) = 'CELL'.
* get and set column dates from select option user input
READ TABLE lt_dates INTO ls_dates INDEX 1.
IF lt_dates IS INITIAL.
lr_col_header->set_text( 'Date' ).
ELSE.
ls_dates-low = ls_dates-low + lv_incr_date.
MOVE ls_dates-low+2(2) TO lv_for_col_date+6(2). "Year
MOVE ls_dates-low+4(2) TO lv_for_col_date+3(2). "Month
MOVE ls_dates-low+6(2) TO lv_for_col_date(2). "Day
MOVE lv_for_col_date TO lv_col_date.
lr_col_header->set_text( lv_col_date ).
lv_incr_date = lv_incr_date + 7.
ENDIF.
LOOP AT lt_orgdata_dates INTO ls_orgdata_dates
WHERE crew = ls_zdata-crew
AND position = ls_zdata-position
AND name = ls_zdata-person
AND trip_arr >= ls_dates-low
AND trip_dep <= ls_dates-low.
* column heading settings
lr_field = lr_table->if_salv_wd_field_settings~get_field( <fs_column>-id ).
lr_field->if_salv_wd_sort~set_sort_allowed( abap_false ).
* trying to set cell variants ?@#??!!???
* lr_cv = lr_column->set_key( ls_zdata-variance ).
* lr_cv->set_editor( lr_input_field ).
* lr_cv->set_cell_design( value = '01').
* lr_column->add_cell_variant( lr_cv ).
* current method of seeting the cell colors... (but puts value in cell!)
FIELD-SYMBOLS: <fs> TYPE data.
lr_column->set_cell_design_fieldname( value = <fs_column>-id ).
ASSIGN COMPONENT <fs_column>-id OF STRUCTURE ls_zdata TO <fs>.
WRITE: CL_WD_TABLE_COLUMN=>e_cell_design-one TO <fs>.
MODIFY lt_zdata FROM ls_zdata. " INDEX lv_index.
ENDLOOP.
ENDIF.
Kind Regards
Dave AlexanderHi check this code to set cell colors for ALV grid.
Take a context attribute with type WDUI_TABLE_CELL_DESIGN.
Here i am populating colors based on some condition.Check the loop of the internal table.
method get_flight_details .
data:node_flights type ref to if_wd_context_node,
it_flights type sflight_tab1,
ls_flights type sflight,
it_final type if_componentcontroller=>elements_flights,
ls_final type if_componentcontroller=>element_flights.
select * from sflight into table it_flights
up to 100 rows.
node_flights = wd_context->get_child_node( 'FLIGHTS' ).
loop at it_flights into ls_flights.
move-corresponding ls_flights to ls_final.
if ls_final-price = '185.00'.
ls_final-readonly = abap_true.
ls_final-celldesign =
cl_wd_table_column=>e_cell_design-badvalue_light.
else.
ls_final-readonly = ' '.
ls_final-celldesign =
cl_wd_table_column=>e_cell_design-goodvalue_light.
endif.
append ls_final to it_final.
endloop.
node_flights->bind_table(
new_items = it_final
set_initial_elements = abap_true
* INDEX = INDEX
data: l_ref_cmp_usage type ref to if_wd_component_usage.
l_ref_cmp_usage = wd_this->wd_cpuse_alv( ).
if l_ref_cmp_usage->has_active_component( ) is initial.
l_ref_cmp_usage->create_component( ).
endif.
data: l_ref_interfacecontroller type ref to iwci_salv_wd_table .
l_ref_interfacecontroller = wd_this->wd_cpifc_alv( ).
data:
l_value type ref to cl_salv_wd_config_table.
l_value = l_ref_interfacecontroller->get_model(
* Make Price column editable
data:l_column type ref to cl_salv_wd_column,
l_column1 type ref to cl_salv_wd_column,
lr_input type ref to cl_salv_wd_uie_input_field,
l_input1 type ref to cl_salv_wd_uie_input_field.
l_column = l_value->if_salv_wd_column_settings~get_column( 'PRICE' ).
create object lr_input
exporting
value_fieldname = 'PRICE'
l_column->set_cell_editor( value = lr_input ).
* to make some cells non editable
lr_input->set_read_only_fieldname( value = 'READONLY' ).
l_value->if_salv_wd_column_settings~delete_column( id = 'READONLY' )
*Set the table Editable
l_value->if_salv_wd_table_settings~set_read_only( value = abap_false ).
*Give colors to cells
l_column1 = l_value->if_salv_wd_column_settings~get_column( 'CARRID' ).
l_column1->set_cell_design_fieldname( value = 'CELLDESIGN' ).
l_value->if_salv_wd_column_settings~delete_column( id = 'CELLDESIGN' )
endmethod.
Thanks
Suman -
Hi How can i add colors in alv.
Can you pls give a good example for this.
thank you,
DeepakHI,
i am sending you a complete woking code ..you just run it and see the option in the output screen..select any of the check box and hit F8..and there it is.. you can modify the code to meet yur need
Reward point if it satisfy your needs..
REPORT ZOBJK1 .
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 = 40
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. -
HELLO,
can u tell me that i want to color column in alv so how to use it ingrid layout.
thanks.*& Report ZDEMO_ALVGRID *
*& Example of a simple ALV Grid Report *
*& The basic ALV grid, Enhanced to display each row in a different *
*& colour *
REPORT zdemo_alvgrid .
TABLES: ekko.
type-pools: slis. "ALV Declarations
*Data Declaration
TYPES: BEGIN OF t_ekko,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
statu TYPE ekpo-statu,
aedat TYPE ekpo-aedat,
matnr TYPE ekpo-matnr,
menge TYPE ekpo-menge,
meins TYPE ekpo-meins,
netpr TYPE ekpo-netpr,
peinh TYPE ekpo-peinh,
line_color(4) type c, "Used to store row color attributes
END OF t_ekko.
DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
wa_ekko TYPE t_ekko.
*ALV data declarations
data: fieldcatalog type slis_t_fieldcat_alv with header line,
gd_tab_group type slis_t_sp_group_alv,
gd_layout type slis_layout_alv,
gd_repid like sy-repid.
*Start-of-selection.
START-OF-SELECTION.
perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform display_alv_report.
*& Form BUILD_FIELDCATALOG
* Build Fieldcatalog for ALV Report
form build_fieldcatalog.
* There are a number of ways to create a fieldcat.
* For the purpose of this example i will build the fieldcatalog manualy
* by populating the internal table fields individually and then
* appending the rows. This method can be the most time consuming but can
* also allow you more control of the final product.
* Beware though, you need to ensure that all fields required are
* populated. When using some of functionality available via ALV, such as
* total. You may need to provide more information than if you were
* simply displaying the result
* I.e. Field type may be required in-order for
* the 'TOTAL' function to work.
fieldcatalog-fieldname = 'EBELN'.
fieldcatalog-seltext_m = 'Purchase Order'.
fieldcatalog-col_pos = 0.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
* fieldcatalog-do_sum = 'X'.
* fieldcatalog-no_zero = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'EBELP'.
fieldcatalog-seltext_m = 'PO Item'.
fieldcatalog-col_pos = 1.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'STATU'.
fieldcatalog-seltext_m = 'Status'.
fieldcatalog-col_pos = 2.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'AEDAT'.
fieldcatalog-seltext_m = 'Item change date'.
fieldcatalog-col_pos = 3.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'Material Number'.
fieldcatalog-col_pos = 4.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MENGE'.
fieldcatalog-seltext_m = 'PO quantity'.
fieldcatalog-col_pos = 5.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MEINS'.
fieldcatalog-seltext_m = 'Order Unit'.
fieldcatalog-col_pos = 6.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'NETPR'.
fieldcatalog-seltext_m = 'Net Price'.
fieldcatalog-col_pos = 7.
fieldcatalog-outputlen = 15.
fieldcatalog-datatype = 'CURR'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PEINH'.
fieldcatalog-seltext_m = 'Price Unit'.
fieldcatalog-col_pos = 8.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
endform. " BUILD_FIELDCATALOG
*& Form BUILD_LAYOUT
* Build layout for ALV grid report
form build_layout.
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-totals_text = 'Totals'(201).
* Set layout field for row attributes(i.e. color)
gd_layout-info_fieldname = 'LINE_COLOR'.
* gd_layout-totals_only = 'X'.
* gd_layout-f2code = 'DISP'. "Sets fcode for when double
* "click(press f2)
* gd_layout-zebra = 'X'.
* gd_layout-group_change_edit = 'X'.
* gd_layout-header_text = 'helllllo'.
endform. " BUILD_LAYOUT
*& Form DISPLAY_ALV_REPORT
* Display report using ALV grid
form display_alv_report.
gd_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = gd_repid
* i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM
* i_callback_user_command = 'USER_COMMAND'
* i_grid_title = outtext
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
* it_special_groups = gd_tabgroup
* IT_EVENTS = GT_XEVENTS
i_save = 'X'
* is_variant = z_template
tables
t_outtab = it_ekko
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.
endform. " DISPLAY_ALV_REPORT
*& Form DATA_RETRIEVAL
* Retrieve data form EKPO table and populate itab it_ekko
form data_retrieval.
data: ld_color(1) type c.
select ebeln ebelp statu aedat matnr menge meins netpr peinh
up to 10 rows
from ekpo
into table it_ekko.
*Populate field with color attributes
loop at it_ekko into wa_ekko.
* Populate color variable with colour properties
* Char 1 = C (This is a color property)
* Char 2 = 3 (Color codes: 1 - 7)
* Char 3 = Intensified on/off ( 1 or 0 )
* Char 4 = Inverse display on/off ( 1 or 0 )
* i.e. wa_ekko-line_color = 'C410'
ld_color = ld_color + 1.
* Only 7 colours so need to reset color value
if ld_color = 8.
ld_color = 1.
endif.
concatenate 'C' ld_color '10' into wa_ekko-line_color.
* wa_ekko-line_color = 'C410'.
modify it_ekko from wa_ekko.
endloop.
endform. " DATA_RETRIEVAL -
Change color in ALV top of page
Hi all,
Can anyone tell me how (if it is possible) to change color in ALV top-of-page?
Thank you in advance,
HagitHi,
It is not possible to change the color in ALV top of page.
Thanks,
Sriram Ponna. -
Want robust solution for alternating row color, resetting every group
I would like a solution for displaying an alternating row color for my detail rows that resets every group, so that row 1 is always gray.
Our Crystal designer provided this code to me:
@rowcnt formula, suppressed, placed in Detail row:
Shared numbervar rowcnt;
rowcnt := rowcnt + 1;
@resetrowcnt, suppressed, placed in Group row:
Shared numbervar rowcnt;
rowcnt := 0;
Formatting formula, placed in Color in Detail > Section Expert:
Shared numbervar rowcnt;
if Remainder(rowcnt, 2) <> 0 then
color(241,241,241)
else
crWhite
This was working fine for me.
However, it is suddenly not working in one of my reports.
The report does happen to have two groups (rowcount.png).
When the report is run, all rows are colored (rowcount02.png).
This report was previously working fine! I'm not sure what changed.
In any case... surely there must be standard code to do this very standard formatting.
I would be very grateful if someone could post some robust code to accomplish the following:
REPORT DATA IN DETAIL ROW, ALTERNATE ROW BANDING:
- Data in Detail row displays alternating row colors
- Odd rows are always shaded, even rows not
- Banding resets every group / does not continue pattern from previous group
REPORT DATA IN GROUP ROW, ALTERNATE ROW BANDING:
Some of our reports place row data in a group row (just the way it happened).
If you could also modify your code in this case.
Thank you!Hi Abhilash/Sastry, since I'm going to switch to Sastry's formulas, could you please confirm correctness of the following. I can't actually run this report, I can only provide it to our London office, bit of a lag for testing.
@resetrowcnt:
Whileprintingrecords;
Numbervar cnt:=0;
@rowcnt:
Whileprintingrecords;
if {HedgeDetails.StrategyID} <> previous({HedgeDetails.StrategyID}) and
{HedgeDetails.DealID} <> previous({HedgeDetails.DealID}) then
Numbervar cnt:=cnt+1;
Details section (Suppress):
not(OnFirstRecord) and
{HedgeDetails.StrategyID}=previous({HedgeDetails.StrategyID}) and
{HedgeDetails.DealID}=previous({HedgeDetails.DealID})
Please note: Suppress checkbox is selected AND the above formula is entered.
Details section (Color):
Whileprintingrecords;
Numbervar cnt;
if cnt mod 2 <> 0 Then color(241,241,241) else crwhite -
Report Template - Standard, Alternating Row Colors
I'm using APEX 4.1.0 and theme 22 on Oracle 10g.
I have some tabular forms in my application. For 2 of those, row deletions are allowed and I have the usual select box column to manage the row deletions. Also my users like the "Standard, Alternating Row Colors" report template and would like to see the alternating row colors whenever possible. Unfortunately I get the "Error on page." browser error in IE when I check a row selector box using this template. When I use a different report template I don't get this error.
The tabular form functions correctly so this error is harmless, but I would like to know what it is for. I'm sure my users would rather not see that error.
By the way, in Firefox the firebug error count increases and I get the following error in the console:
TypeError: can't convert undefined to object
[Break On This Error]
...ovedColor)}gLastRowMoved=b}function html_RowUp(e,d){var c=$x_UpTill(e,"TR");ie_R...
apex_4_1.min.js (line 18)Because all of the whitespace has been helpfully removed :) it's hard to see which expression is undefined and why.
Any ideas?Hi Jackie,
There must be some issues the apex_4_1.min.js file, try to reload it. In apex.oracle.com the tabular form with "Standard, Alternating Row Colors" just works fine.
Regards,
Natarajan -
Change JTable's row color on row selection
Hello!
Everywhere I've looked they're only explaining how to draw rows in different colors WHEN THE TABLE IS BEING CREATED, via prepareRenderer.
But that is not what I am looking for. What I want is to actually change the row's color after the table has been drawn/rendered/whatsoever. For instance, when the user clicks on that row. The default behaviour is for the row to become blueish, but, when the user selects another row, the first selected row turns back to white. I would like to prevent that from happening. I want the row to become FIRE RED when the user clicks on it, and I want the row to remain like that for good, even when the user selects a different row. Do I make any sense here? :-)
Thank you for your time and future suggestions.Everywhere I've lookedApparently you didn't look in the Swing forum, because thats where Swing related questions should be posted.
but how do I assign a cell renderer to an entire row/table ?The easiest way is to use the prepareRenderer(...) method you have already found. My "TablePrepareRenderer" class (which you can find by searching the Swing forum) shows you how to do this.
You will note that the color of the row is determined by data in the table. So all you need to do is add another column in the TableModel that contains the information you need to determine the row color. That column can be removed from view in the table by removing the TableColumn from the TableColumnModel. -
Alternating row color for CF report Builder?
I have a user who wants one of her reports to display
alternating row colors for better read clarity. The reports are
rather lengthy and the rows tend to blend in with eachother.Thanks Epulfy. I am going to give this a try later today.
Much appreciated
EDIT:: This does work. however I'm not sure how to set a
rectangle to the background of the report so it's behind my
details. I draw the rectangle and it just hides whatever I want to
display. When I look at the report it does alternate with rows, but
I can only see details from the rows that it does not alternate on.
Any clue how to set it to the background?
Maybe you are looking for
-
Adding a bookmark link to an image
I have a project in IBA that is made of images llike a coffee table book. All the text is embedded in the artwork as the image covers the entire page. I need to have hyperlinks ( that I have created which sit over the image on certain pages) to link
-
Intelligent barcode font not working in Data Merge?
Intelligent barcode font not working in Data Merge? When using Data Merge I only get a pink box where the code is supposed to go. If I cut and paste the same info into the spot the bar works fine. Anybody ever have this problem?
-
Blurring the entire screen in a WinForms application
Hello, I am trying to come up with a way to blur the entire screen (all forms visible) on a WinForms program. I am using C# in VS2005. I have tried the code from this link: .net - C# dialog form with blur background - Stack Overflow ...and it works q
-
When I open my Final Cut Pro, it comes up as a black screen. If I click around up top - the desktop opens. But as soon as I attempt to do anything in FCP the screen goes black once again - Can anyone help me?
-
Hi, in the new version it's not possible to split events and give the event instantly a new name. you have to go back to "all events" and then find the new events. When you have a lots of events you gets crazy by looking for it. I know that in the "p