cancel
Showing results for 
Search instead for 
Did you mean: 

Web Dynpro ALV grid column names

Former Member
0 Kudos

Hi,

I wish to specify the text that appears on the column names. At present the name defaults to the field name within the structure. Is there a way to specify the name that i wish to appear for each column? Many thanks in advance

Samir

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Use the following code

* Instantiate the used component
  DATA lo_cmp_usage TYPE REF TO if_wd_component_usage.

  lo_cmp_usage =   wd_this->wd_cpuse_usg_alv( ).
  IF lo_cmp_usage->has_active_component( ) IS INITIAL.
    lo_cmp_usage->create_component( ).
  ENDIF.

* Get Model
  DATA lo_interfacecontroller TYPE REF TO iwci_salv_wd_table .
  lo_interfacecontroller =   wd_this->wd_cpifc_usg_alv( ).

  DATA lo_value TYPE REF TO cl_salv_wd_config_table.
  lo_value = lo_interfacecontroller->get_model(
  ).

*---------- ALV table settings.
  DATA: l_table_settings TYPE REF TO if_salv_wd_table_settings .
  l_table_settings ?= lo_value.
  wd_this->l_table =  l_table_settings .

* Set the Editable property to true
  l_table_settings->set_read_only( abap_false ).
* Set table header
  DATA: l_header TYPE REF TO cl_salv_wd_header.
  l_header = l_table_settings->get_header( ).
  l_header->set_text( 'Sales Orders' ).

*---------- Column settings
  DATA: l_column_settings TYPE REF TO if_salv_wd_column_settings.
  l_column_settings ?= lo_value.

* Get columns
  DATA: lt_columns TYPE salv_wd_t_column_ref ,
        ls_columns TYPE salv_wd_s_column_ref .

  DATA: l_column_header  TYPE REF TO cl_salv_wd_column_header .

  lt_columns = l_column_settings->get_columns( )              .

  LOOP AT lt_columns INTO ls_columns .
   CASE ls_columns-id   .                     
      WHEN 'VBELN'     .
        l_column_header = ls_columns-r_column->get_header( )  .
        l_column_header->set_ddic_binding_field(
           if_salv_wd_c_column_settings=>ddic_bind_none )     .
        l_column_header->set_text( 'Sales Order' ). " column header

       WHEN 'POSNR .
        l_column_header = ls_columns-r_column->get_header( )  .
        l_column_header->set_ddic_binding_field(
           if_salv_wd_c_column_settings=>ddic_bind_none )     .
        l_column_header->set_text( 'Item No' ) . "column header
  
      WHEN 'ZMENG'.
        l_column_header = ls_columns-r_column->get_header( )  .
        l_column_header->set_ddic_binding_field(
           if_salv_wd_c_column_settings=>ddic_bind_none )     .
        l_column_header->set_text( 'Qty' ). "column header

        WHEN OTHERS                                             .
        ls_columns-r_column->set_visible(
                           cl_wd_uielement=>e_visible-none )  .

    ENDCASE  .
  ENDLOOP.

Regards,

Radhika.

Answers (2)

Answers (2)

uday_gubbala2
Active Contributor
0 Kudos

Hi Samir,

By default the ALV sets the column name from the DDIC bindings. You need to remove the corresponding binding to be able to specify a custom heading of your own. Try go through this code snippet given out by Thomas Jung in [here|;:

data: l_ref_cmp_usage type ref to if_wd_component_usage.
  l_ref_cmp_usage =   wd_this->wd_cpuse_alv( ).
  if l_ref_cmp_usage->has_active_component( ) is initial.
    l_ref_cmp_usage->create_component( ).
  endif.
 
  data l_salv_wd_table type ref to iwci_salv_wd_table.
  l_salv_wd_table = wd_this->wd_cpifc_alv( ).
  data l_table type ref to cl_salv_wd_config_table.
  l_table = l_salv_wd_table->get_model( ).
  data l_column type ref to cl_salv_wd_column.
  data l_header type ref to cl_salv_wd_column_header.
 
 l_column = l_table->if_salv_wd_column_settings~get_column( 'CREATED_BY' ).
  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_prop_ddic_binding_field(
    property =  if_salv_wd_c_ddic_binding=>bind_prop_tooltip
    value = if_salv_wd_c_ddic_binding=>ddic_bind_none ).
  l_header->set_tooltip( `TTCreated By` ).
  l_header->set_text( `Created By` ).

Regards,

Uday

Former Member
0 Kudos

Hi,

For setting the column headings you can use the object of class CL_SALV_WD_COLUMN_HEADER.

You can get this object reference from class CL_SALV_WD_COLUMN.

Refer below link to understand this in detail.

http://help.sap.com/saphelp_nw70/helpdata/EN/f7/924a3de0384c2c893ca867cb936551/content.htm

Thanks

Feroz