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: 

OO ALV Grid, fix with of columns

Former Member
0 Kudos

Hi all,

i use  cl_gui_alv_grid to display an ALV in my dynpro and i need to set the width of columns ; i read that i had to use the field outputlen (structure LVC_S_FCAT) but it don't work.

Do you have a sample for me ?

Regards

Eric

16 REPLIES 16

Former Member
0 Kudos

I've used this sample code with some success.  The outputlen is in the build_fcat.

ALV Report using class CL_GUI_ALV_GRID ~ Team ABAP

Jeremy

ivan_shadrin
Participant
0 Kudos

It looks like there is no way to fix columns width.

0 Kudos

I agree with you.

Former Member
0 Kudos

Hi Eric,

          Create a reference object to the class cl_salv_columns_table and use this set of code to optimize the column length

               obj_columns = obj_salv->get_columns( ).

               obj_columns->set_key_fixation( 'X' ).

               obj_columns->set_optimize('X').

Regards,

Thulja

kabil_g
Active Participant

Hi Erik,

Pls check

CLEAR ls_fieldcat.

  ls_fieldcat-fieldname = 'MATNR'.

  ls_fieldcat-ref_tabname = 'VBAP'.

  ls_fieldcat-ref_fieldname = 'MATNR'.

  ls_fieldcat-outputlen   = 30.

  ls_fieldcat-key             = 'X'.

  APPEND ls_fieldcat TO pt_fieldcat.

michael_kozlowski
Active Contributor
0 Kudos

0 Kudos

Michael, your link is for WebDynpro application...

ivan_shadrin
Participant
0 Kudos

Hi, Eric! Did you find the solution?

roberto_forti
Contributor
0 Kudos

Hi Eric,

Set the field CWIDTH_OPT  as  'X'  in layout structure LVC_S_LAYO.

Regards.

0 Kudos

This is for a variable optimized column width, not for a fixed column width.

former_member182915
Active Contributor
0 Kudos

Hi Eric,

Sorry to say for this problem we d'not have any solution .

on more scenario,

we working with interactive  oalv. before interaction we have proper aliened alv but after interaction that column width automatically reset .this is the situation i face when i tried to fix the column width in O alv.

raymond_giuseppi
Active Contributor

You can only set a default/desired length (field OUTPUTLEN of field catalog) but user shall be able to change it, and of course you must remove the optimize column (field CWIDTH_OPT of layout)

A solution "could" be coded, you have to handle the event AFTER_REFRESH to check field catalog, (GET_FRONTEND_FIELDCATALOG) and if required, update it (SET_FRONTEND_FIELDCATALOG) and display again the grid (REFRESH_TABLE_DISPLAY)

Hint: Try to prevent infinite loop of refresh event <-> refresh method...

Regards,

Raymond

0 Kudos

The "outputlen" field is not giving expected column width when variant details "is_variant" are passed while displaying ALV.

In layout as well as in field catalogue no flag is set for column width optimization.

Note:

A default layout is set but in layout the flag for column width optimization is set to false.

But still the column width is getting set to optimized one.

Please let me know if you are ware about this issue.

Thanks.

As I wrote some year ago, the field catalog are 'default' values and can be ovveride by user/variant.

Did you try my suggested solution: handle the event after_refresh to force again and again (but prevent infinite loop) the width of some fields even if user load a variant or set the optimize flag himself or herself.

Use GET/SET_FRONTEND_LAYOUT to clear CWIDTH_OPT and GET/SET_FRONTEND_FIELDCATALOG to set OUTPUTLEN and COL_OPT

0 Kudos

Thanks a lot for your quick response Raymond.

Yes I got your point and will implement the GET/SET method for field catalogue/ layout to preserve the column width even after user actions.

But in this case it was not even coming for the first time.

In old default layout even after changing the optimize column it was not reflecting in the output.

So I created a new layout at global level and set it as default one with Optimize column flag as false.

And it is working now for first time.

Do a test when you have implemented the event handler, I seem to remember that it is also triggered at the first display, so it would also have fixed an initial variant with column optimization.