How to optimize the width of the column of type CL_SALV_COLUMNS_TABLE

               The width of the column is optimized through three methods.

  1. Optimize all columns.
  2. Optimize one single column.
  3. Manually set the width of columns.

The optimization is based on the content of the ALV Table.

  1. Optimize all columns.

In order to optimize all the columns of the ALV Table, call the set_optimize method of the columns object.

DATA lr_all_columns TYPE REF TO cl_salv_columns_table.

lr_all_columns = lr_alv_grid->get_columns ( ).

lr_all_columns->set_optimize ( ).

  • Optimize one single column.

‘SET_OPTIMIZED ( )’ method of the cl_salv_column_table is used to optimize the single column of the ALV Table.

DATA lr_all_columns TYPE REF TO cl_salv_columns_table.

DATA lr_single_column TYPE REF TO cl_salv_column_table.

lr_all_columns = lr_alv_grid -> get_columns ( ).

lr_single_column ?= lr_all_columns -> get_column ( ‘Contact_name’ ).

lr_single_column -> set_optimized ( abap_true ).

  • Manual adjustment of column width.

The method set_output_length of the class cl_salv_column_table can be used to set the width of the particular column to a specific predefined value.

DATA lr_all_columns TYPE REF TO cl_salv_columns_table.

DATA lr_single_column TYPE REF TO cl_salv_column_table.

lr_all_columns = lr_alv_grid -> get_columns ( ).

lr_single_column ?= lr_all_columns -> get_column ( ‘Contact_name’ ).

lr_single_column -> set_output_length ( 50 ).

The above manual adjustment of column width will be ignored, if the columns are optimized with the set_optimize ( ) method.