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

Column width cl_salv_tree - data not displaying without set_optimize

matt
Active Contributor
3,479
  METHOD set_columns.
    DATA columns TYPE REF TO cl_salv_columns_tree.
    columns = tree->get_columns( ).
    columns->set_optimize( ).
    DATA all_columns TYPE salv_t_column_ref.
    all_columns = columns->get( ).
    DATA column TYPE salv_s_column_ref.
    LOOP AT all_columns INTO column.
      CASE column-columnname.
        WHEN 'GROUP_NAME'.
          column-r_column->set_output_length( 30 ).
        WHEN 'OWNER'.
          column-r_column->set_technical( ).
        WHEN 'DESCRIPT'.
          column-r_column->set_output_length( 30 ).
        WHEN 'CLASS_NAME'.
          column-r_column->set_technical( ).
        WHEN 'ACTIVE'.
          column-r_column->set_output_length( 10 ).
      ENDCASE.
    ENDLOOP.
  ENDMETHOD.

The set_output_length methods calls have no effect. The column width is set to the width of the column header. The tree is visible.

When I take out set_optimize the column widths are as I want them - but the tree isn't visible.

Any ideas?

1 ACCEPTED SOLUTION
Read only

Sandra_Rossi
Active Contributor
3,090

Weird.

Maybe you can get better results with this:

tree->get_tree_settings( )->set_hierarchy_size( 50 ). " width you want
7 REPLIES 7
Read only

Sandra_Rossi
Active Contributor
3,091

Weird.

Maybe you can get better results with this:

tree->get_tree_settings( )->set_hierarchy_size( 50 ). " width you want
Read only

matt
Active Contributor
0 Likes
3,090

I'm glad you think it's weird. I was beginning to doubt myself. It's the first time I've used CL_SALV_TREE, believe it or not. The column width is my only remaining issue.

I'll try the tree settings thing tomorrow.

Read only

matt
Active Contributor
3,090

Yes. It works!

Once again your technical brilliance shines through. Thank you.

Read only

3,090

frdric.girod matthew.billingham When I have a doubt, I test before answering (what I did yesterday), here was my "minimal reproducible example" (play with <========= to see a weird result when combining):

DATA: go_tree   TYPE REF TO cl_salv_tree,
      gt_outtab TYPE TABLE OF alv_t_t2.
TRY.
    " Note: T_TABLE must be empty otherwise exception occurs immediately!
    " ADD_NODE fills the T_TABLE, SET_DATA_ROW updates it
    gt_outtab = VALUE #( ).
    cl_salv_tree=>factory(
      IMPORTING
        r_salv_tree = go_tree
      CHANGING
        t_table     = gt_outtab ).
    go_tree->get_columns( )->set_optimize( ).                           " <=====================
*    go_tree->get_columns( )->get_column( 'FLDATE' )->set_optimized( ).  " <=====================
*    go_tree->get_tree_settings( )->set_hierarchy_size( 50 ).            " <=====================
    DATA(nodes) = go_tree->get_nodes( ).
    DATA(node_key) = nodes->add_node( related_node = ''
                                      text         = 'root'
                                      relationship = cl_gui_column_tree=>relat_last_child
                    )->get_key( ).
    SELECT * FROM alv_t_t2 INTO TABLE @DATA(lt_outtab) UP TO 3 ROWS.
    LOOP AT lt_outtab REFERENCE INTO DATA(alv_line).
      node_key = nodes->add_node( related_node = node_key
                                  data_row     = alv_line->*
                                  text         = |{ alv_line->carrid }|
                                  relationship = cl_gui_column_tree=>relat_last_child
                    )->get_key( ).
    ENDLOOP.
    go_tree->display( ).
  CATCH cx_salv_error INTO DATA(lx).
    MESSAGE lx TYPE 'I' DISPLAY LIKE 'E'.
ENDTRY.
Read only

FredericGirod
Active Contributor
0 Likes
3,090

it it is possible, can you isolate this tree an provide the code, we could check in our system too.

Read only

matt
Active Contributor
3,090

frdric.girod I would... but Sandra got the answer!

Read only

FredericGirod
Active Contributor
3,090

The great Sandra !