cancel
Showing results for 
Search instead for 
Did you mean: 

Drop down in ALV for Webdynpro ABAP

Former Member
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

sahai
Contributor
0 Kudos

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

Former Member
0 Kudos

Hi S. Sahai,

I have created one node called CSKT (this is a dictionary table) and it contains 4 dictionary element one one element called VALUESET of type WDR_CONTEXT_ATTR_VALUE_LIST.

In my above coding, I have populated this valueset table in the LOOP statement.

Later, I have created one Dropdown objewct where I have given sourse as 'VALUESET element'. I think here I am facing the problem.

Can you describe a better approach to bind data in the ALV after model is created ?

sahai
Contributor
0 Kudos

hi Kalikinkar,

try the above code i am sure it will solve your problem just change the "ame of the column" and values you want to shwoin the code......it wil definetely solve your problem

regards,

sahai.s

gill367
Active Contributor
0 Kudos

HI

I used the same code that you are using.

i am getting the dropdown filled.

second one is filled with only one entry rest are with 3 entries.

put a break point at the line where you are concatenating the strings to add it to value set and see whether values are getting

populated in the table.

thanks

sarbjeet

Former Member
0 Kudos

data is coming into the internal table and it is also get binded. However, I can see blank elements (for 2nd row, I get one blank element) and for other I can see 3 blank elements. Thus it signifies that values are there in the drop down.. however it is not visible to the application. Am I missing something here ?

gill367
Active Contributor
0 Kudos

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

Answers (1)

Answers (1)

Former Member
0 Kudos

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.

Former Member
0 Kudos

Hi Kalikinkar,

I am also having the same problem. I have used the same coding from the net. I checked this thread of yours and tried to change the code but still I am getting empty dropdown. No values are shown in the dropdown.

Please tell me what you did to get the correct dropdown. If you have made any changes in the binding then also please tell me.

I have made a component controller context for the alv table, the same node contains my valueset attribute.

I have then copied this context node to my main view and also to "DATA" node of the interface controller context.

Please tell me what else did you do?

Regards,

Sanghamitra

Former Member
0 Kudos

HI, I also did the same thing, but i cant see the data in the drop down list. Is there anything else I've to do.

Former Member
0 Kudos

Hi ,

    One of my friend was facing theb same issue. & then it has gt resolved by doing the following change in code.

CALL METHOD lr_drdn->set_type

EXPORTING

value = IF_SALV_WD_C_UIE_DRDN_BY_INDEX=>TYPE_KEY_VALUE.

ie. TYPE_KEY_VALUE instead of TYPE_KEY_CONVERT_TO_VALUE.

Regards,

Monishankar Chatterjee

Former Member
0 Kudos

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