cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic dropdown by key values for ALV

Former Member
0 Kudos

Hello,

I have an ALV table in which one field is a dropdown by key. This automatically takes the values of its underlying domain. But I do not have fixed domain values. Instead these values are determined only at runtime. After I asked in SDN, it seems that I cannot tamper with domain values dynamically. Please suggest if you know a way to do it.

The other option would be to bind this DDByKey context attribute with a table that I can keep modifying at runtime. How to do this ?

I already tried out an option that I define a data element for this context attribute, This data element is a table type of an underlying table that I modify at runtime. But unfortunately, with this kind of a data element attached , the attribute itself is not captured with get_columns() method and hence I cannot do anything with it while configuring my ALV. Please suggest if there is another way out.

Regards

Sukanya

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Thanks Manoj !! It worked !

Former Member
0 Kudos

Hi Manoj,

Attribute value set in the ALV table can be filled dynamically in any method , even in WDDOMODIFYVIEW without problem. But then, the corresponding Filter link of this attribute in the ALV was populated with the same dynamic value set only when I had set the Attribute value set in the WDDOINIT of the view or WDDOINIT of the component controller !

Now the problem is that this attribute value set has to be updated everytime when I go out of the view and come back in. But at this point, the WDDOINIT of the view or the component controller is not called anymore !! So my purpose is not served. What to do in that case ?

Best regards

Sukanya

Edited by: Sukanya Mayuri Gogoi on Mar 24, 2009 2:58 PM

former_member402443
Contributor
0 Kudos

Hi Sukanya,

I have seen your problem that you want updated value in the dropdonbykey attribute everytime when you go out of the view and com back in.

I am also not sure, but you can try with calling your method CREATE_COLUMNS_FOR_CATEGORIES for populating the valueset values in the WDDOBEFORENAVIGATION method of the component controller.

Hopes this will helps you in solving ur problem.

Regards

Manoj Kumar

Former Member
0 Kudos

Hi Manoj,

Thanks so much for this detailed answer. I have done the steps exactly as you have mentioned still its not working for some reason, that is , I am not getting the dropdown in the Filter of ALV. Is there any specific point that I need to keep in mind ? Am still trying..

Best regards

Sukanya

former_member402443
Contributor
0 Kudos

Hi Sukanya,

Can you pls send your code, so that i can see whether there is any problem in the code or smthng else.

Because the above code is working perfectly for me.

Regard

Manoj Kumar

Former Member
0 Kudos

Hi Manoj,

I have created and filled my context node with data, then binded it with the ALV component table. Data is also displayed in the ALV.

Then I write a method COFIGURE_ALV() on my view to configure all the columns and call this method in the WDDOMODIFY of my view.

COFIGURE_ALV()

lt_columns = lo_col_settings->get_columns( ).

LOOP AT lt_columns INTO ls_column.

CASE ls_column-id .

WHEN ............

WHEN 'CONTEXT_STATUS'.

CREATE OBJECT lo_drdn_by_key

EXPORTING

selected_key_fieldname = ls_column-id.

lo_header = ls_column-r_column->create_header( ).

lo_header->set_text( 'Status' ).

lo_drdn_by_key->set_read_only_fieldname( 'CONTEXT_STATUS_READONLY' ).

  • lo_drdn_by_key->set_read_only( ).

ls_column-r_column->set_width( '80px' ).

ls_column-r_column->set_cell_editor( lo_drdn_by_key ).

WHEN 'CAT_VALUE_I'.

CREATE OBJECT lo_drdn_by_key

EXPORTING

selected_key_fieldname = ls_column-id.

lo_header = ls_column-r_column->create_header( ).

lo_header->set_text( 'CAT_VALUE_I_HEADER' ).

lo_drdn_by_key->set_read_only_fieldname( 'CONTEXT_STATUS_READONLY' ).

  • lo_drdn_by_key->set_read_only( ).

ls_column-r_column->set_width( '80px' ).

  • ls_column-r_column->if_salv_wd_column_service_ref~set_filter_fieldname( 'CAT_VALUE_I' ).

  • lo_drdn_by_key->set_key_visible( EXPORTING value = abap_true ).

ls_column-r_column->set_cell_editor( lo_drdn_by_key ).

ENDCASE.

ENDLOOP.

Now for this attribute 'CAT_VALUE_I', I populate my dynamic data in the following method:

CREATE_COLUMNS_FOR_CATEGORIES()

DATA lt_cati_value_set TYPE wdr_context_attr_value_list.

DATA ls_cati_value TYPE wdr_context_attr_value.

"Bind the table of pb items to the context-node

lo_nd_pb_item_list = me->mo_context->get_child_node( 'PB_ITEM_LIST' ).

lo_nd_pb_item_list_info = lo_nd_pb_item_list->get_node_info( ).

  • Create Attribute for cat values I

LOOP AT lo_categories->mt_def_categoryi ASSIGNING <fs_cat_val> WHERE pbi_c_value_id IS NOT INITIAL.

CLEAR ls_cati_value.

ls_cati_value-value = <fs_cat_val>-short_name.

ls_cati_value-text = <fs_cat_val>-short_name.

INSERT ls_cati_value INTO TABLE lt_cati_value_set.

ENDLOOP.

lo_nd_pb_item_list_info->set_attribute_value_set( name = 'CAT_VALUE_I'

value_set = lt_cati_value_set ).

Hence the dynamic values are binded to this attribute and shown as DDBykey in my ALV table. But when I click on Filter link on the ALV, still I dont get the same Dropdown for this attribute !

In the WDDOMODIFY of my view , I first call configure_alv() and then create_columns_for_categories().

Now what to do ?

Former Member
0 Kudos

Hi Manoj,

Thanks for this. I had tried it out and then saw that I have done the same which you have suggested .

Now my next problem is that once I have created this attribute and set a value attribute set dynamically, when I click on the 'Filter' link on the ALV, it does not take any values for this attribute field because I didnot and cannot specify any fixed domain values for this attribute. If I want this filter to behave like a dropdown and take the same value set as my attribute value set, what do I have to do ?

Thanks a lot.

Sukanya.

former_member402443
Contributor
0 Kudos

Hi Sukanya,

Regarding your problem that when you click on the 'Filter' link on the ALV, it does not take any values for the dropdownbykey attribute field and If you want this filter to behave like a dropdown and take the same value set as in your attribute value set.

For this you don't need to write any logic for filter to behave like a dropdown for the dropdownbykey column.

Its working fine for me .

I will explain you. Just follow these simple steps.

1. Create a node say NODE with attribute - COL1, COL2,COL3 OF TYPE STRING in the component controller. and set the cardinality of the node to 0..n.

2. Take a alv component usage and map the DATA NODE of the alv component usage to the component controller NODE.

3. Now create a method Configure_alv in the component controller and copy the below mention code.

METHOD Configure_alv .

*-----Declerations For Component Usage

DATA : lo_cmp_usage_cnt_info TYPE REF TO if_wd_component_usage.

  • data declaration for column settings

DATA : lr_column_settings TYPE REF TO if_salv_wd_column_settings,

lr_col_header TYPE REF TO cl_salv_wd_column_header,

lt_columns TYPE salv_wd_t_column_ref,

ls_column TYPE salv_wd_s_column_ref,

lr_std_func TYPE REF TO cl_salv_wd_function_std.

  • data declaration for table settings

DATA : lr_salv_wd_table_ctr TYPE REF TO iwci_salv_wd_table,

lr_table_settings_ctr TYPE REF TO if_salv_wd_table_settings,

lr_header_ctr TYPE REF TO cl_salv_wd_header,

  • Howto use cell variant

l_cv TYPE REF TO cl_salv_wd_cv_standard.

  • Variables for drop-down and inpufield reference

DATA : lr_link_to_action TYPE REF TO cl_salv_wd_uie_link_to_action,

lr_input_field TYPE REF TO cl_salv_wd_uie_input_field,

lr_drdn_by_key TYPE REF TO cl_salv_wd_uie_dropdown_by_key,

l_header TYPE string.

*-----This is comments

-----this wd_this->alv_config_table is declare in the attribute section of component controller of type ref to CL_SALV_WD_CONFIG_TABLE

*-----Create Component

lo_cmp_usage_cnt_info = wd_this->wd_cpuse_alv_usage( ).

IF lo_cmp_usage_cnt_info->has_active_component( ) IS INITIAL.

lo_cmp_usage_cnt_info->create_component( ).

ENDIF.

    • get ALV Component <CONTRACT_DETAILS>*

lr_salv_wd_table_ctr = wd_this->wd_cpifc_alv_usage( ).

wd_this->alv_config_table = lr_salv_wd_table_ctr->get_model( ).

  • set visible row count

lr_table_settings_ctr ?= wd_this->alv_config_table.

lr_table_settings_ctr->set_visible_row_count( '5' ).

lr_table_settings_ctr->set_read_only( abap_false ).

  • lr_table_settings_ctr->set_grid_mode( ).

lr_table_settings_ctr->set_width(

EXPORTING

value = '980PX' ).

wd_this->alv_config_table->if_salv_wd_table_settings~set_data_check( if_salv_wd_c_table_settings=>data_check_on_cell_event ).

wd_this->alv_config_table->if_salv_wd_std_functions~set_pdf_allowed( abap_false ).

wd_this->alv_config_table->if_salv_wd_std_functions~set_view_list_allowed( abap_false ).

wd_this->alv_config_table->if_salv_wd_std_functions~set_edit_insert_row_allowed( abap_false ).

wd_this->alv_config_table->if_salv_wd_std_functions~set_edit_delete_row_allowed( abap_true ).

wd_this->alv_config_table->if_salv_wd_std_functions~set_export_allowed( abap_false ).

wd_this->alv_config_table->if_salv_wd_std_functions~set_edit_check_available( abap_false ).

DATA : lv_str TYPE string.

CREATE OBJECT lr_std_func

EXPORTING

id = lv_str.

.

lr_std_func->set_alignment( if_salv_wd_c_function_settings=>align_left ).

CLEAR: l_header.

l_header = 'Employee Details'.

lr_header_ctr = lr_table_settings_ctr->get_header( ).

lr_header_ctr->set_text( l_header ).

  • set text header for Columns.

CLEAR: l_header,lt_columns.

lr_column_settings ?= wd_this->alv_config_table.

lt_columns = lr_column_settings->get_columns( ).

LOOP AT lt_columns INTO ls_column.

CASE ls_column-id.

WHEN 'COL1'.

  • get header details

lr_col_header = ls_column-r_column->get_header( ).

  • disable DDIC field label

CALL METHOD lr_col_header->set_prop_ddic_binding_field

EXPORTING

property = if_salv_wd_c_ddic_binding=>bind_prop_text

value = if_salv_wd_c_ddic_binding=>ddic_bind_none.

  • set user defined column header

l_header = 'Column 1'.

lr_col_header->set_text( l_header ).

WHEN 'COL2'.

  • get header details

lr_col_header = ls_column-r_column->get_header( ).

  • disable DDIC field label

CALL METHOD lr_col_header->set_prop_ddic_binding_field

EXPORTING

property = if_salv_wd_c_ddic_binding=>bind_prop_text

value = if_salv_wd_c_ddic_binding=>ddic_bind_none.

  • set user defined column header

l_header = 'Column 2'.

lr_col_header->set_text( l_header ).

CREATE OBJECT lr_drdn_by_key

EXPORTING

selected_key_fieldname = ls_column-id.

ls_column-r_column->set_cell_editor( lr_drdn_by_key ).

lr_drdn_by_key->set_key_visible(

EXPORTING

value = abap_true ).

WHEN 'COL3'.

  • get header details

lr_col_header = ls_column-r_column->get_header( ).

  • disable DDIC field label

CALL METHOD lr_col_header->set_prop_ddic_binding_field

EXPORTING

property = if_salv_wd_c_ddic_binding=>bind_prop_text

value = if_salv_wd_c_ddic_binding=>ddic_bind_none.

  • set user defined column header

l_header = 'Column 3'.

lr_col_header->set_text( l_header ).

WHEN OTHERS.

ENDCASE.

CLEAR: l_header,ls_column.

ENDLOOP.

ENDMETHOD.

4. Now create a method FILL_TABLE in the component controller for some dummy data Like given below

and call this in the WDDOINIT method of the component controller before the Configure_alv method.

METHOD fill_table .

DATA lo_nd_node TYPE REF TO if_wd_context_node.

DATA lo_el_node TYPE REF TO if_wd_context_element.

DATA lt_node TYPE wd_this->elements_node.

DATA ls_node LIKE LINE OF lt_node.

  • navigate from <CONTEXT> to <NODE> via lead selection

lo_nd_node = wd_context->get_child_node( name = wd_this->wdctx_node ).

  • @TODO handle not set lead selection

IF lo_nd_node IS INITIAL.

ENDIF.

  • get all declared attributes

lo_nd_node->get_static_attributes_table(

IMPORTING

table = lt_node ).

CLEAR ls_node.

ls_node-col1 = 'Col1'.

ls_node-col3 = 'Col3'.

APPEND ls_node TO lt_node.

CLEAR ls_node.

ls_node-col1 = 'Col1'.

ls_node-col3 = 'Col3'.

APPEND ls_node TO lt_node.

CLEAR ls_node.

ls_node-col1 = 'Col1'.

ls_node-col3 = 'Col3'.

APPEND ls_node TO lt_node.

lo_nd_node->bind_table(

EXPORTING

new_items = lt_node

).

ENDMETHOD.

5. Also copy the below mention code for populating some dummy data for the dropdownbykey attribute in the WDDOINIT method of the view.

method wddoinit.

DATA lo_nd_node TYPE REF TO if_wd_context_node.

DATA lo_el_node TYPE REF TO if_wd_context_element.

DATA ls_node TYPE wd_this->element_node.

DATA lv_col2 LIKE ls_node-col2.

DATA lr_nodeinfo TYPE REF TO if_wd_context_node_info.

  • navigate from <CONTEXT> to <NODE> via lead selection

lo_nd_node = wd_context->get_child_node( name = wd_this->wdctx_node ).

lr_nodeinfo = lo_nd_node->get_node_info( ).

  • @TODO handle not set lead selection

IF lo_nd_node IS INITIAL.

ENDIF.

  • get element via lead selection

lo_el_node = lo_nd_node->get_element( ).

  • @TODO handle not set lead selection

IF lo_el_node IS INITIAL.

ENDIF.

  • get single attribute

lo_el_node->get_attribute(

EXPORTING

name = `COL2`

IMPORTING

value = lv_col2 ).

  • Data declaration for drop-down list value

DATA : ls_value_set TYPE wdy_key_value,

lt_value_set TYPE wdy_key_value_table,

ls_land TYPE t005t,

lt_land TYPE TABLE OF t005t.

SELECT * FROM t005t

INTO TABLE lt_land UP TO 10 ROWS

WHERE spras = sy-langu.

LOOP AT lt_land INTO ls_land.

CLEAR ls_value_set.

ls_value_set-key = ls_land-land1.

ls_value_set-value = ls_land-landx.

INSERT ls_value_set INTO TABLE lt_value_set.

ENDLOOP.

lr_nodeinfo->set_attribute_value_set(

EXPORTING

name = `COL2`

value_set = lt_value_set ).

endmethod.

6. Now embed the view in the window and also the alv table in the view container that you have taken in your view for the alv component.

7. Create application for the component and run and after that when you select the filter link you will see the dropdown will appear for the second column COL2 with all tha values that you have set for the attribute dynamically.

Hopes this will helps you.

Regard

Manoj Kumar

former_member402443
Contributor
0 Kudos

Hi Sukanya,

Regarding your problem to dynamically populate values in the dropdownbykey for alv.

If am not wrong

1 .You hv create a node for alv to display the data and within this you hv create a attribute that contain the dropdownbykey values.

2. You hv set the cardinality of node to 0..n.

3. You also hv mapped the context node to the data node of the alv component usage.

To Fill the values in the attribute that mapped to the dropdownbykey for alv , Please check the code below.

In this method i am populating the bank account in the dropdownbykey of the alv grid. In this method i am calling a FM for getting the bank account info and then binding to the attribute .

You can also select the data from the database table directly.

You can call this method where you want to populate the data in the alv grid.

METHOD fill_bank_account_info .

  • Data declaration for payment table node info

DATA : lo_nd_payment_table TYPE REF TO if_wd_context_node,

lo_el_payment_table TYPE REF TO if_wd_context_element,

lr_nodeinfo TYPE REF TO if_wd_context_node_info,

ls_payment_table TYPE wd_this->element_payment_table.

  • Data declaration for Internal Table/Workarea

DATA : lt_accountdetail TYPE TABLE OF /dmpui/db_accont_type,

ls_accountdetail TYPE /dmpui/db_accont_type,

ls_value_set TYPE wdy_key_value,

lt_value_set TYPE wdy_key_value_table.

  • navigate from <CONTEXT> to <PAYMENT_TABLE> via lead selection

lo_nd_payment_table = wd_context->get_child_node( name = wd_this->wdctx_payment_table ).

lr_nodeinfo = lo_nd_payment_table->get_node_info( ).

  • Calling the BAPI for getting the bank/Country/Account Information

CALL FUNCTION '/DMPUI/DB_BANK_ACCOUNT_INFO'

EXPORTING

iv_proposal = wd_this->lv_proposal

iv_bpnumber = wd_comp_controller->mv_bp_number

iv_medium = im_medium

iv_screen = c_screen

TABLES

et_accountdetail = lt_accountdetail.

LOOP AT lt_accountdetail INTO ls_accountdetail.

    • Concatenating the values into a variable*

CONCATENATE ls_accountdetail-bankland

ls_accountdetail-bankkey

ls_accountdetail-acnum_ext

INTO lv_account RESPECTING BLANKS.

ls_value_set-key = lv_account.

ls_value_set-value = lv_account.

    • Inserting the values to a internal table*

INSERT ls_value_set INTO TABLE lt_value_set.

CLEAR ls_value_set.

ENDLOOP.

  • setting the attributes for the value set

lr_nodeinfo->set_attribute_value_set(

EXPORTING

name = `ACCOUNT_NUMBER`

value_set = lt_value_set ).

ENDMETHOD.

After this you can configure your alv . For this see the below code.

METHOD configure_alv .

  • data declaration for column settings

DATA : lr_column_settings TYPE REF TO if_salv_wd_column_settings,

lr_col_header TYPE REF TO cl_salv_wd_column_header,

lt_columns TYPE salv_wd_t_column_ref,

ls_column TYPE salv_wd_s_column_ref.

  • data declaration for table settings

DATA : lr_salv_wd_table_ctr TYPE REF TO iwci_salv_wd_table,

lr_table_settings_ctr TYPE REF TO if_salv_wd_table_settings,

lr_header_ctr TYPE REF TO cl_salv_wd_header.

  • Variables for drop-down and inpufield reference

DATA : lr_drdn_by_key TYPE REF TO cl_salv_wd_uie_dropdown_by_key,

lr_input_field TYPE REF TO cl_salv_wd_uie_input_field,

l_header TYPE string.

  • get ALV Component <CONTRACT_DETAILS>

lr_salv_wd_table_ctr = wd_this->wd_cpifc_payment_detail( ).

wd_this->alv_config_table = lr_salv_wd_table_ctr->get_model( ).

lr_column_settings ?= wd_this->alv_config_table.

lt_columns = lr_column_settings->get_columns( ).

LOOP AT lt_columns INTO ls_column.

CASE ls_column-id.

WHEN 'PAYMENT_METHOD'.

  • get header details

lr_col_header = ls_column-r_column->get_header( ).

  • disable DDIC field label

CALL METHOD lr_col_header->set_prop_ddic_binding_field

EXPORTING

property = if_salv_wd_c_ddic_binding=>bind_prop_text

value = if_salv_wd_c_ddic_binding=>ddic_bind_none.

  • set user defined column header

l_header = wd_assist->if_wd_component_assistance~get_text( key = '020' ).

lr_col_header->set_text( l_header ).

CREATE OBJECT lr_drdn_by_key

EXPORTING

selected_key_fieldname = ls_column-id.

ls_column-r_column->set_cell_editor( lr_drdn_by_key ).

lr_drdn_by_key->set_key_visible(

EXPORTING

value = abap_true ).

WHEN OTHERS.

ENDCASE.

CLEAR: l_header,ls_column.

ENDLOOP.

endmethod.

Hopes this will helps you.

Regard

Manoj Kumar