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: 

ALV GRID

Former Member
0 Kudos

Hi,

I am using ALV GRID layout for the report.

I would like to change color of two columns.

How this can be done.

Thanks,

Pratibha

1 ACCEPTED SOLUTION

former_member188685
Active Contributor
0 Kudos

Hi,

You need to use fieldcatalog-emphasize = 'C600'. "red

for the two columns.

x_fieldcat-fieldname = 'VBELN'.

..

x_fieldcat-emphasize = 'C600'.

append it_fieldcat.

clear x_fieldcat.

x_fieldcat-fieldname = 'POSNR'.

..

x_fieldcat-emphasize = 'C600'.

append it_fieldcat.

or else you want to show them as key fields

then you can use fieldcat-key = 'X'.

regards

vijay

8 REPLIES 8

Former Member
0 Kudos

in fieldcatalog

for those 2 fields(columns)

it_fieldcat-fieldname = 'FLD1'.

it_fieldcat-emphasize = 'Cxyz'.

where

C is constant

x - color code

y - intensify

z - inverse

jayanthi_jayaraman
Active Contributor
0 Kudos

Former Member
0 Kudos

hi

HERE IS A SAMPLE PROGRAM TO ADD COLOR TO THE COLUMN

REPORT ZALVCOLOR.

TYPE-POOLS: SLIS.

INCLUDE <ICON>.

*- Fieldcatalog

DATA: IT_FIELDCAT TYPE LVC_T_FCAT,

IT_FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV..

*- For Events

DATA:IT_EVENTS TYPE SLIS_T_EVENT.

DATA: X_FIELDCAT TYPE LVC_S_FCAT,

X_FIELDCAT1 TYPE SLIS_FIELDCAT_ALV.

DATA:X_LAYOUT TYPE LVC_S_LAYO.

TABLES: LIPS.

DATA: BEGIN OF IT_VBAP OCCURS 0,

VBELN LIKE VBAP-VBELN,

POSNR LIKE VBAP-POSNR,

<b> CELLCOLOR TYPE LVC_T_SCOL,</b>

END OF IT_VBAP.

SELECT VBELN

POSNR

UP TO 10 ROWS

INTO CORRESPONDING FIELDS OF TABLE IT_VBAP

FROM VBAP.

DATA:L_POS TYPE I VALUE 1.

CLEAR: L_POS.

L_POS = L_POS + 1.

X_FIELDCAT-SELTEXT = 'VBELN'.

X_FIELDCAT-FIELDNAME = 'VBELN'.

X_FIELDCAT-TABNAME = 'ITAB'.

X_FIELDCAT-COL_POS = L_POS.

X_FIELDCAT-OUTPUTLEN = '10'.

APPEND X_FIELDCAT TO IT_FIELDCAT.

CLEAR X_FIELDCAT.

L_POS = L_POS + 1.

X_FIELDCAT-SELTEXT = 'POSNR'.

X_FIELDCAT-FIELDNAME = 'POSNR'.

X_FIELDCAT-TABNAME = 'ITAB'.

X_FIELDCAT-COL_POS = L_POS.

X_FIELDCAT-OUTPUTLEN = '5'.

APPEND X_FIELDCAT TO IT_FIELDCAT.

CLEAR X_FIELDCAT.

L_POS = L_POS + 1.

<b>X_LAYOUT-CTAB_FNAME = 'CELLCOLOR'.

DATA: LS_CELLCOLOR TYPE LVC_S_SCOL.</b>

DATA: L_INDEX TYPE SY-TABIX.

<b>LOOP AT IT_VBAP.

L_INDEX = SY-TABIX.

LS_CELLCOLOR-FNAME = 'VBELN'.

LS_CELLCOLOR-COLOR-COL = '6'.

LS_CELLCOLOR-COLOR-INT = '1'.

APPEND LS_CELLCOLOR TO IT_VBAP-CELLCOLOR.

MODIFY IT_VBAP INDEX L_INDEX TRANSPORTING CELLCOLOR.

ENDLOOP.</b>

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'

EXPORTING

I_CALLBACK_PROGRAM = SY-REPID

IS_LAYOUT_LVC = X_LAYOUT

IT_FIELDCAT_LVC = IT_FIELDCAT

TABLES

T_OUTTAB = IT_VBAP[]

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.

REGARDS

KISHORE

Message was edited by: Harikishore Sreenivasulu

Former Member
0 Kudos

You can color using this:

BEGIN OF OUTTAB OCCURS 0.

INCLUDE STRUCTURE <your structure>.

DATA: LINECOLOR(4) TYPE C,

END OF OUTTAB.

Assign a 4 digit color code to this field to change the color of each line. Furthermore you should set the name of this field in the layout:

ZZLAYOUT-INFO_FNAME = 'LINECOLOR'.

Set the field EMPHASIZE of the layout structure for the column

Again add a field (in this case a table) to the structure of your table:

BEGIN OF OUTTAB OCCURS 0.

INCLUDE STRUCTURE <your structure>.

DATA: COLORTAB TYPE LVC_T_COL,

END OF OUTTAB.

For each column you want to color add a line to table COLORTAB (for each line of your ALV). Furthermore you should set the name of this table in the layout:

ZZLAYOUT-CTAB_FNAME = 'COLORTAB'.

See http://help.sap.com/saphelp_bw33/helpdata/en/7f/e477e2fba211d2b48f006094192fe3/frameset.htm for more help.

Former Member
0 Kudos

with connection to my previous post

C = Constant

x = varies from 1 to 8.

y = 0 or 1

z = 0 or 1

check out more info on SHOWCOLO program

Former Member
0 Kudos

hi,

check this ample code for coloring the columns

  • 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

satesh

former_member188685
Active Contributor
0 Kudos

Hi,

You need to use fieldcatalog-emphasize = 'C600'. "red

for the two columns.

x_fieldcat-fieldname = 'VBELN'.

..

x_fieldcat-emphasize = 'C600'.

append it_fieldcat.

clear x_fieldcat.

x_fieldcat-fieldname = 'POSNR'.

..

x_fieldcat-emphasize = 'C600'.

append it_fieldcat.

or else you want to show them as key fields

then you can use fieldcat-key = 'X'.

regards

vijay

Former Member
0 Kudos

Hi,

Chk this sample prog:

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

and these links for more ference:

http://www.sap-img.com/abap/line-color-in-alv-example.htm

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

1.

2.

Also see

http://www.sapgenie.com/abap/controls/alvgrid.htm

Best Regards,

Anjali