The width of the column is optimized through three methods.
- Optimize all columns.
- Optimize one single column.
- Manually set the width of columns.
The optimization is based on the content of the ALV Table.
- 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.