Application Development and Automation 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: 
Read only

ALV

Former Member
0 Likes
779

Hello,

How to coler a row in alv display.

I am using methods for display.

Hello,

How to coler a row in alv display.

I am using methods for display.

6 REPLIES 6
Read only

Former Member
0 Likes
734

Hi,

if you now the row number then use sy-tabix

if sy-tabix =4.

format color col_key intensified on.

else.

format color col_key intensified off.

endif.

OFF

or COL_BACKGROUND

Background (GUI-specific)

1

or COL_HEADING

Headers (grayish blue)

2

or COL_NORMAL

List body (bright gray)

3

or COL_TOTAL

Totals (yellow)

4

or COL_KEY

Key columns (bluish green)

5

or COL_POSITIVE

Positive threshold value (green)

6

or COL_NEGATIVE

Negative threshold value (red)

7

or COL_GROUP

Control levels (violet)

Thanks

Venki

Read only

andreas_mann3
Active Contributor
Read only

Former Member
0 Likes
734

1)add a field to your output table

line_color(4) type c,

2) Do programmatically what you need to do and specify the colour you want for each row.

e.g

if <condition>.

itab-line_colour = 'C210'

endif.

how you get this is

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 )

3 Define the layout with

ws_layout-info_fieldname = 'LINE_COLOR'.

Please check this link it is very userful

http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_color.htm

Read only

0 Likes
734

hai,

I am trying to display the 12th row for a color.

But almost i am getting color from line 2 to line 13.

READ TABLE GT_BPSTAB ASSIGNING <GT_BPSTAB> INDEX LV_COUNTER.

IF LV_COUNTER = 12.

*FORMAT COLOR COL_KEY INTENSIFIED ON.

WA_BPSTAB-COLOR_LINE = 'C610'.

APPEND WA_BPSTAB TO GT_BPSTAB.

ENDIF.

LS_LAYOUT-INFO_FNAME = 'COLOR_LINE'.

  • append GT_FIELDCATALOG to LT_FIELDCATALOG.

CALL METHOD GRID->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

I_STRUCTURE_NAME = 'gt_STRUCT'

I_SAVE = X_SAVE

I_DEFAULT = LV_DEF

IS_LAYOUT = LS_LAYOUT

CHANGING

IT_OUTTAB = GT_BPSTAB[]

IT_FIELDCATALOG = GT_FIELDCATALOG[]

EXCEPTIONS

INVALID_PARAMETER_COMBINATION = 1

PROGRAM_ERROR = 2

TOO_MANY_LINES = 3

OTHERS = 4

.

Read only

Former Member
0 Likes
734

Method: 1

Assign a variable celltab TYPE lvc_t_styl, in the internal table which u dispaly the data.

In the layout give, wa_layout-stylefname = 'CELLTAB'.

In the final table before showing the data do like the below code.

DATA : lt_celltab TYPE lvc_t_styl,

ls_celltab TYPE lvc_s_styl.

READ TABLE i_final_data INTO wa_final_data INDEX 1.

ls_celltab-fieldname = 'LNG_TYPES'.

ls_celltab-style = '00000060'.

INSERT ls_celltab INTO TABLE lt_celltab.

CLEAR ls_celltab.

ls_celltab-fieldname = 'LNG_QUANTITY'.

ls_celltab-style = '00003060'.

INSERT ls_celltab INTO TABLE lt_celltab.

CLEAR ls_celltab.

ls_celltab-fieldname = 'NG_TYPES'.

ls_celltab-style = '00000666'.

INSERT ls_celltab INTO TABLE lt_celltab.

CLEAR ls_celltab.

ls_celltab-fieldname = 'NG_QUANTITY'.

ls_celltab-style = '00000066'.

INSERT ls_celltab INTO TABLE lt_celltab.

CLEAR ls_celltab.

wa_final_data-celltab[] = lt_celltab[].

MODIFY i_final_data FROM wa_final_data INDEX 1.

CLEAR: ls_celltab, lt_celltab, wa_final_data.

Here ls_celltab-style = '00000066' or '00000060' gives the color for a particular cell.

Read the row which u want to make cell colored. For that row, append the field name and style into ls_celltab.

ls_celltab-fieldname = 'LNG_TYPES'.

ls_celltab-style = '00003040'.

INSERT ls_celltab INTO TABLE lt_celltab.

wa_final_data-celltab[] = lt_celltab[].

So that the particular cell will become colored.

Method 2:

Do as follows

1. declare one field say color in the output table of type SLIS_T_SPECIALCOL_ALV.

2. Also declare a table color like

DATA COLOR TYPE SLIS_T_SPECIALCOL_ALV WITH HEADER LINE.

3. After you have filled the field catalog do like this,

LOOP AT IT_ALV_DATA.

IF SY-TABIX = 2.

COLOR-FIELDNAME = 'POSNR'.

COLOR-COLOR-COL = 6.

COLOR-COLOR-INT = 0.

APPEND COLOR.

IT_ALV_DATA-COLOR = COLOR[].

MODIFY IT_ALV_DATA.

ENDIF.

ENDLOOP.

Regards,

Prakash.

Read only

Former Member
0 Likes
734

Have a look at BCALV_TREE_ITEMLAYOUT. It is present in 4.7 I think.

Also have a look at below code:

report zrich_0002 .

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

  • 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'.

  • 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.

I hope it helps.

Best Regards,

Vibha

*Please mark all the helpful answers