Skip to Content
1
Jan 08, 2009 at 10:40 AM

CL_SALV_TABLE Problem - Optimize single Column

12394 Views

Hello fellow ABAPers,

I have problem displaying an internal table using the CL_SALV_TABLE class.

Here's what I do:

First creating a SALV object:

DATA gr_salv_table TYPE REF TO cl_salv_table.
cl_salv_table=>factory( EXPORTING r_container  = ref_container
                        IMPORTING r_salv_table = gr_salv_table
                         CHANGING t_table      = itab ).

Then I want to customize the columns to look nice, so creating a column-object:

DATA lr_columns TYPE REF TO cl_salv_columns_table.
lr_columns = gr_salv_table->get_columns( ).

After that I want the columns to have an optimized width, fortunately the CL_SALV_COLUMNS_TABLE class has a neat method to do that:

lr_columns->set_optimize( 'X' ).

Now I use the display method to show the ALV table on screen:

gr_salv_table->display( ).

... and it works, everything looks great, but now I want a single column to have a specific output length while the other columns are still optimized.

It seems to me that the SET_OPTIMIZED method of CL_SALV_COLUMN_TABLE doesn't work, see the following code:

DATA lr_column TYPE REF TO cl_salv_column_table.
lr_columns->set_optimize( 'X' ).
lr_column ?= lr_columns->get_column( 'MANDT' ).
IF lr_column->is_optimized( ) = ' '.
  BREAK-POINT.
ENDIF.

When I debug that piece of code I always end up running into the break-point, which means that this column is not optimized, even though I told the columns class to optimize it.

OK, so I tried to not use the set_optimize method of the columns class at all and do it by myself, optimize every column manually, code:

DATA it_columns TYPE salv_t_column_ref.
FIELD-SYMBOLS <wa_columns> LIKE LINE OF it_columns.

it_columns = ip_ref_columns->get( ).
LOOP AT it_columns ASSIGNING <wa_columns>.
  IF <wa_columns>-r_column->get_columnname( ) NE 'MANDT'.
    <wa_columns>-r_column->set_optimized( 'X' ).
  ENDIF.
ENDLOOP.

This way I check every column that is not mandt and set it optimize = true but that's not working either. No column of the ALV that I see is optimized.

So, it's an SAP SALV_TABLE bug?

Am I doing something wrong?

Is there another way to get what I want? In short: I want to optimize the width of all columns in my table except for one column, where I want do specify its outputlength.

The itab I display is dynamic, I don't know any columns but the one (MANDT) that I want to not being optimized.

Thanks alot, any help would be highly appreciated.

A. Jung