cancel
Showing results for 
Search instead for 
Did you mean: 

How to resize the columns of a table??

Former Member
0 Kudos

HI Friends,

Can anyone tell me..How to resize or drag & drop the column widths of the standard or ALV tables, when it is in the output..?

Accepted Solutions (0)

Answers (3)

Answers (3)

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

Try this if it is 7.0 Enhancement Package1.

data lr_table type ref to cl_salv_wd_config_table. 

 

lr_table->if_salv_wd_table_settings~set_fixed_table_layout( abap_true ).

Former Member
0 Kudos

Hi Shalini,

You can use the below code to programatically set the width: 

DATA: lv_ref_cmp_usage TYPE REF TO if_wd_component_usage,
         lv_salv_wd_table TYPE REF TO iwci_salv_wd_table,
         lv_table TYPE REF TO cl_salv_wd_config_table,
         lv_column TYPE REF TO cl_salv_wd_column.

* create an instance of ALV component

  lv_ref_cmp_usage = wd_this->wd_cpuse_alv_table_inst( ). " Use your component name
  IF lv_ref_cmp_usage->has_active_component( ) IS INITIAL.
    lv_ref_cmp_usage->create_component( ).
  ENDIF.

* get ALV component

  lv_salv_wd_table = wd_this->wd_cpifc_alv_table_inst( ).
  lv_table = lv_salv_wd_table->get_model( ).

lv_column = lv_table->if_salv_wd_column_settings~get_column( 'COLUMN_NAME').

lv_column->set_width( '50%').

If you want to set the width in the output display you can always drag the column header in the ALV output like any other table

Regards,

Gayathri Shanbhag

Former Member
0 Kudos

Thanks for your response,

But by trying both of your codes i am only able to set the widths..but i

cant able to change them in the output itself.

I want to resize the column widths when posted to IE like dis..

Here is a video of it:

http://www.flickr.com/photos/tjung/2806011790/

Pls help me out

Former Member
0 Kudos

Hi Shalini,

Use below code to set the width of column and replace the column names in place of FIELD1,FIELD2...  

DATA: l_columns             TYPE salv_wd_t_column_ref,
        ls_columns            LIKE LINE OF l_columns

    DATA: lr_column             TYPE REF TO cl_salv_wd_column,
        lr_column_text        TYPE REF TO cl_salv_wd_column_header,
        l_value               TYPE REF TO cl_salv_wd_config_table,
        lv_text               TYPE string.

 

    lo_cmp_usage = wd_this->wd_cpuse_alv_table( ).
  IF lo_cmp_usage->has_active_component( ) IS INITIAL.
    lo_cmp_usage->create_component( ).
  ENDIF.
  lo_interfacecontroller = wd_this->wd_cpifc_alv_table( ).
  l_value = lo_interfacecontroller->get_model( ).

    l_value->if_salv_wd_column_settings~get_columns(
   RECEIVING
     value  = l_columns
     ) .

LOOP AT l_columns INTO ls_columns.
    lr_column = l_value->if_salv_wd_column_settings~get_column( ls_columns-id ).

*    change colomun text.
    CALL METHOD lr_column->get_header
      RECEIVING
        value = lr_column_text.
    IF ls_columns-id EQ 'FIELD1'.
      lv_text = 'Description'.
      lr_column->SET_WIDTH( "90" ) .

ELSEIF ls_columns-id EQ 'FIELD2'.
      lv_text = 'Driver Charges'.
        lr_column->SET_WIDTH( '120' ) .
    ELSEIF ls_columns-id EQ 'FIELD3'.
            lv_text = 'Month-Year'.
        lr_column->SET_WIDTH( '120' ) .

   lr_column_text  = ls_columns-r_column->get_header( ).
    CALL METHOD ls_columns-r_column->create_header
      RECEIVING
        value = lr_column_text.
    CALL METHOD lr_column_text->set_text
      EXPORTING
        value = lv_text.



  ENDLOOP.

Regards,

venkat.

Former Member
0 Kudos

Hi Shalini,

If u use above code u can drag and drop column names and we can change the positions also.....

Regards,

Venkat.