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: 
SAP Community Downtime Scheduled for This Weekend

ALV row color

Former Member
0 Kudos
2,549

Dear All,

I have a requirement to color selected rows in ALV based on the condition, I did managed to get the color code in the final internal table and when I am passing the table to the 'fieldcat' I am getting only one color.

Can any one tell me what's the problem with row color.

Thanks,

Fed

1 ACCEPTED SOLUTION

former_member1245113
Active Contributor
0 Kudos
223

This message was moderated.

12 REPLIES 12

former_member1245113
Active Contributor
0 Kudos
224

This message was moderated.

0 Kudos
223

Dear Ram,

I tried seeing some blogs in SDN before posting about this and unable to figure out what is the problem including your answer also before posting.

Can any one tell me what is the issue>

Thanks,

Fed

0 Kudos
223

While populating the final internal table, are you updating the different line color codes in "color_code" field based on conditions ?

like

if <final_internal_table>-column = 'X'.
  <final_internal_tabl>-line_color = 'C240'.
else.
  <final_internal_tabl>-line_color = 'C250'.
endif.

Regards

Vinod

Edited by: Vinod Kumar on Apr 5, 2010 10:24 AM

0 Kudos
223

Hi,

Color code should be of characters 4.

  • Populate color variable with colour properties

  • Char 1 = C (This is a color property)

  • Char 2 = Color codes: 1 - 7

  • Char 3 = Intensified on/off ( 1 or 0 )

  • Char 4 = Inverse display on/off ( 1 or 0 )

For eg:

types: begin of ty_output,

bill_hdr type vbrk,

color type char4,

end of ty_output.

data: itab type standard table of ty_output,

s_tab type ty_output.

s_tab-belnr = '1341413'.

s_tab-budat = sy-datum.

s_tab-color = 'C500'.

append s_tab to itab.

~~~~~~~~~~~~~~~~~

Hope this info helps.

Regards,

Subramanian

0 Kudos
223

Hi Vinod,

I have absolutely no problem in the final internal table, here is the coding

IF LW_TRANS-COLOR = 'X'.

LW_UPDATE-LINE_COLOR = 'C610'.

ELSE.

LW_UPDATE-LINE_COLOR = 'C410'.

ENDIF.

but I feel may be I need to assign this field to the fieldcat or ?

Thanks,

Fed

0 Kudos
223

REPORT  Z_ALV_CELL_COLOR.
DEFINE m_fieldcat.
  add 1 to ls_fieldcat-col_pos.
  ls_fieldcat-fieldname   = &1.
  ls_fieldcat-ref_tabname = &2.
  append ls_fieldcat to lt_fieldcat.
END-OF-DEFINITION.

TYPE-POOLS: slis.                      " ALV Global types

SELECTION-SCREEN :
  SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max.    "#EC NEEDED
PARAMETERS p_max(2) TYPE n DEFAULT '30' OBLIGATORY.         "#EC *
SELECTION-SCREEN END OF LINE.

TYPES :
  BEGIN OF ty_data,
    vkorg TYPE vbak-vkorg,             " Sales organization
    kunnr TYPE vbak-kunnr,             " Sold-to party
    vbeln TYPE vbak-vbeln,             " Sales document
    netwr TYPE vbak-netwr,             " Net Value of the Sales Order
  END OF ty_data,

* Data displayed
  BEGIN OF ty_vbak,
    vkorg TYPE vbak-vkorg,             " Sales organization
    kunnr TYPE vbak-kunnr,             " Sold-to party
    vbeln TYPE vbak-vbeln,             " Sales document
    netwr TYPE vbak-netwr,             " Net Value of the Sales Order
    tabcolor TYPE lvc_t_scol,          " Cell Color
  END OF ty_vbak.

DATA:
  gt_data TYPE TABLE OF ty_data,
* Data displayed
  gt_vbak TYPE TABLE OF ty_vbak.

START-OF-SELECTION.

  PERFORM f_read_data.
  PERFORM f_fill_color.
  PERFORM f_display_data.

*---------------------------------------------------------------------*
*      Form  f_read_data_vbak
*---------------------------------------------------------------------*
FORM f_read_data.

  SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_data
           FROM vbak UP TO p_max ROWS.

ENDFORM.                               " F_READ_DATA

0 Kudos
223

Hi,

I think you are missing the layout setting

wa_layout-info_fieldname =      'LINE_COLOR'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
 i_callback_program                = sy-repid
 is_layout                         = wa_layout
 it_fieldcat                       = it_fieldcat
TABLES
  t_outtab                          = it_mara
EXCEPTIONS
 program_error                     = 1
 OTHERS                            = 2.

Regards

Vinod

0 Kudos
223

Dear Vinod,

Thanks for the reply.

I have decleared this ' GD_LAYOUT-INFO_FIELDNAME = 'LINE_COLOR'.'

But no clue what is the problem.

Thanks,

Fed

0 Kudos
223

Hi, I have tested the same with a sample program which gave me desired result with different color for different material groups, Try this.

TYPE-POOLS : slis.
TYPES : BEGIN OF ty_mara ,
         matnr TYPE matnr,
         matkl TYPE matkl,
         line_color(4) TYPE c,
        END OF ty_mara.

DATA : it_mara TYPE STANDARD TABLE OF ty_mara.
FIELD-SYMBOLS :  <wa_mara> TYPE ty_mara.

DATA : it_fieldcat TYPE slis_t_fieldcat_alv,
       wa_fieldcat TYPE slis_fieldcat_alv,
       wa_layout   TYPE slis_layout_alv.

SELECT matnr matkl FROM mara
  INTO TABLE it_mara
  UP TO 10 ROWS.

LOOP AT it_mara ASSIGNING <wa_mara>.
  IF <wa_mara>-matkl EQ '2001'.
    MOVE 'C410' TO <wa_mara>-line_color.
  ELSE.
    MOVE 'C510' TO <wa_mara>-line_color.
  ENDIF.

ENDLOOP.

wa_layout-zebra = 'X'.
wa_layout-colwidth_optimize = 'X'.
wa_layout-info_fieldname =      'LINE_COLOR'.


CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'MATNR'.
wa_fieldcat-seltext_m = 'Material'.
APPEND wa_fieldcat TO it_fieldcat.

CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'MATKL'.
wa_fieldcat-seltext_m = 'group'.
APPEND wa_fieldcat TO it_fieldcat.


CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
 i_callback_program                = sy-repid
 is_layout                         = wa_layout
 it_fieldcat                       = it_fieldcat
TABLES
  t_outtab                          = it_mara
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

Vinod

0 Kudos
223

Thanks Vinod,

I havent assigned here ' is_layout = wa_layout' now got it.

Thanks,

Fed

Former Member
0 Kudos
223

Continue.....


*--------------------------------------------------------------------*
*      Form  f_fill_color
*--------------------------------------------------------------------*
FORM f_fill_color.

  DATA :
    ls_data TYPE ty_data,
    ls_vbak TYPE ty_vbak.

  LOOP AT gt_data INTO ls_data.

    CLEAR ls_vbak.
    MOVE-CORRESPONDING ls_data TO ls_vbak.

    PERFORM f_modify_color USING 'NETWR' CHANGING ls_vbak.
    PERFORM f_modify_color USING 'VBELN' CHANGING ls_vbak.

*   Fill gt_vbak
    APPEND ls_vbak TO gt_vbak.

  ENDLOOP.

ENDFORM.                               " F_FILL_COLOR
*---------------------------------------------------------------------*
*      Form  F_modify_color
*---------------------------------------------------------------------*
FORM f_modify_color USING u_fieldname TYPE lvc_fname
                 CHANGING us_vbak     TYPE ty_vbak.

  DATA :
    l_rnd_value TYPE integer2,
    ls_tabcolor TYPE lvc_s_scol.

* Random value
  CALL FUNCTION 'RANDOM_I2'
       EXPORTING
            rnd_min   = 0
            rnd_max   = 3
       IMPORTING
            rnd_value = l_rnd_value.

  CLEAR ls_tabcolor.
  ls_tabcolor-fname = u_fieldname.

Former Member
0 Kudos
223

Continue......


CASE l_rnd_value.
    WHEN 0.
      ls_tabcolor-color-col = 1.       " Blue.
      ls_tabcolor-color-int = 0.
      ls_tabcolor-color-inv = 0.
    WHEN 1.
      ls_tabcolor-color-col = 3.       " Yellow.
      ls_tabcolor-color-int = 0.
      ls_tabcolor-color-inv = 0.
    WHEN 2.
      ls_tabcolor-color-col = 5.       " Green.
      ls_tabcolor-color-int = 0.
      ls_tabcolor-color-inv = 0.
    WHEN 3.
      ls_tabcolor-color-col = 6.       " Red.
      ls_tabcolor-color-int = 0.
      ls_tabcolor-color-inv = 0.
  ENDCASE.

  INSERT ls_tabcolor INTO TABLE us_vbak-tabcolor.

ENDFORM.                               " F_MODIFY_COLOR
*---------------------------------------------------------------------*
*      Form  f_display_data
*---------------------------------------------------------------------*
FORM f_display_data.

  DATA:
    ls_layout   TYPE slis_layout_alv,
    ls_fieldcat TYPE slis_fieldcat_alv,
    lt_fieldcat TYPE slis_t_fieldcat_alv.

* Build the field catalog
  m_fieldcat 'VKORG' 'VBAK'.
  m_fieldcat 'KUNNR' 'VBAK'.
  m_fieldcat 'VBELN' 'VBAK'.
  m_fieldcat 'NETWR' 'VBAK'.

* Fill Layout
  ls_layout-coltab_fieldname  = 'TABCOLOR'.

* Display the list
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
            is_layout   = ls_layout
            it_fieldcat = lt_fieldcat
       TABLES
            t_outtab    = gt_vbak.

ENDFORM.                               " F_DISPLAY_DATA