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: 

Coloring an single field of an ALV using factory method

Former Member
0 Kudos

how can we color just a single field in ALV using factory method.

5 REPLIES 5

Former Member
0 Kudos

FIELDCAT-FIELDNAME = 'VBELN'.

FIELDCAT-EMPHASIZE = 'C710'.------->color

http://saptechnical.com/Tutorials/ALV/ColorSALV/F4.htm

Former Member
0 Kudos

HI shan,

This is using the simple ALV FMs.

iw wanted to get it in SAP ALV factory methods..

Former Member

Former Member
0 Kudos

Hello Regi you may want to check this sample code, basically what you need is to use the lvc_s_colo structure and the set_color method of the class cl_salv_column_table.


METHOD set_colors.
*
*.....Color for COLUMN.....
    DATA: lo_cols_tab TYPE REF TO cl_salv_columns_table,
          lo_col_tab  TYPE REF TO cl_salv_column_table.
    DATA: ls_color TYPE lvc_s_colo.    " Colors strucutre
*
*   get Columns object
    lo_cols_tab = co_alv->get_columns( ).
*
    INCLUDE <color>.
*
*   Get ERDAT column & set the yellow Color fot it
    TRY.
        lo_col_tab ?= lo_cols_tab->get_column( 'ERDAT' ).
        ls_color-col = col_total.
        lo_col_tab->set_color( ls_color ).
      CATCH cx_salv_not_found.
    ENDTRY.
*
*.......Color for Specific Cell & Rows.................
*   Applying color on the 3rd Row and Column AUART
*   Applying color on the Entire 5th Row
*
    DATA: lt_s_color TYPE lvc_t_scol,
          ls_s_color TYPE lvc_s_scol,
          la_vbak    LIKE LINE OF ct_vbak,
          l_count    TYPE i.
*
    LOOP AT ct_vbak INTO la_vbak.
      l_count = l_count + 1.
      CASE l_count.
*       Apply RED color to the AUART Cell of the 3rd Column
        WHEN 3.
          ls_s_color-fname     = 'AUART'.
          ls_s_color-color-col = col_negative.
          ls_s_color-color-int = 0.
          ls_s_color-color-inv = 0.
          APPEND ls_s_color TO lt_s_color.
          CLEAR  ls_s_color.
*
*       Apply GREEN color to the entire row # 5
*         For entire row, we don't pass the Fieldname
        WHEN 5.
          ls_s_color-color-col = col_positive.
          ls_s_color-color-int = 0.
          ls_s_color-color-inv = 0.
          APPEND ls_s_color TO lt_s_color.
          CLEAR  ls_s_color.
      ENDCASE.
*     Modify that data back to the output table
      la_vbak-t_color = lt_s_color.
      MODIFY ct_vbak FROM la_vbak.
      CLEAR  la_vbak.
      CLEAR  lt_s_color.
    ENDLOOP.
*
*   We will set this COLOR table field name of the internal table to
*   COLUMNS tab reference for the specific colors
    TRY.
        lo_cols_tab->set_color_column( 'T_COLOR' ).
      CATCH cx_salv_data_error.                         "#EC NO_HANDLER
    ENDTRY.
*
  ENDMETHOD.                    "set_colors

uwe_schieferstein
Active Contributor
0 Kudos

Hello Reji

You may have a look at my sample report ZUS_SDN_ALV_CELL_STYLE_2 in thread

Regards

Uwe