cancel
Showing results for 
Search instead for 
Did you mean: 

ALV with dropdown in column and other questions

Former Member
0 Kudos

hi,

I created an editable alv with configuration model via external context mapping.

now I have a column which contains strings and my aim is to show this whole column as a dropdownlist. the possible values of this dropdown are fetched in a database table at runtime and each cell in this column got its own selected value in this dropdownlist.

changes of the selected values should be written in the database table in a later step.

1. what changes do I have to do?

should I remove my external mapping concerning the alv and use the setData method? or what is the easiest way to get my dropdownlist in this column instead of normal text (string) ?

2. should I choose dropdownbykey or by index?

I suppose I have to change the context when changing the selected value in the dropdownlist and the read out the changed context element and update my database table?

3. how could I access rows (= tuples) in an alv?

4. how can I avoid that a row could be deleted, inserted or added with the normal functions of the alv?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Thorsten,

If the possible list of values in the dropdown is different for each row, you need a drop down by index. Else this can be done using a dropdown by key itself.

The only change that you need to do is create a cell editor of type dropdown for that particular column and configure your ALV model.

The sample code for changing the cell editor would be:

l_alv_model = l_ref_interfacecontroller->get_model( ).

DATA:

lr_column_settings TYPE REF TO if_salv_wd_column_settings,

lr_column type ref to CL_SALV_WD_COLUMN.

lr_dropdown TYPE REF TO CL_SALV_WD_UIE_DROPDOWN_BY_KEY.

lr_column_settings ?= l_alv_model.

lr_column = lr_column_settings->get_column( <column name> ).

CREATE OBJECT lr_dropdown EXPORTING

SELECTED_KEY_FIELDNAME= '<fieldname>'

lr_column->set_cell_editor( lr_dropdown ).

Here, you can substitute the field name with your field name that has to be displayed as a dropdown.

The dropdown list can be populated in the wddoinit method by attaching a value set to the attribute in the context node info. Everything else will be like you do in a normal table. You can so a get_static_attributes of your elements and persist in tables. Whenever you change the selected value, the context will be updated immediately. You can have a user defined function like 'Save' or something where you can just read the context and process the data.

If you do not want to display any of the normal functions, you can do the following:

data: lt_functions type SALV_WD_T_FUNCTION_STD_REF,

ls_function type SALV_WD_s_FUNCTION_STD_REF.

lt_functions = l_alv_model->if_salv_wd_function_settings~get_functions_std( ).

loop at lt_functions into ls_function.

ls_function-r_function->set_visible( CL_WD_UIELEMENT=>E_VISIBLE-NONE ).

endloop.

The above code will hide all the standard functions. If you want to hide specific ones, do a get_function(id) and set_visible.

Hope this helps.

Regards

Nithya

Former Member
0 Kudos

thanks Nithya S,

I have further questions concerning your proposal.

1. what do you mean with the "fieldname"? the name of the column?

2. should I first create the elements of the context (then the column for the dropdwon is type string) and then create the cell editor or otherwise?

3. how do I have to attach the value set to the attribute in detail? and yes I got the same possible list of values for each dropdown in the column and so I have to use dropdownbykey.

Former Member
0 Kudos

Fieldname refers to the context attribute name inside your context node that is bound to the ALV. You need to create the context node first, and one of its attributes will be a dropdown. This is the node that you will be passing to the set_data method. The cell editor has to be defined only after the context node is available and mapped to the ALV model.

To attach a value set to context attributes, see this . It is the same way that you attach values to a dropdown normally, outside an ALV.

Regards

Nithya

Former Member
0 Kudos

>>>This is the node that you will be passing to the set_data method

I have external mapping at the moment...so you mean I have to delete this external mapping and do the context mapping manually with the set_data method?

Former Member
0 Kudos

Doesnt matter, it should work either way. I generally use the set_data method and have given it.

Regards

Nithya

Former Member
0 Kudos

thank you again for your answer...I got another problem now.

I have a usage of the alv only in a view and not in my component controller.

this view mapps to the context of the component controller.

I create the elements of the context via bindStructure in a method of my component controller and there I have to create the dropdown but I can´t do this because this should happen in my alv-init method in the wddoinit of my view.

Former Member
0 Kudos

You dont have to create the dropdown where you create your elements. You can have it in the wddoinit of your view and it should work fine. This should be done where you are configuring the ALV, not where you are populating the context node. You can do bind_elements in your comp controller method. But you will be initializing the ALV in the view, and put this code there.

Regards

Nithya

Former Member
0 Kudos

You dont have to create the dropdown where you create your elements. You can have it in the wddoinit of your view and it should work fine. This should be done where you are configuring the ALV, not where you are populating the context node. You can do bind_elements in your comp controller method. But you will be initializing the ALV in the view, and put this code there.

>>>

ok I changed the type of the attribute for the dropdown in the context of the component controller from string to cl_salv_wd_uie_dropdown_by_key and so when I want to pass the value to the structure before I bind the element to the node it´s necessary to have the dropdown.

I think I was wrong.

You mean I should leave the type of the context attribut as a string and then in the alv-init method of my view create the cell editor and dropdown?

and where I have to bind the value set to the attribute and how? I suppose it only could happen when I create the context elements in the component controller?

Former Member
0 Kudos

Hi Thorsten,

Yes, you need to leave the attribute type as string, and create only a cell editor as a reference of type cl_salv_wd_uie_dropdown_by_key.

I think you are confused between the data binding to the context node and UI element binding. They do not need to be interlinked. Adding a value set to the context node is to be done separately. That has no relevance on what UI element you use. If you use a drop down, it will come in the drop down. But you can use the value set like a check table even with an input field. So what UI element you use does not matter.

What you do in the ALV configuration is only manipulating the display. Here you have nothing to do with the actual data. You only say that in this model which takes the data from this node, the cell editor needs to be a drop down for one field. The default cell editor will be input field or textview, and you are changing it to a dropdown. And as you know, in web dynpro, each UI element has its own class and you are just creating a reference to that class here. The parameter SELECTED_KEY_FIELDNAME is the binding that you do of the selectedKey attribute in a normal dropdown. So you specify which attribute is going to be selected using the dropdown.

So you will be working on your context node and node info references for setting the values. And work on the ALV configuration model to get the dropdown. Even if you change the ALV to a normal table and set this field as a dropdown, the list of values will still hold good, as they are independent of UI element.

I hope I have clarified things, get back if you have any issues.

Regards

Nithya

Answers (1)

Answers (1)

Former Member
0 Kudos

thanks Nithya I got my dropdown in the column now and it was a pitfall for me to recognize that the valueset-value is linked for the dropdown to the attribute value. I am opening another thread for another problem now