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: 

REUSE_ALV_GRID_DISPLAY and optimize column width

andrew_jacobs2
Participant
11,311

Hello,

I'm using REUSE_ALV_GRID_DISPLAY with optimize column width set ON.

I'm allowing users to edit a column that can have from one to fifty characters.

When the grid is initially displayed, if the longest string in this editable column is twenty characters, the optimize column width works just fine.

However, if the user enters a string longer than 20 characters, the column does not re-optimize its width.

I tried refreshing the grid after the user edits the column but that does not work.

So my question:

Is it possible to programatically have the grid re-optimize the column width?

Thx.

Andy

1 ACCEPTED SOLUTION

Former Member
3,003

Andy,

I don't know the answer to you question, but try this and see what happens.

1) Execute with initial data (20 chars in the column)

2) Modify and make it 30

3) Change the layout, go to "Display" tab, check "Optimize Columns" box, and execute

Did it now optimize column width? If it did, then you can debug and see what SAP did. If it did not, as a last resort, you can remove column width optimization and make all of them full width all the time.

5 REPLIES 5

sarbajitm
Contributor
0 Kudos
3,003

Hi,

Don't you put a code piece like the following one:

C_it_layout-colwidth_optimize = 'X'.

where you are building the layout?

Regards.

Former Member
3,004

Andy,

I don't know the answer to you question, but try this and see what happens.

1) Execute with initial data (20 chars in the column)

2) Modify and make it 30

3) Change the layout, go to "Display" tab, check "Optimize Columns" box, and execute

Did it now optimize column width? If it did, then you can debug and see what SAP did. If it did not, as a last resort, you can remove column width optimization and make all of them full width all the time.

bruno_moreira
Explorer
0 Kudos
3,003

Hi Andrew,

try this in the end of form USER_COMMAND, works with ALV_GRID perfectly

  DATA: l_grid(33),

        ls_layout TYPE  lvc_s_layo.

  FIELD-SYMBOLS <fs_grid> TYPE REF TO cl_gui_alv_grid.

  UNASSIGN <fs_grid>.

  l_grid = '(SAPLSLVC_FULLSCREEN)GT_GRID-GRID'.

  ASSIGN (l_grid) TO <fs_grid>.

  IF <fs_grid> IS ASSIGNED.

    CLEAR ls_layout.

    CALL METHOD <fs_grid>->get_frontend_layout

      IMPORTING

        es_layout = ls_layout.

    IF sy-subrc EQ 0.

    ls_layout-cwidth_opt = 'X'.

    CALL METHOD <fs_grid>->set_frontend_layout

      EXPORTING

        is_layout = ls_layout.

    ENDIF.

former_member726065
Discoverer
0 Kudos
3,003

Hi.

"3) Change the layout, go to "Display" tab, check "Optimize Columns" box, and execute"

WHERE?

Thank you.

former_member726065
Discoverer
0 Kudos
3,003

Declare the layout :

DATA: LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,

WA_FCAT TYPE LINE OF SLIS_T_FIELDCAT_ALV.

* And insert in IS_LAYOUT