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: 

Optimize certain columns and fixed others of the same ALV

Former Member
0 Kudos

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

6 REPLIES 6

Former Member
0 Kudos

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

former_member188685
Active Contributor
0 Kudos

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'.

KK07
Contributor
0 Kudos

hi,

u can use the following

wa_fieldcat-fix_column = 'X'.

this will fix the perticular column.

Former Member
0 Kudos

Thanks guys for your explanation but I have already found a solution to my problem. Thank again.

0 Kudos

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.

0 Kudos

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.