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: 
Read only

ALV grid - column width doesn't get optimized

Former Member
8,336

Dear SAP friends,

My program displays ALV grid in PBO:

  gs_layout-cwidth_opt = 'X'.   " optimize column width


CALL METHOD grid1->set_table_for_first_display
    EXPORTING
    i_structure_name      = 'IT_REPORT_X'
      is_layout            = gs_layout
      is_print             = gs_print
      it_toolbar_excluding = it_exclude

    CHANGING
      it_outtab        = it_report_x
      it_fieldcatalog  = gt_fcat.

I have a custom button in the standard toolbar which I use to repopulate the grid if a certain criteria is met. To repopulate the grid I am using method:

   CALL METHOD grid1->refresh_table_display.

So on initial display the grid has column width optimized.

But when I do refresh - the columns don't get optimized.

What is wrong?

Thank you,

Tatyana

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
2,438

Hello Tatyana

It seems that you have to call method go_grid->set_frontend_layout a second time but please do not ask me when and where (PBO vs. PAI, before/after REFRESH_TABLE_DISPLAY).

However, you are definitely on the safe side if you simply call the entire

CALL METHOD grid1->set_table_for_first_display
    EXPORTING
    i_structure_name      = 'IT_REPORT_X'
      is_layout            = gs_layout
      is_print             = gs_print
      it_toolbar_excluding = it_exclude
 
    CHANGING
      it_outtab        = it_report_x
      it_fieldcatalog  = gt_fcat.

again at PBO. Disadvantage: scroll positions get lost.

Regards

Uwe

5 REPLIES 5
Read only

uwe_schieferstein
Active Contributor
2,439

Hello Tatyana

It seems that you have to call method go_grid->set_frontend_layout a second time but please do not ask me when and where (PBO vs. PAI, before/after REFRESH_TABLE_DISPLAY).

However, you are definitely on the safe side if you simply call the entire

CALL METHOD grid1->set_table_for_first_display
    EXPORTING
    i_structure_name      = 'IT_REPORT_X'
      is_layout            = gs_layout
      is_print             = gs_print
      it_toolbar_excluding = it_exclude
 
    CHANGING
      it_outtab        = it_report_x
      it_fieldcatalog  = gt_fcat.

again at PBO. Disadvantage: scroll positions get lost.

Regards

Uwe

Read only

2,438

I can confirm that this should work if you call

set_frontend_layout

before

refresh_table_display

This was a problem that I had for a while, and this solved it. I called it in the PBO.

Good luck

Brian

Message was edited by:

Brian Sammond

Read only

Former Member
2,438

Thank you guys! Very Much!

I need to keep my scrool.

So the 'set_frontend_layout' before 'refresh_table_display' resolves the problem.

  CALL METHOD grid1->set_frontend_layout
        EXPORTING
            is_layout = gs_layout.
   CALL METHOD grid1->refresh_table_display.

Tatyana.

Read only

0 Likes
2,438

If you question is answered, please mark the question as answered so that people will know.

Brian

Read only

janewar
Participant
0 Likes
2,438

FORM FRM_REFRESH_ALV.

DATA:LS_STABLE TYPE LVC_S_STBL.


CALL METHOD G_GRID->SET_FRONTEND_FIELDCATALOG
EXPORTING
IT_FIELDCATALOG = GT_FIELDCAT.

CALL METHOD G_GRID->SET_FRONTEND_LAYOUT
EXPORTING
IS_LAYOUT = GS_LAYOUT.

LS_STABLE-ROW = 'X'. "固定行
LS_STABLE-COL = 'X'. "固定列

CALL METHOD G_GRID->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = LS_STABLE.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

ENDFORM. " FRM_REFRESH_ALV SPAN { font-family: "Consolas"; font-size: 10pt; color: #F8F8F2; background: #282A36; }.L0S31 { font-style: italic; color: #6272A4; }.L0S32 { color: #BD93F9; }.L0S33 { color: #F1FA8C; }.L0S52 { color: #66D9EF; }.L0S55 { color: #50FA7B; }.L0S70 { color: #50FA7B; }