on 07-10-2007 3:33 PM
Hi,
I;m struggling with creating drop-down in alv grid and unfortunately I couldn't find any reasonable solution. One of the column in grid should be dropdown type, data in dropdown should come from internal table.
I would apreciate your help,
Adam
Hi,
thanks for your reply, I really do appreciate your help.
I created dropdown for one column and it works. Now I'm stuck with creating second dropdown in the same alv.
I will give you some backgrounds of the steps I followed.
1) I added to new fields to the structure which is shown in the alv, FIELD1 and FIELD2, both are of WDR_CONTEXT_ATTR_VALUE_LIST type.
2) I initialize the columns, where dropdown is supposed to be:
- first column
l_col_name = 'COL1'.
lr_column = lr_model->if_salv_wd_column_settings~get_column( l_col_name ).
*set editable
wd_comp_controller->editable_columns(
EXPORTING
ir_model = lr_model
i_col_name = l_col_name
).
DATA: lr_drdn_by_idx_col1 TYPE REF TO cl_salv_wd_uie_dropdown_by_idx.
CREATE OBJECT lr_drdn_by_idx_erfme EXPORTING selected_key_fieldname = 'col1'.
lr_drdn_by_idx_col1->set_valueset_fieldname( value = 'FIELD1' ).
lr_drdn_by_idx_col1->set_read_only( value = abap_false ).
lr_drdn_by_idx_col1->set_type( if_salv_wd_c_uie_drdn_by_index=>type_key_value ).
lr_column->set_cell_editor( lr_drdn_by_idx_col1 ).
- second column
l_col_name = 'col2'.
lr_column = lr_model->if_salv_wd_column_settings~get_column( l_col_name ).
wd_comp_controller->editable_columns(
EXPORTING
ir_model = lr_model
i_col_name = l_col_name
).
DATA: lr_drdn_by_idx_col2 TYPE REF TO cl_salv_wd_uie_dropdown_by_idx.
CREATE OBJECT lr_drdn_by_idx_col2 EXPORTING selected_key_fieldname = 'FIELD2'.
lr_drdn_by_idx_col2->set_valueset_fieldname( value = 'FIELD2' ).
lr_drdn_by_idx_col2->set_read_only( value = abap_false ).
lr_drdn_by_idx_col2->set_type( if_salv_wd_c_uie_drdn_by_index=>type_key_value ).
lr_column->set_cell_editor( lr_drdn_by_idx_col2 ).
3) so far is everything ok, problem come up when I load the data, actually straight after that, in Debugger functions loading data doesn't show any errors. However before showing website I got an error.
Piece of code loading data into structure with dropdown:
ls_po_result TYPE zstructure.
lt_po_result TYPE table of zstructure.
fields where dropdown supposed to be
ls_po_result-col1 = value1.
ls_po_result-col2 = value2.
fields where dropdownlist is hold
this method return table type WDR_CONTEXT_ATTR_VALUE_LIST.
call method fill_single_dd
exporting id = ls_po_result-id
receiving dd_table = ls_po_result-FIELD1[].
ls_po_result-FIELD2 = ls_po_result-FIELD1.
APPEND ls_po_result TO lt_po_result.
************************************************************************************
The error I'm encountering is:
<b> The following error text was processed in the system T03 : Lower-Level Node with Name VIEW_TABLE.1.DATA.1.SALV_WD_NODE_00001.SALV_WD_NODE_00002 Does Not Exist </b>
***************************************************************************************
One more thing, no matter which dropdown I implement it works, the problem encounter when I add the second one.
Any help I would appreciate.
Kind regards,
Adam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Adam,
I am not very sure about the error you have got. Have you added the field1 and field2 as child nodes in your context nodes? They need to be attributes in the same node as the data, and not child nodes.
Also, where do you call the fill_data method? It should be called in the init method itself. What are the data types of the fields value1 and value2? One more thing - what is the code in the editable_columns method of the component controller? I dont think you need that method. Since the ALV is set as edit enabled at the table settings level itself, you dont need it for each column.
I have tried code similar to yours, with two drop downs and it works fine for me. My sample code is for a context node that has two fields - company_name and url. There are two more fields name_list and url_list which hold the set of values for these two drop downs. In my case, the entire code is in the init method. You can probably compare it with your code and check if something is missing.
<b>method WDDOINIT .</b>
data: lt_valueset type wdr_context_attr_value_list,
ls_valueset type wdr_context_attr_value,
lr_node type ref to if_wd_context_node,
stru_links type if_main=>element_links,
itab_links type if_main=>elements_links.
lr_node = wd_context->get_child_node( name = 'LINKS' ).
clear: ls_valueset.
ls_valueset-value = 'N1'.
ls_valueset-text = 'Google'.
append ls_valueset to lt_valueset.
clear: ls_valueset.
ls_valueset-value = 'N2'.
ls_valueset-text = 'Microsoft'.
append ls_valueset to lt_valueset.
clear: ls_valueset.
ls_valueset-value = 'N3'.
ls_valueset-text = 'SAP'.
append ls_valueset to lt_valueset.
clear: stru_links.
stru_links-name_list = lt_valueset.
clear: lt_valueset, ls_valueset.
ls_valueset-value = 'U1'.
ls_valueset-text = 'www.google.com'.
append ls_valueset to lt_valueset.
clear: ls_valueset.
ls_valueset-value = 'U2'.
ls_valueset-text = 'www.microsoft.com'.
append ls_valueset to lt_valueset.
clear: ls_valueset.
ls_valueset-value = 'U3'.
ls_valueset-text = 'www.sap.com'.
append ls_valueset to lt_valueset.
stru_links-url_list = lt_valueset.
append stru_links to itab_links.
DATA: l_ref_INTERFACECONTROLLER TYPE REF TO IWCI_SALV_WD_TABLE,
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.
l_ref_INTERFACECONTROLLER = wd_This->wd_CpIfc_Alv( ).
l_ref_INTERFACECONTROLLER->Set_Data(
R_NODE_DATA = lr_node " Ref to if_Wd_Context_Node
).
DATA:
l_alv_model TYPE REF TO cl_salv_wd_config_table,
lr_column_settings TYPE REF TO if_salv_wd_column_settings,
lr_column TYPE REF TO cl_salv_wd_column,
lr_dropdown_1 type ref to cl_salv_wd_uie_dropdown_by_idx,
lr_dropdown_2 type ref to cl_salv_wd_uie_dropdown_by_idx.
l_alv_model = l_ref_interfacecontroller->get_model( ).
l_alv_model->if_salv_wd_table_settings~set_read_only( abap_false ).
lr_column ?= l_alv_model->if_salv_wd_column_settings~get_column( id = 'NAME' ).
CREATE OBJECT lr_dropdown_1 EXPORTING selected_key_fieldname = 'NAME'.
lr_dropdown_1->set_valueset_fieldname( value = 'NAME_LIST' ).
lr_dropdown_1->set_read_only( value = abap_false ).
lr_dropdown_1->set_type( if_salv_wd_c_uie_drdn_by_index=>type_key_value ).
lr_column->set_cell_editor( lr_dropdown_1 ).
lr_column ?= l_alv_model->if_salv_wd_column_settings~get_column( id = 'URL' ).
CREATE OBJECT lr_dropdown_2 EXPORTING selected_key_fieldname = 'URL'.
lr_dropdown_2->set_valueset_fieldname( value = 'URL_LIST' ).
lr_dropdown_2->set_read_only( value = abap_false ).
lr_dropdown_2->set_type( if_salv_wd_c_uie_drdn_by_index=>type_key_value ).
lr_column->set_cell_editor( lr_dropdown_2 ).
lr_node->bind_elements( itab_links ).
<b>endmethod.</b>
Hope this helps. Do get back if you face more issues.
Regards,
Nithya
Hi Nithya S,
Thanks for your answer. I respond with delay as I've been trying to tackle the issue with more than one dropdown in one alv and it seems that it's not possible.
I implemented dropdowns your way, however I'm still getting the same error.
The only way is to have two dropdowns with the same value list and the same current value. It means that once I change value in the first dropdown it will be changed in the second as well.
Kind regards,
Adam
Hi Nithya,
I did everything like your code with 5 dropdowns. But when I run my web dynpro application, there is no error, but not the content is shown, that was in the editable alv before, but an empty alv with only one editable row. There the dropdowns are as they should be. With the right content - I can chose all that I want. When I save the new inputs, all the content that was in the alv before is shown (with my new row ), but when I try now to use the dropdowns, there is nothing filled in. I am not able to chose anything. How can this be? Have I to do something in another method, than in the wddoinit?
Best Regards
Ingmar
I think the easiest way is to post my complete method. Sorry, its long, because of 5 dropdown and some input fields:
METHOD wddoinit .
DATA:lt_valueset TYPE wdr_context_attr_value_list,
ls_valueset TYPE wdr_context_attr_value,
lr_node TYPE REF TO if_wd_context_node,
stru_total_list TYPE if_mainview=>element_node_dispo_tab,
itab_total_list TYPE if_mainview=>elements_node_dispo_tab.
*Input for the Prio Dropdown
lr_node = wd_context->get_child_node( name = 'NODE_DISPO_TAB' ).
CLEAR: ls_valueset.
ls_valueset-value = 'I'.
ls_valueset-text = 'I'.
INSERT ls_valueset INTO TABLE lt_valueset.
CLEAR: ls_valueset.
ls_valueset-value = 'II'.
ls_valueset-text = 'II'.
INSERT ls_valueset INTO TABLE lt_valueset.
CLEAR: ls_valueset.
ls_valueset-value = 'III'.
ls_valueset-text = 'III'.
INSERT ls_valueset INTO TABLE lt_valueset.
CLEAR: stru_total_list.
stru_total_list-prio_list = lt_valueset.
Input for the Status Dropdown
CLEAR: ls_valueset, lt_valueset.
ls_valueset-value = 'Offen'.
ls_valueset-text = 'Offen'.
INSERT ls_valueset INTO TABLE lt_valueset.
CLEAR: ls_valueset.
ls_valueset-value = 'Angebot'.
ls_valueset-text = 'Angebot'.
INSERT ls_valueset INTO TABLE lt_valueset.
stru_total_list-status_list = lt_valueset.
*Input for the Remote Dropdown
CLEAR: ls_valueset, lt_valueset.
ls_valueset-value = 'Ja'.
ls_valueset-text = 'Ja'.
INSERT ls_valueset INTO TABLE lt_valueset.
CLEAR: ls_valueset.
ls_valueset-value = 'Nein'.
ls_valueset-text = 'Nein'.
INSERT ls_valueset INTO TABLE lt_valueset.
stru_total_list-remote_list = lt_valueset.
Input for the Skill Dropdown
CLEAR: ls_valueset, lt_valueset.
ls_valueset-value = 'SAPScript'.
ls_valueset-text = 'SAPScript'.
INSERT ls_valueset INTO TABLE lt_valueset.
CLEAR: ls_valueset.
ls_valueset-value = 'Smartforms'.
ls_valueset-text = 'Smartforms'.
INSERT ls_valueset INTO TABLE lt_valueset.
stru_total_list-skill_list = lt_valueset.
*Input for the Modul Dropdown
CLEAR: ls_valueset, lt_valueset.
ls_valueset-value = 'CO'.
ls_valueset-text = 'CO'.
INSERT ls_valueset INTO TABLE lt_valueset.
CLEAR: ls_valueset.
ls_valueset-value = 'CRMO'.
ls_valueset-text = 'CRMO'.
INSERT ls_valueset INTO TABLE lt_valueset.
*Input of dropdowns to internal table
stru_total_list-modul_list = lt_valueset.
INSERT stru_total_list INTO TABLE itab_total_list.
DATA: l_ref_interfacecontroller TYPE REF TO iwci_salv_wd_table,
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.
l_ref_interfacecontroller = wd_this->wd_cpifc_alv( ).
*ref to if_wd_context_node
l_ref_interfacecontroller->set_data( r_node_data = lr_node ).
DATA: l_value TYPE REF TO cl_salv_wd_config_table,
lr_column TYPE REF TO cl_salv_wd_column,
lr_column_settings TYPE REF TO if_salv_wd_column_settings,
lr_dropdown1 TYPE REF TO cl_salv_wd_uie_dropdown_by_idx,
lr_dropdown2 TYPE REF TO cl_salv_wd_uie_dropdown_by_idx,
lr_dropdown3 TYPE REF TO cl_salv_wd_uie_dropdown_by_idx,
lr_dropdown4 TYPE REF TO cl_salv_wd_uie_dropdown_by_idx,
lr_dropdown5 TYPE REF TO cl_salv_wd_uie_dropdown_by_idx,
lr_input_field TYPE REF TO cl_salv_wd_uie_input_field.
l_value = l_ref_interfacecontroller->get_model( ).
DATA: lr_table_settings TYPE REF TO if_salv_wd_table_settings,
lr_std TYPE REF TO if_salv_wd_std_functions.
*make alv editable
lr_table_settings ?= l_value.
lr_table_settings->set_read_only( abap_false ).
*Activating the functional sections of ALV-Output
lr_table_settings->set_enabled( abap_true ).
*rows should not be selectable
lr_table_settings->set_row_selectable( abap_false ).
hide buttons "check", "delete row" and "insert row"
lr_std ?= l_value.
lr_std->set_edit_check_available( abap_false ).
lr_std->set_edit_check_available( abap_false ).
lr_std->set_edit_delete_row_allowed( abap_false ).
lr_std->set_edit_insert_row_allowed( abap_false ).
create dropdown
lr_column_settings ?= l_value.
lr_column = lr_column_settings->get_column( 'PRIO' ).
CREATE OBJECT lr_dropdown1
EXPORTING
selected_key_fieldname = 'PRIO'.
lr_dropdown1->set_valueset_fieldname( value = 'PRIO_LIST' ).
lr_dropdown1->set_read_only( value = abap_false ).
lr_dropdown1->set_type( if_salv_wd_c_uie_drdn_by_index=>type_key_value ).
lr_column->set_cell_editor( lr_dropdown1 ).
create dropdown
lr_column_settings ?= l_value.
lr_column = lr_column_settings->get_column( 'STATUS' ).
CREATE OBJECT lr_dropdown2
EXPORTING
selected_key_fieldname = 'STATUS'.
lr_dropdown2->set_valueset_fieldname( value = 'STATUS_LIST' ).
lr_dropdown2->set_read_only( value = abap_false ).
lr_dropdown2->set_type( if_salv_wd_c_uie_drdn_by_index=>type_key_value ).
lr_column->set_cell_editor( lr_dropdown2 ).
create dropdown
lr_column_settings ?= l_value.
lr_column = lr_column_settings->get_column( 'THEMA' ).
CREATE OBJECT lr_input_field
EXPORTING
value_fieldname = 'THEMA'.
lr_column->set_cell_editor( lr_input_field ).
set cell editor for input field
lr_column_settings ?= l_value.
lr_column = lr_column_settings->get_column( 'KD_NR' ).
CREATE OBJECT lr_input_field
EXPORTING
value_fieldname = 'KD_NR'.
lr_column->set_cell_editor( lr_input_field ).
set cell editor for input field
lr_column_settings ?= l_value.
lr_column = lr_column_settings->get_column( 'KD_NAME' ).
CREATE OBJECT lr_input_field
EXPORTING
value_fieldname = 'KD_NAME'.
lr_column->set_cell_editor( lr_input_field ).
set cell editor for input field
lr_column_settings ?= l_value.
lr_column = lr_column_settings->get_column( 'KD_ORT' ).
CREATE OBJECT lr_input_field
EXPORTING
value_fieldname = 'KD_ORT'.
lr_column->set_cell_editor( lr_input_field ).
set cell editor for input field
lr_column_settings ?= l_value.
lr_column = lr_column_settings->get_column( 'KD_ANSPR' ).
CREATE OBJECT lr_input_field
EXPORTING
value_fieldname = 'KD_ANSPR'.
lr_column->set_cell_editor( lr_input_field ).
create dropdown
lr_column_settings ?= l_value.
lr_column = lr_column_settings->get_column( 'REMOTE' ).
CREATE OBJECT lr_dropdown3
EXPORTING
selected_key_fieldname = 'REMOTE'.
lr_dropdown3->set_valueset_fieldname( value = 'REMOTE_LIST' ).
lr_dropdown3->set_read_only( value = abap_false ).
lr_dropdown3->set_type( if_salv_wd_c_uie_drdn_by_index=>type_key_value ).
lr_column->set_cell_editor( lr_dropdown3 ).
create dropdown
lr_column_settings ?= l_value.
lr_column = lr_column_settings->get_column( 'SKILL' ).
CREATE OBJECT lr_dropdown4
EXPORTING
selected_key_fieldname = 'SKILL'.
lr_dropdown4->set_valueset_fieldname( value = 'SKILL_LIST' ).
lr_dropdown4->set_read_only( value = abap_false ).
lr_dropdown4->set_type( if_salv_wd_c_uie_drdn_by_index=>type_key_value ).
lr_column->set_cell_editor( lr_dropdown4 ).
create dropdown
lr_column_settings ?= l_value.
lr_column = lr_column_settings->get_column( 'MODUL' ).
CREATE OBJECT lr_dropdown5
EXPORTING
selected_key_fieldname = 'MODUL'.
lr_dropdown5->set_valueset_fieldname( value = 'MODUL_LIST' ).
lr_dropdown5->set_read_only( value = abap_false ).
lr_dropdown5->set_type( if_salv_wd_c_uie_drdn_by_index=>type_key_value ).
lr_column->set_cell_editor( lr_dropdown5 ).
set cell editor for input fields
lr_column_settings ?= l_value.
lr_column = lr_column_settings->get_column( 'MA_NAME' ).
CREATE OBJECT lr_input_field
EXPORTING
value_fieldname = 'MA_NAME'.
lr_column->set_cell_editor( lr_input_field ).
set cell editor for input fields
lr_column_settings ?= l_value.
lr_column = lr_column_settings->get_column( 'TEAMLEITER' ).
CREATE OBJECT lr_input_field
EXPORTING
value_fieldname = 'TEAMLEITER'.
lr_column->set_cell_editor( lr_input_field ).
*bind content of internal table
lr_node->bind_table( itab_total_list ).
ENDMETHOD.
Message was edited by:
Ingmar Kroll
Hi Ingmar,
it seems to me ok, you create here only one row though. If you want to have values of dropdowns in each row, you need to implement defining values for each row.
The difference to my code is that first I create dropdowns, there are empties, once I insert new row into Alv table, dropdowns are dynamically fulfilled.
regards,
Adam
You need to set the cell editor of the particular column to a drop down by key element and set the selectedKey property of the drop down.
Here is some sample code:
data: lr_col type ref to CL_SALV_WD_COLUMN,
lr_dropdown type ref to cl_salv_wd_uie_dropdown_by_key.
l_alv_model = l_ref_interfacecontroller->get_model( ).
l_alv_model->if_salv_wd_table_settings~set_read_only( abap_flase ).
lr_col = l_alv_model->if_salv_wd_column_settings~get_column( id = <your field name> ).
create object lr_dropdown exporting selected_key_fieldname = <your field name>.
lr_col->set_cell_editor( lr_dropdown ).
Have this code in the method where you initialize your ALV settings. Getting values into the drop down is irrespective of the ALV. That can be done in the init method of the view itself. You need to set the attribute value set of the context node attribute.
Sample code for the drop down filling would be as follows:
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( 'node' ).
lr_nodeinfo = lr_node->get_node_info( ).
<i>* itab and wa are of your internal table and work area types
</i>loop at itab into wa.
ls_valueset-value = wa-field_name.
ls_valueset-text = wa-field_name.
append ls_valueset to lt_valueset.
endloop.
lr_nodeinfo->set_attribute_value_set(
exporting
name = <attribute name>
value_set = lt_valueset
).
Hope this helps.
Regards,
Nithya
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Create an object of (CL_SALV_WD_UIE_DROPDOWN_BY_KEY) UI class for dropdown by key and use set_cell_editor method to set the cell.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.