09-19-2008 10:10 AM
Hi All,
I was wondering whether it is possible to optimize the width of certain columns based on their content and fixed( hard coding the width ) the others, all fields found in the same ALV.
Thanks,
Shabir
09-19-2008 10:20 AM
Hi,
Here are some suggestions for your query :
You can fix length of a particular column in ALV by setting outputlen field in fieldcatalog.
<fieldcatalog>-outputlen = '20'.
You can use key field of fieldcatalog, which will fix your column during horizontal scrolling.
<fieldcatalog>-key = 'X'.
Hope this will solve your query.
Regards,
Brajvir
09-19-2008 10:24 AM
If it is Object Oriented ALV or LVC function then it is possible.
in OOALV/LVC Function Fieldcatalog is of type LVC_S_FCAT
here you have an option to optimize the column level
wa_fcat-COL_OPT = 'X'.
09-19-2008 10:30 AM
hi,
u can use the following
wa_fieldcat-fix_column = 'X'.
this will fix the perticular column.
09-20-2008 9:12 AM
Thanks guys for your explanation but I have already found a solution to my problem. Thank again.
12-04-2009 11:47 AM
Please could you share your answer?
I am using the OO model CL_SALV_TABLE and have used the method set_optimized for specific columns, but they are not being optimized when the grid is displayed.
Example:
Attributes on my class which the code below uses:
gr_columns type ref to CL_SALV_COLUMNS_TABLE.
gr_column type ref to CL_SALV_COLUMN_TABLE.
gr_column ?= gr_columns->get_column(
columnname = 'PSPID' ).
gr_column->set_optimized( abap_true ).
If I use:
gr_columns->set_optimize( abap_true ).
This seems to affect all columns and so those which I want to explicitly set a width are also optimized.
09-20-2010 7:11 PM
Here is what i am using to manage the lenght of the columns.
TRY.
gets the columns object
lref_columns = iref_alv->get_columns( ).
loops trough the columns to hide the unnecessary ones
lt_columns = lref_columns->get( ).
LOOP AT lt_columns INTO ls_column.
lv_colname = ls_column-columnname.
CASE lv_colname.
WHEN 'MANDT'.
ls_column-r_column->set_technical( if_salv_c_bool_sap=>true ).
WHEN 'MATNR'. "Material Number
ls_column-r_column->set_long_text( 'Material Number'(017) ).
ls_column-r_column->set_medium_text( 'Material Number'(017) ).
ls_column-r_column->set_short_text( 'Mat.Number'(036) ).
ls_column-r_column->SET_OUTPUT_LENGTH( '11' ).
WHEN 'MTART'. "Material Type
ls_column-r_column->set_long_text( 'Material Type'(020) ).
ls_column-r_column->set_medium_text( 'Material Type'(020) ).
ls_column-r_column->set_short_text( 'Mat. Type'(037) ).
ls_column-r_column->SET_OUTPUT_LENGTH( '13' ).
WHEN 'MATKL'. "Material Group
ls_column-r_column->set_long_text( 'Material Group'(040) ).
ls_column-r_column->set_medium_text( 'Material Group'(040) ).
ls_column-r_column->set_short_text( 'Mat. Group'(023) ).
ls_column-r_column->set_output_length( '10' ).
WHEN OTHERS.
ENDCASE.
ENDLOOP.