cancel
Showing results for 
Search instead for 
Did you mean: 

How to fix the width of the column when using alv table

Former Member
0 Kudos

Hi ,

I am displaying the contents in a table. Of course using alv component i displayed the content. Now the problem is the column width is not fixed with value of the table entries( based on the domain length level). As length of field increases or decreses as the length of the content increases or decreases. I wanted to fix the column width whatever be the length of the contents.

Can any one help in this regard ?

Thanks Pons.

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member402443
Contributor
0 Kudos

Hi,

Please find the code related to your problem.

METHOD configure_alv .

  • data declaration for column settings

DATA : lr_column_settings TYPE REF TO if_salv_wd_column_settings,

lr_col_header TYPE REF TO cl_salv_wd_column_header,

lt_columns TYPE salv_wd_t_column_ref,

ls_column TYPE salv_wd_s_column_ref.

  • data declaration for table settings

DATA : lr_salv_wd_table_ctr TYPE REF TO iwci_salv_wd_table,

lr_table_settings_ctr TYPE REF TO if_salv_wd_table_settings,

lr_header_ctr TYPE REF TO cl_salv_wd_header.

  • Variables for drop-down and inpufield reference

DATA : lr_drdn_by_key TYPE REF TO cl_salv_wd_uie_dropdown_by_key,

lr_input_field TYPE REF TO cl_salv_wd_uie_input_field,

l_header TYPE string.

  • get ALV Component <CONTRACT_DETAILS>

lr_salv_wd_table_ctr = wd_this->wd_cpifc_payment_detail( ).

wd_this->alv_config_table = lr_salv_wd_table_ctr->get_model( ).

  • set visible row count

lr_table_settings_ctr ?= wd_this->alv_config_table.

lr_table_settings_ctr->set_visible_row_count( '5' ).

lr_table_settings_ctr->set_read_only( abap_false ).

lr_table_settings_ctr->set_grid_mode( ).

lr_table_settings_ctr->set_width(

EXPORTING

value = '980PX' ).

wd_this->alv_config_table->if_salv_wd_table_settings~set_data_check( if_salv_wd_c_table_settings=>data_check_on_cell_event ).

wd_this->alv_config_table->if_salv_wd_std_functions~set_pdf_allowed( abap_false ).

wd_this->alv_config_table->if_salv_wd_std_functions~set_view_list_allowed( abap_false ).

wd_this->alv_config_table->if_salv_wd_std_functions~set_edit_insert_row_allowed( abap_false ).

wd_this->alv_config_table->if_salv_wd_std_functions~set_edit_delete_row_allowed( abap_true ).

wd_this->alv_config_table->if_salv_wd_std_functions~set_export_allowed( abap_false ).

wd_this->alv_config_table->if_salv_wd_std_functions~set_edit_check_available( abap_false ).

CLEAR: l_header.

l_header = wd_assist->if_wd_component_assistance~get_text( '030' ).

lr_header_ctr = lr_table_settings_ctr->get_header( ).

lr_header_ctr->set_text( l_header ).

  • set text header for Columns.

CLEAR: l_header,lt_columns.

lr_column_settings ?= wd_this->alv_config_table.

lt_columns = lr_column_settings->get_columns( ).

LOOP AT lt_columns INTO ls_column.

CASE ls_column-id.

WHEN 'PAYMENT_METHOD'.

  • get header details

lr_col_header = ls_column-r_column->get_header( ).

  • disable DDIC field label

CALL METHOD lr_col_header->set_prop_ddic_binding_field

EXPORTING

property = if_salv_wd_c_ddic_binding=>bind_prop_text

value = if_salv_wd_c_ddic_binding=>ddic_bind_none.

  • set user defined column header

l_header = wd_assist->if_wd_component_assistance~get_text( key = '020' ).

lr_col_header->set_text( l_header ).

CREATE OBJECT lr_drdn_by_key

EXPORTING

selected_key_fieldname = ls_column-id.

ls_column-r_column->set_cell_editor( lr_drdn_by_key ).

ls_column-r_column->se_width( '100PX' ).

lr_drdn_by_key->set_key_visible(

EXPORTING

value = abap_true ).

WHEN OTHERS.

ENDCASE.

CLEAR: l_header,ls_column.

ENDLOOP.

ENDMETHOD.

Regards

Manoj Kumar

Former Member
0 Kudos

Hello,

Please see this: [Web Dynpro ABAP - Fixing a Column in an ALV|https://wiki.sdn.sap.com/wiki/x/GFg].

Regards.

Former Member
0 Kudos

Hi,

Thanks for your information.

In the above replies, The reply given by Arjun may be suitable for my requirement as I need how to fix a column width in the ALV grid.

Not least the reply by David is also very much useful ...like how to fix the scrollable column.

I found both are very much useful.

Again my problem is where to introduce the code of both of these techniques, fixing the width and fixing the scrollable column ? .

Can you please give me an idea ?

Thanks in advance.....

Regards

Pons

yesrajkumar
Active Participant
0 Kudos

Hi,

Use the following code in the DOINIT method of your view.

DATA:

lr_salv_wd_table_usage TYPE REF TO if_wd_component_usage,

lr_salv_wd_table TYPE REF TO iwci_salv_wd_table.

  • Check ALV component usage

lr_salv_wd_table_usage = wd_this->wd_cpuse_alv( ).

IF lr_salv_wd_table_usage->has_active_component( ) IS INITIAL.

lr_salv_wd_table_usage->create_component( ).

ELSE.

lr_salv_wd_table_usage->delete_component( ).

lr_salv_wd_table_usage->create_component( ).

ENDIF.

  • Get ALV component

lr_salv_wd_table = wd_this->wd_cpifc_alv( ).

  • Get ConfigurationModel from ALV Component

wd_this->mr_table = lr_salv_wd_table->get_model( ).

        • Set table settings

DATA:

lr_table_settings TYPE REF TO if_salv_wd_table_settings.

lr_table_settings ?= wd_this->mr_table .

lr_table_settings->set_visible_row_count( '5' ).

lr_table_settings->set_width( '100%' ).

Thanks,

Rajkumar.S

arjun_thakur
Active Contributor
0 Kudos

Hi Ponnuchamy,

You can use the code (given in my previous post ) in the WDDOINIT method of component controller.

I hope it helps.

Regards

Arjun

Former Member
0 Kudos

HI,

I wanted to share my experience.

Arjun, the code you refered will be working if we add it to the doinit() method of the view not in the component controller.

I hope the code given by Rajkumar to place in the doinit() method of the view.

Note:

Since I got the answer i didnt try with other codes.

Any way thanks for all.

regards

Pons.

Edited by: Ponnuchamy on Feb 19, 2009 12:52 PM

Edited by: Ponnuchamy on Feb 24, 2009 10:20 AM

Edited by: Ponnuchamy on Feb 28, 2009 10:23 AM

Former Member
0 Kudos

This has been solved.

Regards

Pons

arjun_thakur
Active Contributor
0 Kudos

Hi Ponnuchamy,

Please refer to this [thread|] and look for the code provided by Jatra.

I hope it helps.

Regards

Arjun