cancel
Showing results for 
Search instead for 
Did you mean: 

How to color individual cell in dynamic cl salv table

calvinkarlo
Explorer
0 Kudos

Hi experts 

I'm trying to color cell values that are not equal to 0, but I'm getting this entire cell column color.

calvinkarlo_0-1707215793791.png

can you please check my code snippet?

 

  data: t_color  type lvc_t_scol,
        lt_color type lvc_t_scol,
        ls_color type lvc_s_scol.
  data : gr_struct_typ    type ref to  cl_abap_datadescr,
         gr_dyntable_typ  type ref to  cl_abap_tabledescr,
         ls_component     type         cl_abap_structdescr=>component,
         gt_component     type         cl_abap_structdescr=>component_table.
  field-symbols: <gfs_line>,
                 <gfs_line1>,
                 <gfs_line2>,
                 <gfs_line12>,
                 <gfs_dyn_table>  type standard table,
                 <gfs_dyn_struct> type any, "STANDARD TABLE ,
                 <gfs_dyn_table2> type standard table,
                 <fs_color>       type lvc_t_scol.

  " for alv color
  ls_component-name = 't_color'. " <fs_frt>-Z_HEADER.
  ls_component-type ?= cl_abap_datadescr=>describe_by_data( t_color ).
  append ls_component to gt_component.
  "table 1
  gr_struct_typ  ?= cl_abap_structdescr=>create( p_components = gt_component ).
  gr_dyntable_typ = cl_abap_tabledescr=>create( p_line_type = gr_struct_typ ).

  create data:
  gt_dyn_table type handle gr_dyntable_typ,
  gw_dyn_line type handle gr_struct_typ,
  gw_dyn_line1 type handle gr_struct_typ.

  assign gt_dyn_table->* to <gfs_dyn_table>.
  assign gw_dyn_line->* to <gfs_line>.
  assign gw_dyn_line1->* to <gfs_line12>.

Loop itab 
         loop itab2
        assign component 't_color'  of structure <gfs_line> to <fs_color>.
            if <fs3> is assigned.
           
            <fs3> = <fs1> - <fs2>.

                     if <fs3> ne 0.
                      ls_color-fname     = c_diffheader.
                      ls_color-color-col = 6.
                      ls_color-color-int = 1.
                      ls_color-color-inv = 0.
                      append ls_color to lt_color.
                       clear ls_color.
                      <fs_color> = lt_color.
                     endif.
            endif.
      endloop. "itab2
at end of row.
      append <gfs_line> to <gfs_dyn_table>.
      clear: <gfs_line>.
    endat.
endloop.
"display
data  :  lo_cols        type ref to cl_salv_columns,
         lo_salv_table  type ref to cl_salv_table,
         lo_column      type ref to cl_salv_column,
         lo_columns     type ref to cl_salv_columns_table,
         l_gr_functions type ref to cl_salv_functions.

  try.
      cl_salv_table=>factory(
        importing
          r_salv_table = lo_salv_table
        changing
          t_table      = <gfs_dyn_table> ).
    catch cx_salv_msg.

  endtry.
" get columns object
  lo_cols = lo_salv_table->get_columns( ).
  "Set color
  lo_salv_table->get_columns( )->set_color_column( 't_color' ).

  lo_salv_table->display( ).

 

Please help 

 

Sandra_Rossi
Active Contributor
0 Kudos
Your ABAP code cannot compile, there are obvious syntax errors. As you didn't post your real code, I'm not sure it's worth looking at your code... Better debug it yourself: you know that T_COLOR component of your ALV internal table is incorrect so it should be more easy for you than for us.

Accepted Solutions (0)

Answers (1)

Answers (1)

ennowulff
Active Contributor
0 Kudos

Clear lt_color in LOOP or append directly to the needed table: 

append ls_color to <fs_color>.