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: 

To change the subtotals row color in ALV(Grid / List ) .

Former Member
0 Kudos

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

2 REPLIES 2

Former Member
0 Kudos

where r u friends.................?

Former Member
0 Kudos

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 :

Hope this helps you in solving your issue.

Please Reward Points if any of the above points are helpful to you.

Regards,

Kalyan Chakravarthy