2011 Mar 15 12:13 PM
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.
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.
2011 Mar 15 12:30 PM
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
2011 Mar 15 12:30 PM
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
2011 Mar 15 12:31 PM
Hi,
You can do that using the colwidth_optimize = 'X'. in the layout internal table while passing it to the ALV FM.
Thanks,
Sri.
2011 Mar 15 12:40 PM
Hi,
data : fs_field_cat TYPE lvc_s_fcat.
fs_field_cat-outputlen = '30'.
Thanks,
Archana.
2011 Mar 15 2:39 PM
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.
2011 Mar 15 3:02 PM
dont fix the column width, just use:
layout-cwidth_opt = 'X'.
2013 Nov 15 6:03 AM
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( ).
2011 Mar 15 3:11 PM
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
2011 Mar 17 8:35 AM
Hi Alpana,
The only way you can accomplish this is by passing 'X' to the parameter - Layout-colwidth_optimize.
thanks,
Guru.
2013 Nov 15 6:04 AM
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( ).
2013 Nov 21 9:38 PM
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( ).
| User | Count |
|---|---|
| 6 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |