Application Development 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: 

Dynamically alter the Column width of ALV Grid

Former Member
0 Kudos

Hi,

I have a requirement to dynamically alter the Column width of the ALV grid.

For eg, if I have 3 records in a single column ALV grid then the Columns width should be the maximum of the 3 records.

If the first record is of length 5, 2nd record of length 10 and 3rd record of length 8,

then the column width should dynamically take 10 (maximum length of all the records).

Please let me know if it is possible.

Thanks,

Harini

1 ACCEPTED SOLUTION

SuhaSaha
Advisor
Advisor

Hello,

Its possible. You have to pass the "column width optimizer" flag in the layout structure of the ALV.

DATA: ST_LAYOUT TYPE SLIS_LAYOUT_ALV.

ST_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM       = SY-REPID
      IS_LAYOUT                = FP_ST_LAYOUT "Pass the layout struc. here
      IT_FIELDCAT              = FP_IT_FIELDCAT
      IT_SORT                  = FP_IT_SORT
      I_SAVE                   = 'A'
    TABLES
      T_OUTTAB                 = FP_IT_FINAL
    EXCEPTIONS
      PROGRAM_ERROR            = 1
      OTHERS                   = 2.
  IF SY-SUBRC <> 0.
*   Error in calling Standard ALV Functional Module
  ENDIF.

BR,

Suhas

3 REPLIES 3

SuhaSaha
Advisor
Advisor

Hello,

Its possible. You have to pass the "column width optimizer" flag in the layout structure of the ALV.

DATA: ST_LAYOUT TYPE SLIS_LAYOUT_ALV.

ST_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM       = SY-REPID
      IS_LAYOUT                = FP_ST_LAYOUT "Pass the layout struc. here
      IT_FIELDCAT              = FP_IT_FIELDCAT
      IT_SORT                  = FP_IT_SORT
      I_SAVE                   = 'A'
    TABLES
      T_OUTTAB                 = FP_IT_FINAL
    EXCEPTIONS
      PROGRAM_ERROR            = 1
      OTHERS                   = 2.
  IF SY-SUBRC <> 0.
*   Error in calling Standard ALV Functional Module
  ENDIF.

BR,

Suhas

Former Member
0 Kudos

Hi,

One suggestion is, first get the maximum length from all the entries into one variable..say v_max_length. Now while filling the fieldcat, give ddic_outputlen = v_max_length for all the entries...

Try this...

Hope this helps you...

Former Member
0 Kudos

HI,

In layout Structure set COLWIDTH_OPTIMIZE field to 'X'.