Skip to Content
avatar image
Former Member

Drop down in ALV for Webdynpro ABAP

Hi Experts,

I was trying to implement one Web dynpro ABAP application that will show one ALV and ALV will content one dropdown so that user can select data from the drop down. Addtion to that, my dropdown should have data based on another column of ALV.

I have followed one article which is available in Net.

At the end of development, ALV is displayed with dropdown. Also dropdown has data binded. However, no data is visible in dropdown.

I have created one context node having four dictionary element and one elemt for dispplaying the dropdown.

In the DoInit method of view, i have written below code:

  • Data Declaration

DATA:

lo_node_cskt TYPE REF TO if_wd_context_node,

lo_el_cskt TYPE REF TO if_wd_context_element,

ls_cskt TYPE wd_this->element_cskt,

lt_cskt TYPE wd_this->elements_cskt,

lo_cmp_usage TYPE REF TO if_wd_component_usage,

lv_value TYPE REF TO cl_salv_wd_config_table,

lr_column TYPE REF TO cl_salv_wd_column,

lr_drdn TYPE REF TO cl_salv_wd_uie_dropdown_by_idx,

ls_value_set TYPE wdr_context_attr_value,

lv_tabix TYPE sy-tabix,

lv_count(2) TYPE c,

lo_interfacecontroller TYPE REF TO iwci_salv_wd_table.

  • Navigate from <CONTEXT> to <CSKT> via lead selection:

lo_node_cskt = wd_context->get_child_node( name = wd_this->wdctx_cskt ).

  • get element via lead selection

lo_el_cskt = lo_node_cskt->get_element( ).

  • Get Data:

SELECT kokrs kostl datbi ktext FROM cskt INTO CORRESPONDING FIELDS OF TABLE lt_cskt.

lv_count = 0.

  • Populate value set

LOOP AT lt_cskt INTO ls_cskt.

lv_tabix = sy-tabix.

CLEAR ls_cskt-ktext.

DO 3 TIMES.

lv_count = lv_count + 1.

CONCATENATE 'TEST' lv_count INTO ls_value_set-text.

CONCATENATE 'TEST' lv_count INTO ls_value_set-value.

if lv_tabix = 2.

if sy-index = 2.

EXIT.

endif.

endif.

APPEND ls_value_set TO ls_cskt-valueset.

ENDDO.

MODIFY lt_cskt FROM ls_cskt INDEX lv_tabix TRANSPORTING ktext valueset.

ENDLOOP.

  • Bind data

lo_node_cskt->bind_table( lt_cskt ).

  • Instantiate ALV

lo_cmp_usage = wd_this->wd_cpuse_alv( ).

IF lo_cmp_usage->has_active_component( ) IS INITIAL.

lo_cmp_usage->create_component( ).

ENDIF.

lo_interfacecontroller = wd_this->wd_cpifc_alv( ).

  • Bind Data to Interface Controller Node

lo_interfacecontroller->set_data(

r_node_data = lo_node_cskt

).

  • Get ALV reference table

lv_value = lo_interfacecontroller->get_model( ).

  • Make KTEXT column as drop down

CALL METHOD lv_value->if_salv_wd_column_settings~get_column

EXPORTING

id = 'KTEXT'

RECEIVING

value = lr_column.

  • Create Object for Drop down

CREATE OBJECT lr_drdn

EXPORTING

selected_key_fieldname = 'KTEXT'.

CALL METHOD lr_drdn->set_valueset_fieldname

EXPORTING

value = 'VALUESET'.

CALL METHOD lr_drdn->set_type

EXPORTING

value = IF_SALV_WD_C_UIE_DRDN_BY_INDEX=>TYPE_KEY_CONVERT_TO_VALUE.

CALL METHOD lr_column->set_cell_editor

EXPORTING

value = lr_drdn.

CALL METHOD lv_value->if_salv_wd_table_settings~set_read_only

EXPORTING

value = abap_false.

I am still finding the answer why data in drop down is not visible. However, I can select by clicking dropdown and blank elements (since data is not visible) can be selected.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Jan 27, 2011 at 09:30 AM

    HI Kalikinkar,

    FOR GETTING DROPDOWN GENERALLY WE DO THE FOLLOWING.

    1) CHOOSE THE FIELD IN ALV WHERE WE HAVE TO GIVE THE DROPWON....

    2)TO POPULATE VALUE IN THE DROPDOWN WE MAKE AN ATTRIBUTE valueset OF TYPE WDR_CONTEXT_ATTR_VALUE_LIST

    .remember here that this node is simply used because we have to populate value in the dropdown it will not be used for binding it with any other attribute.

    use the following code

    data: lr_col type ref to CL_SALV_WD_COLUMN,
    lr_dropdown type ref to cl_salv_wd_uie_dropdown_by_key.
    lo_value = lo_interfacecontroller->get_model( ).
    lo_value->if_salv_wd_table_settings~set_read_only( abap_false ).
    lr_column = lo_value->if_salv_wd_column_settings~get_column( id = 'Name of the alv column' ).
    create object lr_dropdown exporting selected_key_fieldname = 'Name of the alv column' ..
    lr_column->set_cell_editor( lr_dropdown ).
    data: lt_valueset type table of wdr_context_attr_value,
    ls_valueset type wdr_context_attr_value,
    lr_node type ref to if_wd_context_node,
    lr_nodeinfo type ref to if_wd_context_node_info.
    lr_node = wd_context->get_child_node( 'CTX_VN_ALV_TABLE' ).
    lr_nodeinfo = lr_node->get_node_info( ).
    * navigate from <CONTEXT> to <CTX_VN_ALV_TABLE> via lead selection
      LO_ND_CTX_VN_ALV_TABLE = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_CTX_VN_ALV_TABLE ).
    * get element via lead selection
      LO_EL_CTX_VN_ALV_TABLE = LO_ND_CTX_VN_ALV_TABLE->GET_ELEMENT( ).
    * @TODO handle not set lead selection
      IF LO_EL_CTX_VN_ALV_TABLE IS INITIAL.
      ENDIF.
      CALL METHOD LO_ND_CTX_VN_ALV_TABLE->GET_STATIC_ATTRIBUTES_TABLE
        IMPORTING
          TABLE = LT_ALV.
    *append ls_valueset to lt_valueset.
    ls_valueset-value = 'First value'.
    ls_valueset-text = 'First value'. 
    append ls_valueset to lt_valueset.
    
    ls_valueset-value = 'Second value'.
    ls_valueset-text = 'Second value'. 
    append ls_valueset to lt_valueset.
    lr_nodeinfo->set_attribute_value_set(
    exporting
    name = 'TYPES'
    value_set = lt_valueset
    ).

    this code will show the dropdown in alv column and values will be first valeu and second value

    hope this will solve your problem

    regards,

    sahai.s

    Edited by: sahai.s on Jan 27, 2011 10:31 AM

    Edited by: sahai.s on Jan 27, 2011 10:34 AM

    Add comment
    10|10000 characters needed characters exceeded

    • Hey

      i am using the same code except i have just modified little bit the select statement to restrict the number of entries.

      and also besides writing the code in wddoinit i have added the compenent usage of alv component and added the node

      having the structure ckst and after that deleting the dictionary reference to add the attribute valueset in both places

      component controller and view controller and mapped them and mapped the data node of interface controller of comp

      usage to this node in comp contrlr.

      and adding the view container and embeding table view of alv comp there.

      that's it

      and here is the code which is almost same as yours except small change in select statement.

      method WDDOINIT .
        DATA:
      lo_node_cskt TYPE REF TO if_wd_context_node,
      lo_el_cskt TYPE REF TO if_wd_context_element,
      ls_cskt TYPE wd_this->element_cskt,
      lt_cskt TYPE wd_this->elements_cskt,
      lo_cmp_usage TYPE REF TO if_wd_component_usage,
      lv_value TYPE REF TO cl_salv_wd_config_table,
      lr_column TYPE REF TO cl_salv_wd_column,
      lr_drdn TYPE REF TO cl_salv_wd_uie_dropdown_by_idx,
      ls_value_set TYPE wdr_context_attr_value,
      lv_tabix TYPE sy-tabix,
      lv_count(2) TYPE c,
      lo_interfacecontroller TYPE REF TO iwci_salv_wd_table.
      
      * Navigate from <CONTEXT> to <CSKT> via lead selection:
      lo_node_cskt = wd_context->get_child_node( name = wd_this->wdctx_cskt ).
      
      * get element via lead selection
      lo_el_cskt = lo_node_cskt->get_element( ).
      
      * Get Data:
      SELECT kokrs kostl datbi ktext FROM cskt INTO CORRESPONDING FIELDS OF TABLE lt_cskt up to 10 rows .
      
      lv_count = 0.
      
      * Populate value set
      LOOP AT lt_cskt INTO ls_cskt.
      lv_tabix = sy-tabix.
      CLEAR ls_cskt-ktext.
      DO 3 TIMES.
      lv_count = lv_count + 1.
      CONCATENATE 'TEST' lv_count INTO ls_value_set-text.
      CONCATENATE 'TEST' lv_count INTO ls_value_set-value.
      if lv_tabix = 2.
      if sy-index = 2.
      EXIT.
      endif.
      endif.
      APPEND ls_value_set TO ls_cskt-valueset.
      ENDDO.
      
      MODIFY lt_cskt FROM ls_cskt INDEX lv_tabix TRANSPORTING ktext valueset.
      ENDLOOP.
      
      * Bind data
      lo_node_cskt->bind_table( lt_cskt ).
      
      * Instantiate ALV
      lo_cmp_usage = wd_this->wd_cpuse_alv( ).
      IF lo_cmp_usage->has_active_component( ) IS INITIAL.
      lo_cmp_usage->create_component( ).
      ENDIF.
      
      lo_interfacecontroller = wd_this->wd_cpifc_alv( ).
      
      * Bind Data to Interface Controller Node
      lo_interfacecontroller->set_data(
      r_node_data = lo_node_cskt
      ).
      
      * Get ALV reference table
      lv_value = lo_interfacecontroller->get_model( ).
      
      * Make KTEXT column as drop down
      CALL METHOD lv_value->if_salv_wd_column_settings~get_column
      EXPORTING
      id = 'KTEXT'
      RECEIVING
      value = lr_column.
      
      * Create Object for Drop down
      CREATE OBJECT lr_drdn
      EXPORTING
      selected_key_fieldname = 'KTEXT'.
      
      CALL METHOD lr_drdn->set_valueset_fieldname
      EXPORTING
      value = 'VALUESET'.
      CALL METHOD lr_drdn->set_type
      EXPORTING
      value = IF_SALV_WD_C_UIE_DRDN_BY_INDEX=>TYPE_KEY_CONVERT_TO_VALUE.
      
      CALL METHOD lr_column->set_cell_editor
      EXPORTING
      value = lr_drdn.
      
      CALL METHOD lv_value->if_salv_wd_table_settings~set_read_only
      EXPORTING
      value = abap_false.
      endmethod.

      thanks

      sarbjeet

  • avatar image
    Former Member
    Jan 28, 2011 at 06:52 AM

    thanks guys. Now i am able to view the data in drop down... all i needed was to declare a global context and map it to view context.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Monishankar,

      This solution is the Savior 😊

      I had the same issue discussed in this thread and has been resolved by changing TYPE_KEY_CONVERT_TO_VALUE to TYPE_KEY_VALUE.

      Thanks,

      Somu