Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

color in alv

Former Member
0 Kudos

hi to all,

i have intensified color on/off and some other options in ALV grid report...

so how can i define char....

and tell me somemore details working with colors in ALV.

loop at it_vbak into wa_vbak.

*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_vbak-line_color = 'C410'

ld_color = ld_color + 1.

  • Only 7 colours so need to reset color value

if ld_color = 6.

ld_color = 1.

endif.

concatenate 'C' ld_color '10' into wa_vbak-line_color.

  • wa_ekko-line_color = 'C410'.

modify it_vbak from wa_vbak.

RAJU.

1 ACCEPTED SOLUTION
8 REPLIES 8

Former Member
0 Kudos

Former Member
0 Kudos

Hi,

Plz refer these threads too

1.

2.

Also see

<b>http://www.sapgenie.com/abap/controls/alvgrid.htm</b>

http://www.henrikfrank.dk/abapexamples/ABAP%20objects%20and%20controls/alvgrid_control.htm

http://help.sap.com/saphelp_erp2004/helpdata/en/7f/e477e2fba211d2b48f006094192fe3/content.htm

Check this link to get code for different colors http://www.sapdesignguild.org/resources/ma_guidelines/VisualDesignRules/colors.html

Try this out the same thing will work for Reuse also.

Hope this helps.

Former Member
0 Kudos

Hi,

example on ALV with line color

http://www.geocities.com/mpioud/Z_ALV_LINE_COLOR.html

example on ALV with cell color

http://www.geocities.com/mpioud/Z_ALV_CELL_COLOR.html

regards,

venu.

Former Member
0 Kudos

Sample code again


report XXX.
*****************************************************************
* 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 = 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.

* 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'.
[code]* Color line move 'C410' to wa_mara-color_line.

elseif wa_mara-counter = '0004'

and p_cell = 'X'.

<b>* Color cell</b>

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.

*****************************************************************

<b>* 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 </b>****************************************************************

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.

[/code]

Hope u have got the solution, if u have then kindly close the thread by rewarding else get back to us with queries.

Former Member
0 Kudos

Hi,

Did you try using the option EMPHASIZE in the field catalog (LVC_T_FCAT)?.

Please reward points if this explanation useful.

Regards,

Siva

Former Member
0 Kudos

hai,

see basically there are three types you can assiagn colors

1 for the entire row.

2 for the entire column

3 for the indivial cell

1. for the indivial coulmn

you have to set the field 'EMMPHASIZE' in lvc_S_layo

with following values.

*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_vbak-line_color = 'C410'

2. for indivial row coloring.

you have to decalre a field <rowcolor> in the internal table conating output values.

and you need to set the field 'INFO_FNAME' in the lcv_s_layo to <ROWCOLOR> according to my example.

example code is

data: begin of itab occurs 0.

include structure vbak.

rowcolor(4) type c,

end of itab.

next loop through the internal table

and for the ROWCOLOR field put the folowing values

*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_vbak-line_color = 'C410'

3. for coloring the indivial cells

data: begin of itab occurs 0.

include structure vbak.

data: rowcolor(4) type c.

data: ct type lvc_t_scol.

data: end of itab.

and set the field 'ctab_fname' to 'CT' according to my example i LCV_s+layo.

and again loop through the internal table

here CT is an internal table.

put the columns and the what color according to your requirement and append it, appemding should be done for each row.

for more on THIrd point. Pls come back

Former Member
0 Kudos

Hi,

Some more info on working with colors in alv:

http://www.sapfans.com/forums/viewtopic.php?t=52107

Use field emphasize of field catalog structure.

emphasize (highlight columns in color)

value set: SPACE, 'X' or 'Cxyz' (x:'1'-'9'; y,z: '0'=off '1'=on)

'X' = column is colored with the default column highlight color.

'Cxyz' = column is colored with a coded color:

C: Color (coding must begin with C)

x: color number

y: bold

z: inverse

Regards,

Anjali