Page 1 of 1

ALV Grid: Optimize column width

PostPosted: Tue Apr 12, 2011 8:09 am
by Frank183
Hi gang,

I'm experiencing a weird effect:

I have 2 ALV grids in a splitter container, the top grid displays order heads the bottom grid displays the order positions of the selected order head.
Fine, for both grids I set in the layout the zebra look and opt. col. width (LVC_S_LAYO-CWIDTH_OPT) to 'X'.

Now, for the top grid that works fine, but for the bottom grid only the zebra look works, the width of the columns are *not* optimized. If I look at the variant display the box *is* checked. But only when I change *anything* in the variant, all of a sudden it works.

Can anybody explain this ... ?


Re: ALV Grid: Optimize column width

PostPosted: Tue Apr 12, 2011 9:00 am
by Sharpshooter
From OSS note 1009650:
Code: Select all
[12] Within the ALV Grid, the system calculates the optimal column width only during the first call due to performance reasons.
If the method CL_GUI_ALV_GRID->REFRESH_TABLE_DISPLAY is called for the grind instance, the system does not optimize the grid again.
To force the grid to be optimized again, the methods CL_GUI_ALV_GRID->GET_FRONTEND_LAYOUT and CL_GUI_ALV_GRID->SET_FRONTEND_LAYOUT must be called before the method CL_GUI_ALV_GRID->REFRESH_TABLE_DISPLAY is called. The transfer of the parameter CWIDTH_OPT = 'X' ensures that the column widths are calculated again.
In the object model of the ALV (package SALV_OM), you must reset the column optimization by calling the method cl_salv_columns->set_optimize before you call the method cl_salv_table->refresh.

While this is not exactly your case, maybe it helps with a solution?

Re: ALV Grid: Optimize column width

PostPosted: Wed Apr 13, 2011 7:16 am
by Frank183
Hey !!!!!!!

That was spot on !

When I call set_table_for_first_display the itab with it is still empty. Only when an order head is selected the itab becomes filled with data, but then I call only a refresh_table_display.

I found out that before the refresh only a set_frontend_layout is needed.

Thanks a lot, man !!!

Re: ALV Grid: Optimize column width

PostPosted: Mon Nov 07, 2016 1:50 pm
by danilosaciloto
An easy way is to do as follows (after refresh_table_display)

DATA lv_alv_col_opt TYPE sy-ucomm.
lv_alv_col_opt = '&OPT'.
call method screen9001-alv-control->set_function_code
c_ucomm = lv_alv_col_opt.

This always works doesn't matter if in PBO or PAI