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

Optimise ALV header

Former Member
0 Likes
3,403

Hi everyone,

Is there any way for me to optimize the ALV columns in such a way that the length is picked as the larger of either the long header that I provide through my program or the column content?

For example:

if the header is 'Employee Name' and the entry is 'Dave', I should be able to see the entire header 'Employee Name' for that column. Conversely, if the heading is 'Employee Name' but the entry is 'Leonardo daVinci' the column should optimize itself to fit the entire entry.

Thanks and regards,

Alpana.

data: alv TYPE REF TO cl_salv_table,

       lr_columns TYPE REF TO cl_salv_columns_table.

cl_salv_table=>factory( IMPORTING r_salv_table = alv

                         CHANGING  t_table   = it_f ).  --> internal table

lr_columns = alv->get_columns( ).

lr_columns->set_optimize( 'X' ).

alv->display( ).

11 REPLIES 11
Read only

Former Member
0 Likes
2,432

Hi Alpana,

While designing the layout for your ALV , Design it as follows.

DATA: gs_layout TYPE slis_layout_alv.

.........

.........

.................

.................

.......................

gs_layout-colwidth_optimize = 'X'.

.............................

.............................

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = l_repid

is_layout = gs_layout " Use here

it_fieldcat = gt_fieldcat

i_save = 'A'

it_events = gt_events[]

it_sort = lt_sort

i_callback_user_command = 'PROCESS_USER_COMMAND'

TABLES

t_outtab = lt_display

EXCEPTIONS

program_error = 1

OTHERS = 2.

This will take care of the column width according to the value length.

Regards,

Subhash

Read only

Former Member
0 Likes
2,432

Hi Alpana,

You can use column optimize option which is part of the field catalogue properties.

use below code for column header optimize

FORM field_catalog .

DEFINE fcat.

clear wa_fcat.

wa_fcat-fieldname = &1.

wa_fcat-outputlen = &2.

wa_fcat-COL_OPT = &3.

append wa_fcat to fcat.

END-OF-DEFINITION.

fcat : 'MATNR' '18' 'A'.

Endform.

Regards,

Kunjan

Read only

sridhar_meesala
Active Contributor
0 Likes
2,432

Hi,

You can do that using the colwidth_optimize = 'X'. in the layout internal table while passing it to the ALV FM.

Thanks,

Sri.

Read only

Former Member
0 Likes
2,432

Hi,

data : fs_field_cat TYPE lvc_s_fcat.

fs_field_cat-outputlen = '30'.

Thanks,

Archana.

Read only

Former Member
0 Likes
2,432

Thanks everyone, for your valuable inputs. However, I am creating the ALV using classes, so could you please give me suggestions for the same instead of 'REUSE_ALV_GRID_DISPLAY'.. Thank you.

Also, if I fix the column width, and if in the future the data exceeds those many characters, I shall have problems right? And also to point out, if I set the optimize field and after optimization, the column is fit for 'short' length, but my column header exceeds 10 characters, the ALV will display the corresponding short field level maintained in the data dictionary instead of the medium/long text I pass through my program right? None of the above two cases are desirable.

So is there a way for me to optimize the column width to my header length if the data is shorter than the header or to the data if it is longer than the header?

Thanks again.

Regards,

Alpana.

Read only

0 Likes
2,432

dont fix the column width, just use:

layout-cwidth_opt = 'X'.

Read only

0 Likes
2,432

data: alv TYPE REF TO cl_salv_table,

       lr_columns TYPE REF TO cl_salv_columns_table.

cl_salv_table=>factory( IMPORTING r_salv_table = alv

                         CHANGING  t_table   = it_f ).  --> internal table

lr_columns = alv->get_columns( ).

lr_columns->set_optimize( 'X' ).

alv->display( ).

Read only

Former Member
0 Likes
2,432

Hi..

don't use column width optimise but try this when creating your field catalogue:

ls_fieldcat-reptext_ddic = text-001 "text-001 contains Employee Information

ls_fieldcat--outputlen = STRLEN( text-001 ) " This will calculate the length of the header

Hope this work for you

Read only

Former Member
0 Likes
2,432

Hi Alpana,

The only way you can accomplish this is by passing 'X' to the parameter - Layout-colwidth_optimize.

thanks,

Guru.

Read only

0 Likes
2,432

data: alv TYPE REF TO cl_salv_table,

       lr_columns TYPE REF TO cl_salv_columns_table.

cl_salv_table=>factory( IMPORTING r_salv_table = alv

                         CHANGING  t_table   = it_f ).  --> internal table

lr_columns = alv->get_columns( ).

lr_columns->set_optimize( 'X' ).

alv->display( ).

Read only

Former Member
0 Likes
2,432

data: alv TYPE REF TO cl_salv_table,

       lr_columns TYPE REF TO cl_salv_columns_table.

cl_salv_table=>factory( IMPORTING r_salv_table = alv

                         CHANGING  t_table   = it_f ).  --> internal table

lr_columns = alv->get_columns( ).

lr_columns->set_optimize( 'X' ).

alv->display( ).