cancel
Showing results for 
Search instead for 
Did you mean: 

Supply method to populate values dynamically in dropdown

Former Member
0 Kudos

DATA: lo_nd_ministry TYPE REF TO if_wd_context_node,

lr_node_info TYPE REF TO if_wd_context_node_info.

DATA ls_ministry TYPE wd_this->element_ministry.

DATA lv_ministry LIKE ls_ministry-ministry.

lo_nd_ministry = wd_context->get_child_node( name = 'MINISTRY' ).

lr_node_info = lo_nd_ministry->get_node_info( ).

CALL METHOD lo_nd_ministry->get_attribute

EXPORTING

  • index = USE_LEAD_SELECTION

name = 'MINISTRY'

IMPORTING

value = lv_ministry .

TYPES : BEGIN OF ty_item,

item TYPE comt_product_id,

END OF ty_item.

DATA ls_item TYPE ty_item. "wd_this->Element_item.

DATA lt_item TYPE STANDARD TABLE OF ty_item."wd_this->Element_item.

  • e.g. call a data providing FuBa

if lv_ministry = '1'.

ls_item-item = '100011'. " sample only !

APPEND ls_item TO lt_item.

elseif lv_ministry = '2'.

ls_item-item = '100012'. " sample only !

APPEND ls_item TO lt_item.

endif.

node->bind_table(

EXPORTING

new_items = lt_item

set_initial_elements = abap_true )

.

This is my code in supply function of child node ITEM which is binded to a drop down by index field, Ministry is binded to a drop down by key field, my requirement is to populate drop down by index conditionally when ministry is selected each time. I have coded the above code in supply function. The selective population of drop down ITEM is not happening. Kindly provide inputs.

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member199125
Active Contributor
0 Kudos

Hi Vishal,

Supply function will execute Only when if there are no values in a node or when values in node are cleared.

As per your requirement ,

You need to implement the code in ONSELECT method of drop down by key, then the values in populate DDBI.

If you still have the issues, please post the same .

Regards

Srinivas

former_member184578
Active Contributor
0 Kudos

Hi Vishal.,

Instead of writing the code in supply function., u write the code in onSelect for Ministry.

For Ministry DropDownByKey ., in onSelect create a method and place ur code in that method.,

hope this helps u.,

Reply if u need some more clarifications.,

Thanks & Regards

Kiran

Former Member
0 Kudos

Hello,

It works for setting data from my Onselect method. I use the following code:

DATA: lo_nd_ministry TYPE REF TO if_wd_context_node,

lo_nd_item TYPE REF TO if_wd_context_node,

lr_node_info TYPE REF TO if_wd_context_node_info.

    • data declaration

TYPES : BEGIN OF ty_item,

item TYPE comt_product_id,

END OF ty_item.

DATA ls_element TYPE REF TO if_wd_context_element.

DATA ls_item TYPE ty_item.

DATA lt_item TYPE STANDARD TABLE OF ty_item.

DATA lv_ministry TYPE comt_hierarchy_id.

lo_nd_ministry = wd_context->get_child_node( name = 'MINISTRY' ).

  • lr_node_info = lo_nd_ministry->get_node_info( ).

*

  • CALL METHOD lo_nd_ministry->get_attribute

  • EXPORTING

    • index = USE_LEAD_SELECTION

  • name = 'MINISTRY'

  • IMPORTING

  • value = lv_ministry

  • .

  • CALL METHOD lo_nd_ministry->get_element

    • EXPORTING

    • index = USE_LEAD_SELECTION

  • RECEIVING

  • node_element = ls_element

  • .

*

  • CALL METHOD ls_element->get_attribute

  • EXPORTING

  • name = 'MINISTRY'

  • IMPORTING

  • value = lv_ministry.

Data lv_index type i.

CALL METHOD lo_nd_ministry->get_lead_selection_index

receiving

index = lv_index

.

CALL METHOD lo_nd_ministry->get_attribute

EXPORTING

index = lv_index

name = 'MINISTRY'

IMPORTING

value = lv_ministry

.

IF lv_ministry = '3'.

ls_item-item = '100011'. " sample only !

APPEND ls_item TO lt_item.

ELSEIF lv_ministry = '2'.

ls_item-item = '100012'. " sample only !

APPEND ls_item TO lt_item.

ENDIF.

lo_nd_item = lo_nd_ministry->get_child_node( name = 'ITEM' ).

lr_node_info = lo_nd_item->get_node_info( ).

CALL METHOD lo_nd_item->bind_table

EXPORTING

new_items = lt_item

set_initial_elements = abap_true.

However , the strange problem is lead selection always returns the same value that is index = 1 no matter what i select and only attribute lv_ministry gets filled with value = 3 all the time.

Request your inputs.

Regards,

Vishal Bhatia

Former Member
0 Kudos

is it returning the same value because it is drop down by key having 1:1 cardinality?

former_member184578
Active Contributor
0 Kudos

Hi,

As MINISTRY is DropDownByKey, if u get index it will always return 1. so u have to use get_attribute only instead of passing index..

try .,

CALL METHOD lo_nd_ministry->get_attribute
EXPORTING
name = 'MINISTRY'
IMPORTING
value = lv_ministry.

it(lv_ministry) will give the selected value in drop down.,

hope this helps u.,

reply if u need some more clarifications.,

Thanks & Regards

Kiran

Former Member
0 Kudos

Hi Kiran,

I had dont get attribute before and that too was giving only the same value u can see the commented code i posted. Hence, I went to lead selection.

Get attribute also is not working.

Regards,

Vishal Bhatia

Former Member
0 Kudos

Hi Kiran,

I had done get attribute before and that too was giving only the same value(lv_ministry = 3); you can see the commented code I posted. Strangely lv_ministry is not my first value in dropdown infact its value number 3 in the list.

Hence, I went to lead selection.

Get attribute also is not working.

Regards,

Vishal Bhatia

former_member184578
Active Contributor
0 Kudos

Hi vishal,

Using Code Wizard just read ministry attribute., if it is dropDownByKey..

It will give the code automatically as i mentioned in my previous reply.., get_attribute() method..

It will work.,

If it is DropDownByIndex use .,

CALL METHOD lo_nd_ministry->get_lead_selection_index

receiving

index = lv_index.

I think in if condition u are checking for index.,

if lv_ministry = '3'. " is 3 index or value .. check this .. put a break point and check., what value is coming for lv_ministry..

hope this helps u.,

Thanks & Regards

Kiran

Former Member
0 Kudos

How to use the code wizard?

lv_ministry = 3 ( 3 is the value ) i have checked it with breakpoint..

Is this happening cos it is having drop down by key cardinality 1:1....

Regards,

Vishal Bhatia

Former Member
0 Kudos

Hi Kiran,

I managed to use code wizard and this is my latest code....

DATA: "lo_nd_ministry TYPE REF TO if_wd_context_node,

lo_nd_item TYPE REF TO if_wd_context_node,

lr_node_info TYPE REF TO if_wd_context_node_info.

    • data declaration

TYPES : BEGIN OF ty_item,

item TYPE comt_product_id,

END OF ty_item.

DATA ls_element TYPE REF TO if_wd_context_element.

DATA ls_item TYPE ty_item.

DATA lt_item TYPE STANDARD TABLE OF ty_item.

DATA lo_nd_ministry TYPE REF TO if_wd_context_node.

DATA lo_el_ministry TYPE REF TO if_wd_context_element.

DATA ls_ministry TYPE wd_this->element_ministry.

DATA lv_ministry LIKE ls_ministry-ministry.

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

lo_nd_ministry = wd_context->get_child_node( name = wd_this->wdctx_ministry ).

  • get element via lead selection

lo_el_ministry = lo_nd_ministry->get_element( ).

  • alternative access via index

  • lo_el_ministry = lo_nd_ministry->get_element( index = 1 ).

  • @TODO handle non existant child

  • IF lo_el_ministry IS INITIAL.

  • ENDIF.

  • get single attribute

lo_el_ministry->get_attribute(

EXPORTING

name = `MINISTRY`

IMPORTING

value = lv_ministry ).

IF lv_ministry = '3'.

ls_item-item = '100011'. " sample only !

APPEND ls_item TO lt_item.

ELSEIF lv_ministry = '2'.

ls_item-item = '100012'. " sample only !

APPEND ls_item TO lt_item.

ENDIF.

lo_nd_item = lo_nd_ministry->get_child_node( name = 'ITEM' ).

lr_node_info = lo_nd_item->get_node_info( ).

CALL METHOD lo_nd_item->bind_table

EXPORTING

new_items = lt_item

set_initial_elements = abap_true.

However it still puts the value back to 3.. What is it that is settling lv_ministry to 3 no matter what.. I have completely deleted the supply function i had used.. how is the value getting pushed to 3 no matter what I select?

Regards,

Vishal Bhatia

Former Member
0 Kudos

It works fine now both fields have to be drop down by Index.

Thanks And regards.