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: 

change the color of a row in ALV grid, using OOPS, SET_TABLE_FOR_FIRST_DISP

Former Member
0 Kudos

Please help!!!

Thanks in advance...

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Basant ,

You have to set the EMPHASIZE option in the field catalog and while creating the layout mention gd_layout-info_fieldname = 'LINE_COLOR'.

line_color is used to store row color attributes.

Pls refer to the code below

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

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.

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

Hope this helps.

Regards,

Chitra

13 REPLIES 13

Former Member
0 Kudos

hai what is the question and what u want

be specific

reagrds

afzal

0 Kudos

Hi Afzal.

I Have an indicator in my internal table, i want the color of the row should be changed when the value of the indicator is 'X'.

Former Member
0 Kudos

use EMPHASIZE option in your fieldcatlog for colour of individual line

0 Kudos

Can you please explain me... I think that will be static....

0 Kudos

you cannot dynamicaly assign colour line to alv

it must be predefine in fieldcatalog

0 Kudos

Hi,

set the color of a complete column by calling the method set_color of cl_salv_column of the column

for more details see the report SALV_DEMO_TABLE_COLUMNS.

Regards,

Jayaram

Former Member
0 Kudos

Hi,

In general for colour for a particular column that i possible empasize

option in fieldcatalog.

By using ooops if u want colour at a row leval.layout option should be checked.

U see the below code.

*at layout section******

wa_layout-info_fieldname = 'COLOR'.

loop at i_vbap into wa_vbap where checkbox = 'X'.

  • IF wa_vbap-checkbox = 'X'.

l_vbeln = wa_vbap-vbeln.

wa_vbap-checkbox = 'X'.

wa_vbap-color = 'C610'. ""gives u colou'

modify i_vbap from wa_vbap transporting checkbox color.

  • fs_spfli = t_vbap.

  • APPEND fs_spfli TO t_sspfli.

  • ENDIF.

endloop.

U check some examples for standard alv bcalv*

Regards,

Naveen M.

Former Member
0 Kudos

Hi ,

You need to pass field catalog emphasize field value as 4 digit color code to

get the color.

Check the bellow code -

DATA : w_cont TYPE REF TO cl_gui_custom_container,
       w_grid TYPE REF TO cl_gui_alv_grid.

DATA : fs_fcat TYPE lvc_s_fcat,
       fs_layo TYPE lvc_s_layo,
       t_fcat TYPE lvc_t_fcat.

 .
 .
data : t_sbook like table of sbook.
select * from sbook into table t_sbook.

START-OF-SELECTION.
  SELECT carrid connid fldate price FROM sflight
  INTO TABLE t_sflight .
  CALL SCREEN 100.
    .
    .
    .

  fs_fcat-fieldname = 'W_CHECK'.
  fs_fcat-coltext = 'Select'.
  fs_fcat-checkbox = 'X'.
  fs_fcat-edit = 'X'.
  APPEND fs_fcat TO t_fcat.
  CLEAR fs_fcat.

  fs_fcat-edit = 'X'.
  fs_fcat-REF_TABLE = 'SFLIGHT'.
  fs_fcat-coltext = 'ID'.
  APPEND  fs_fcat TO t_fcat.
  CLEAR fs_fcat.

  fs_fcat-fieldname = 'FLDATE'.
  fs_fcat-EMPHASIZE = 'C310'.  " For color here yellow
    fs_fcat-coltext =  'Flight Date'.
  APPEND  fs_fcat TO t_fcat.
  clear fs_fcat.
  fs_fcat-fieldname = 'PRICE'.
  fs_fcat-coltext =  'PRICE'.
  APPEND  fs_fcat TO t_fcat.
  CLEAR fs_fcat.
 
  CALL METHOD w_grid->set_table_for_first_display
    EXPORTING
      i_structure_name              = 'FS_SFLIGHT'
    is_layout                     = fs_layo
    CHANGING
      it_outtab                     = t_sflight
    it_fieldcatalog               = t_fcat " Passing field catalog
    EXCEPTIONS
      invalid_parameter_combination = 1
      program_error                 = 2
      too_many_lines                = 3
      OTHERS                        = 4
          .

Regards

Pinaki

0 Kudos

Hi

Went through you coding.It worked for me fine can you please tell me why do you use lvc_t_fcat

and also why do you append APPEND fs_fcat TO t_fcat.Is there any reason for this..It dint work when i simply used

APPEND fs_fcat.

DATA : w_cont TYPE REF TO cl_gui_custom_container,

w_grid TYPE REF TO cl_gui_alv_grid.

DATA : fs_fcat TYPE lvc_s_fcat,

fs_layo TYPE lvc_s_layo,

t_fcat TYPE lvc_t_fcat.

.

.

data : t_sbook like table of sbook.

select * from sbook into table t_sbook.

START-OF-SELECTION.

SELECT carrid connid fldate price FROM sflight

INTO TABLE t_sflight .

CALL SCREEN 100.

.

.

.

fs_fcat-fieldname = 'W_CHECK'.

fs_fcat-coltext = 'Select'.

fs_fcat-checkbox = 'X'.

fs_fcat-edit = 'X'.

APPEND fs_fcat TO t_fcat.

CLEAR fs_fcat.

fs_fcat-edit = 'X'.

fs_fcat-REF_TABLE = 'SFLIGHT'.

fs_fcat-coltext = 'ID'.

APPEND fs_fcat TO t_fcat.

CLEAR fs_fcat.

fs_fcat-fieldname = 'FLDATE'.

fs_fcat-EMPHASIZE = 'C310'. " For color here yellow

fs_fcat-coltext = 'Flight Date'.

APPEND fs_fcat TO t_fcat.

clear fs_fcat.

fs_fcat-fieldname = 'PRICE'.

fs_fcat-coltext = 'PRICE'.

APPEND fs_fcat TO t_fcat.

CLEAR fs_fcat.

CALL METHOD w_grid->set_table_for_first_display

EXPORTING

i_structure_name = 'FS_SFLIGHT'

is_layout = fs_layo

CHANGING

it_outtab = t_sflight

it_fieldcatalog = t_fcat " Passing field catalog

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4

Regards

Harish

Former Member
0 Kudos

Hi Basant ,

You have to set the EMPHASIZE option in the field catalog and while creating the layout mention gd_layout-info_fieldname = 'LINE_COLOR'.

line_color is used to store row color attributes.

Pls refer to the code below

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

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.

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

Hope this helps.

Regards,

Chitra

Former Member
0 Kudos

Hi

It's like for the function for ALV (list or GRID), u need to define field for color attribute in the output table and set it in the layout structure;

check this sample:

-> Output table

DATA: BEGIN OF T_OUTTAB OCCURS 0,
       BUKRS LIKE BKPF-BUKRS,
       BELNR LIKE BKPF-BELNR,
       BUDAT LIKE BKPF-BUDAT,
       COLOR(3) TYPE C,                      "<----Color field
      END   OF T_OUTTAB.

-> Alv data

DATA: LVC_S_LAYO  TYPE LVC_S_LAYO.
DATA: GT_FIELDCAT TYPE LVC_T_FCAT.
DATA: GS_FIELDCAT TYPE LVC_S_FCAT.
DATA: GRID1              TYPE REF TO CL_GUI_ALV_GRID,
      G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.

DATA: FL_CHG_COLOR.
DATA: OK_CODE TYPE SY-UCOMM.

-> Start-of-selection

START-OF-SELECTION.

  SELECT BUKRS BELNR BUDAT UP TO 100 ROWS
     FROM BKPF INTO TABLE T_OUTTAB
       WHERE BUKRS = 'MAAB'.

  PERFORM SET_COLOR.

  CALL SCREEN 100.

--> Form

FORM SET_COLOR .
  LOOP AT T_OUTTAB.
    IF SY-TABIX = 3 OR SY-TABIX = 6 OR SY-TABIX = 9.
      IF FL_CHG_COLOR IS INITIAL.
        T_OUTTAB-COLOR = 'C30'.
      ELSE.
        T_OUTTAB-COLOR = 'C40'.
      ENDIF.
      MODIFY T_OUTTAB.
    ENDIF.
  ENDLOOP.
  IF FL_CHG_COLOR IS INITIAL.
    FL_CHG_COLOR   = 'X'.
  ELSE.
    FL_CHG_COLOR   = SPACE.
  ENDIF.
ENDFORM.                    " SET_COLOR

-Flow of dynpro

PROCESS BEFORE OUTPUT.
  MODULE PBO_0100.
*
PROCESS AFTER INPUT.
 MODULE USER_COMMAND_0100.

MODULE USER_COMMAND_0100 INPUT.
  CASE OK_CODE.
    WHEN 'BACK'. LEAVE TO SCREEN 0.
    WHEN 'COLOR'. PERFORM SET_COLOR.
  ENDCASE.
ENDMODULE.

I don't know why, but I can't post the code of module PBO_0100, anyway here it create the objects for the grid and the container and call the method to display and refresh the grid.

Max

Edited by: max bianchi on May 11, 2009 12:08 PM

former_member183990
Active Contributor
0 Kudos

hi use this

go to wiki->search for coloring ALV it gives lot many some of which is given below

https://wiki.sdn.sap.com/wiki/display/Snippets/AddColorsinALVRows

https://wiki.sdn.sap.com/wiki/display/Snippets/ColoringacellinanALVconditionally

https://wiki.sdn.sap.com/wiki/display/Snippets/ColoringaRowinanALVconditionally

https://wiki.sdn.sap.com/wiki/display/Snippets/ChangecolorofindividualALV+rows

cheers

s.janagar

Former Member
0 Kudos

use this code , it works when MEINS has the KG it changes the color of that row.

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: ld_color(1) type c.

select ebeln ebelp statu aedat matnr menge meins netpr peinh

from ekpo

into table it_ekko.

ld_color = ld_color + 1. "color wht you wnat to fill in a row.

*Populate field with color attributes

loop at it_ekko into wa_ekko.

IF wa_ekko-MEINS = 'KG'.

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

ENDIF.

modify it_ekko from wa_ekko.

endloop.

*and last pass this it_ekko table to

it_outtab = it_ekko in set_table_for_first_display function.

Edited by: Avenai on Jun 30, 2010 10:37 AM