cancel
Showing results for 
Search instead for 
Did you mean: 

Change Header Text for a ALV table column

Former Member
0 Kudos

Hi,

I am trying to change the header text of a column. I am using the following coding:

*"----------------------------------------------------------------------
  DATA:
    lr_cmp_usage               TYPE REF TO if_wd_component_usage,
    lr_com_controller_if       TYPE REF TO iwci_salv_wd_table,
    lr_alv_config              TYPE REF TO cl_salv_wd_config_table,
    lr_alv_column              TYPE REF TO CL_SALV_WD_COLUMN,
    lr_alv_header              TYPE REF TO CL_SALV_WD_COLUMN_HEADER
  ."!
*  FIELD-SYMBOLS:
*
*  ."!
  CONSTANTS:
    abap_true                           TYPE flag VALUE 'X',
    abap_false                          TYPE flag VALUE ' '
  ."!
*"----------------------------------------------------------------------


* get alv config object
*"----------------------------------------------------------------------
  lr_cmp_usage = wd_this->wd_cpuse_usage_alv( ).

* ggf objekt instanziieren
  IF lr_cmp_usage->has_active_component( ) IS INITIAL.
    lr_cmp_usage->create_component( ).
  ENDIF.
  lr_com_controller_if = wd_this->wd_cpifc_usage_alv( ).
  lr_alv_config = lr_com_controller_if->get_model( ).
*"----------------------------------------------------------------------

* get column & header object
*"----------------------------------------------------------------------
  lr_alv_column = lr_alv_config->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN( 'FELD1' ).
  lr_alv_header = lr_alv_column->get_header( ).
*"----------------------------------------------------------------------

* set header text
*"----------------------------------------------------------------------
  lr_alv_header->set_text( 'TEST').
*"----------------------------------------------------------------------

I don't know why the header text is still the same, the change takes no effect.

Where is my mistake?

Thanks & Regards,

Hendrik

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

add this line and try

lr_alv_header ->set_ddic_binding_field( IF_SALV_WD_C_DDIC_BINDING=>DDIC_BIND_NONE ).

Regards

Tamil

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Hendrik,

I don't know if you are trying to change the heading dynamically but if you want to simply change the heading permanently, simply go to the layout window of the view, open the table and the column you want to change. Double click on the header item, TABLE_XXX_HEADER, and then change the value in the properties section in the lower right of the screen. I'm on ECC 6.0 and it works fine.

Thanks,

Tom

Former Member
0 Kudos

Hi,

it was an ALV Table, so this is the only way to change the column name.

If you use a standard table, the way you described is possible.

I am sorry that I didn't mentioned that above.

Regards,

Hendrik

Former Member
0 Kudos

For Standard table,you want to change the header do in this way.

method wddomodifyview .
data: obj_table type ref to cl_wd_table,
      lr_column type ref to cl_wd_table_column,
     lr_header type ref to cl_wd_caption.

obj_table ?= view->get_element( 'TABLE1' ).

lr_column = obj_table->get_column(
               id         = 'TABLE1_PRICE'
*              INDEX      = INDEX
                 ).

lr_header  = lr_column->get_header( ).
lr_header->set_text( value = 'Money'   ).
lr_column->set_header( the_header = lr_header   ).

EndMethod.

Thanks

Suman

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

I ran into the same problem the other day. I thought for sure that setting the text used to override the DDic binding, but I guess that isn't the case any longer. What I found is that you just need to tell the column object to ignore the DDic Bindings with a call to the SET_PROD_DDIC_BINDING_FIELD method:

l_column = l_table->if_salv_wd_column_settings~get_column( 'POSTING_DATE' ).
  data l_header type ref to CL_SALV_WD_COLUMN_HEADER.
  l_header = l_column->get_header( ).
  l_header->SET_PROP_DDIC_BINDING_FIELD(
    property =  IF_SALV_WD_C_DDIC_BINDING=>BIND_PROP_TEXT
    value = IF_SALV_WD_C_DDIC_BINDING=>DDIC_BIND_NONE ).
  l_header->set_text( `Posting Date` ).

Former Member
0 Kudos

Hey guys,

great! It works!

Thank you very much! For others: the working code:

method WDDOINIT .
*"----------------------------------------------------------------------
  DATA:
    lr_cmp_usage               TYPE REF TO if_wd_component_usage,
    lr_com_controller_if       TYPE REF TO iwci_salv_wd_table,
    lr_alv_config              TYPE REF TO cl_salv_wd_config_table,
    lr_alv_column              TYPE REF TO CL_SALV_WD_COLUMN,
    lr_alv_header              TYPE REF TO CL_SALV_WD_COLUMN_HEADER
  ."!
*  FIELD-SYMBOLS:
*
*  ."!
  CONSTANTS:
    abap_true                           TYPE flag VALUE 'X',
    abap_false                          TYPE flag VALUE ' '
  ."!
*"----------------------------------------------------------------------


* get alv config object
*"----------------------------------------------------------------------
  lr_cmp_usage = wd_this->wd_cpuse_usage_alv( ).

* ggf objekt instanziieren
  IF lr_cmp_usage->has_active_component( ) IS INITIAL.
    lr_cmp_usage->create_component( ).
  ENDIF.
  lr_com_controller_if = wd_this->wd_cpifc_usage_alv( ).
  lr_alv_config = lr_com_controller_if->get_model( ).
*"----------------------------------------------------------------------


* get column & header object
*"----------------------------------------------------------------------
  lr_alv_column = lr_alv_config->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN( 'FELD1' ).
  lr_alv_header = lr_alv_column->get_header( ).
*"----------------------------------------------------------------------


* set header text
*"----------------------------------------------------------------------
  lr_alv_header->set_ddic_binding_field( IF_SALV_WD_C_DDIC_BINDING=>DDIC_BIND_NONE ).
  lr_alv_header->set_text( 'TEST').
*"----------------------------------------------------------------------


endmethod.

Edited by: Gedicke, Hendrik on Jul 29, 2008 2:53 PM

Former Member
0 Kudos

Hi

Add the following code before lr_alv_header->set_text( 'TEST').

*"----


lr_alv_header->set_ddic_binding_field( '00' ).

Regards

Naresh