Application Development and Automation 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: 
Read only

Bug in CL_SALV_TREE when using ADD_AGGREGATION / SET_STYLE ?

aabhas_wilmar
Contributor
0 Likes
1,099

Hi Experts!

I am trying to implement CL_SALV_TREE for creating a tree report which will be capable of performing AVERAGE and TOTAL on numeric (INT / DEC) columns. Secondly, I am trying to change the color (style) of the cell (item) based on its value.

To add aggregations I am doing something like this:

 DATA: lr_aggregations TYPE REF TO cl_salv_aggregations.

  lr_aggregations = gr_tree->get_aggregations( ).
  lr_aggregations->clear( ).

 TRY.
      lr_aggregations->add_aggregation( columnname  = 'BKJOB'
                                        aggregation = if_salv_c_aggregation=>total ).
      lr_aggregations->add_aggregation( columnname  = 'CNJOB'
                                        aggregation = if_salv_c_aggregation=>total ).
      lr_aggregations->add_aggregation( columnname  = 'AVCAP'
                                        aggregation = if_salv_c_aggregation=>total ).
    CATCH cx_salv_not_found cx_salv_data_error cx_salv_existing. 
  ENDTRY.

And for changing the STYLE (background color) of a cell (item) I am using following code:

TRY .

        LOOP AT it_nodes INTO wa_nodes.
          l_node_key = wa_nodes-key.
          nodes = gr_tree->GET_NODES( ).

          node = nodes->get_node( l_node_key ).
          item = node->get_item( 'BKCAP' ).
          lv_val = item->get_value( ).
          ASSIGN lv_val->* TO <lv_value>.

          IF <lv_value> GT '100.00'.
            item->set_style( lv_high ). "5 (Red)
          ELSEIF <lv_value> BETWEEN '80.00' AND '100.00'.
            item->set_style( lv_med ). "7 (Yellow)
          ELSEIF <lv_value> LT '80.00'.
            item->set_style( lv_low ). "6 (Green)
          ENDIF.

        ENDLOOP.
      CATCH cx_salv_msg.
    ENDTRY.

The color changes work fine for leaf nodes but it doesn't if it is parent node. If I comment the aggregation code, it displays the color.

I believe ADD_AGGREGATION method overrides the STYLE of the NODE ITEM.

Is it a bug? Any fixes?

Thanks & Regards,

Aabhas K Vishnoi

Hi Experts!

I am trying to implement CL_SALV_TREE for creating a tree report which will be capable of performing AVERAGE and TOTAL on numeric (INT / DEC) columns. Secondly, I am trying to change the color (style) of the cell (item) based on its value.

To add aggregations I am doing something like this:

 DATA: lr_aggregations TYPE REF TO cl_salv_aggregations.

  lr_aggregations = gr_tree->get_aggregations( ).
  lr_aggregations->clear( ).

 TRY.
      lr_aggregations->add_aggregation( columnname  = 'BKJOB'
                                        aggregation = if_salv_c_aggregation=>total ).
      lr_aggregations->add_aggregation( columnname  = 'CNJOB'
                                        aggregation = if_salv_c_aggregation=>total ).
      lr_aggregations->add_aggregation( columnname  = 'AVCAP'
                                        aggregation = if_salv_c_aggregation=>total ).
    CATCH cx_salv_not_found cx_salv_data_error cx_salv_existing. 
  ENDTRY.

And for changing the STYLE (background color) of a cell (item) I am using following code:

TRY .

        LOOP AT it_nodes INTO wa_nodes.
          l_node_key = wa_nodes-key.
          nodes = gr_tree->GET_NODES( ).

          node = nodes->get_node( l_node_key ).
          item = node->get_item( 'BKCAP' ).
          lv_val = item->get_value( ).
          ASSIGN lv_val->* TO <lv_value>.

          IF <lv_value> GT '100.00'.
            item->set_style( lv_high ). "5 (Red)
          ELSEIF <lv_value> BETWEEN '80.00' AND '100.00'.
            item->set_style( lv_med ). "7 (Yellow)
          ELSEIF <lv_value> LT '80.00'.
            item->set_style( lv_low ). "6 (Green)
          ENDIF.

        ENDLOOP.
      CATCH cx_salv_msg.
    ENDTRY.

The color changes work fine for leaf nodes but it doesn't if it is parent node. If I comment the aggregation code, it displays the color.

I believe ADD_AGGREGATION method overrides the STYLE of the NODE ITEM.

Is it a bug? Any fixes?

Thanks & Regards,

Aabhas K Vishnoi

3 REPLIES 3
Read only

naimesh_patel
Active Contributor
0 Likes
881

Actually, when you don't add the aggregations in your TREE, the Node record is exactly same as your very first Leaf so, it takes the same property as the Leaf's property. That's why we can see the color on the first node when we don't apply the Aggregations.

Now, when we apply the aggregations, system applies its own Style on the NODE (Dark Blue color) and this style overrides the style of the Leaf.

Regards,

Naimesh Patel

Read only

0 Likes
881

Hi Naimesh,

Thanks for replying.

I understand your point but ideally aggregation must not override the style.

Anyway, is there a way that I can set my own style to a parent node after aggregation is done?

regards,

Aabhas

Read only

0 Likes
881

is there a way that I can set my own style to a parent node after aggregation is done?

I guess, Aggregation Style would always have higher priority than the Custom Priority.

Regards,

Naimesh Patel