Skip to Content
avatar image
Former Member

Creating columns in ALV at runtime

Hi Experts,

I want to create some columns in my ALV table dynamically, at runtime, all of which will be dropdown by keys. How to do it ?

Thanks and regards

Sukanya.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • avatar image
    Former Member
    Mar 09, 2009 at 10:20 AM

    Hi Sukanya,

    1) There is method new_table_column is there, you can use this method to create a dymanic column lr_column.

    2) create dropdown by key UI element

    CALL METHOD cl_wd_dropdown_by_key=>new_dropdown_by_key

    EXPORTING

    • bind_enabled =

    • bind_key_visible =

    • bind_read_only =

    bind_selected_key = l_col_bind

    • bind_state =

    • bind_text_direction =

    • bind_tooltip =

    • bind_visible =

    • bind_width =

    • context_menu_behaviour = E_CONTEXT_MENU_BEHAVIOUR-INHERIT

    • context_menu_id =

    • enabled = ABAP_TRUE

    • explanation =

    • id =

    • key_visible =

    • label_for =

    • on_select =

    • read_only =

    • state = E_STATE-NORMAL

    • text_direction = E_TEXT_DIRECTION-INHERIT

    • tooltip =

    • view =

    • visible = E_VISIBLE-VISIBLE

    • width =

    RECEIVING

    control = lr_drop_key.

    3) Attach drop down by key to the column

    CALL METHOD lr_column->set_table_cell_editor

    EXPORTING

    the_table_cell_editor = lr_drop_key.

    Best regards,

    Edited by: Rohit Mahajan on Mar 9, 2009 3:50 PM

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 09, 2009 at 10:26 AM

    Hi Sukanya,

    Please go through this [article|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/4c70444a-0801-0010-7688-9e4bd844b783].

    I hope it helps.

    Regards

    Arjun

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 09, 2009 at 10:40 AM

    Hi Sukanya,

    Am not that sure about what you exactly need. Do you mean to say like you have 4 attributes in your context & you would like 2 of them to be displayed as dropdown's within the ALV? If thats what you want then you can proceed like follows:

    1) Instantiate the ALV Component

    2) Get reference to model

    3) To get the dropdowns displayed you need to set the table to editable

    4) Get references to the ALV columns

    5) Loop through the ALV columns & modify the cell editor of desired column to dropdown

    Regards,

    Uday

    Try check the code snippet below in which I am trying to display 2 columns TEMP & TEMP_NEW as dropdowns:

    DATA:
        lr_alv_usage       TYPE REF TO if_wd_component_usage,
        lr_if_controller   TYPE REF TO iwci_salv_wd_table,
        lr_config          TYPE REF TO cl_salv_wd_config_table,
        lr_column_settings TYPE REF TO if_salv_wd_column_settings,
        lt_columns         TYPE        salv_wd_t_column_ref,
        lr_link            TYPE REF TO cl_salv_wd_uie_link_to_action,
        lr_checkbox        TYPE REF TO cl_salv_wd_uie_checkbox,
        lr_image           TYPE REF TO cl_salv_wd_uie_image,
        lr_dropdown        TYPE REF TO CL_SALV_WD_UIE_DROPDOWN_BY_KEY.
      FIELD-SYMBOLS
        <fs_column> LIKE LINE OF lt_columns.
    
    " Instantiate the ALV Component
      lr_alv_usage = wd_this->wd_cpuse_alv( ).
      IF lr_alv_usage->has_active_component( ) IS INITIAL.
        lr_alv_usage->create_component( ).
      ENDIF.
    
    " Get reference to model
      lr_if_controller = wd_this->wd_cpifc_alv( ).
      lr_config        = lr_if_controller->get_model( ).
    
    " To get the dropdowns displayed you need to set the table to editable by using below statement
      lr_config->if_salv_wd_table_settings~set_read_only( abap_false ).
    
    " Set the UI elements.
      lr_column_settings ?= lr_config.
      lt_columns = lr_column_settings->get_columns( ).
    LOOP AT lt_columns ASSIGNING <fs_column>.
        IF <fs_column>-id = 'CARRID'.
          CREATE OBJECT lr_link.
          lr_link->set_text_fieldname( <fs_column>-id ).
          <fs_column>-r_column->set_cell_editor( lr_link ).
        ENDIF.
    
        IF <fs_column>-id = 'TEMP'.
          CREATE OBJECT lr_dropdown
            EXPORTING
              selected_key_fieldname = 'TEMP'.
          <fs_column>-r_column->set_cell_editor( lr_dropdown ).
        ENDIF.
    
        IF <fs_column>-id = 'TEMP_NEW'.
          CREATE OBJECT lr_dropdown
            EXPORTING
              selected_key_fieldname = 'TEMP_NEW'.
          <fs_column>-r_column->set_cell_editor( lr_dropdown ).
        ENDIF.
      ENDLOOP.
    ENDMETHOD.

    Add comment
    10|10000 characters needed characters exceeded