cancel
Showing results for 
Search instead for 
Did you mean: 

Binding a internal table to a attribute

Former Member
0 Kudos

Hi Experts,

I have the following requirements.

I have two drop downs - Class and subclass in web dynpro abap screen.

Based on the value selected from the class drop down, the sub class drop down should be populated.

So i cretaed an internal table and got the values of the sub class into the internal table as below.

SELECT * FROM ysrm70_s_subclas INTO CORRESPONDING FIELDS OF TABLE

lv_subclass WHERE software_class = lv_software_class.

I tried to set the attribute of the sub class drop down by looping the internal table.

loop at lv_subclass into wa_subclass.

lo_el_catalog->set_attribute(

name = `SUB_CLASS`

value = wa_subclass-sub_class ).

endloop.

The problem is i am getting only the last value in the drop down...

say i select the Class as Application Software

then i want the sub class drop down to contain the below items:

Utilities Software

Educational Software

Business Productivity Software

Cross Industry Application Software

Home And Entertainment Software

Vertical Market Application Software

right now i am only getting Vertical Market Application Software in the drop down.

pls. suggest me how this can be done

Regards,

Vinod

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Which Drop down you are using ?

Dropdown by index or dropdown by key .

Refer below code to populate the values in drop down :

DropDownBy Key :

 Here we have two things Value and a Key. Value is shown in the Drop down.

 Node used is For_Drop and Attribute is u2018Drop_Keyu2019.

method WDDOINIT .

DATA : node_info TYPE REF TO if_wd_context_node_info,

value1 TYPE wdy_key_value,

set TYPE wdy_key_value_table,

k1 type string value 'M',

v1 type string value 'MAGO',

k2 type string value 'S',

v2 type string value 'Saurav'.

*

value1-key = k1.

value1-value = v1.

APPEND value1 to set.

value1-key = k2.

value1-value = v2.

APPEND value1 to set.

node_info = wd_context->get_node_info( ).

node_info = node_info->get_child_node('FOR_DROP').

node_info->set_attribute_value_set( name = 'DROP_KEY' value_set = set ).

endmethod.

DropDown By Index:

 Value passed into internal table.

 Internal table is finally binded with the corresponding node(Context)

method WDDOINIT .

data : it_table type STANDARD TABLE OF sflight.

DATA lo_nd_cn_drpindex TYPE REF TO if_wd_context_node.

DATA lo_el_cn_drpindex TYPE REF TO if_wd_context_element.

DATA ls_cn_drpindex TYPE wd_this->element_cn_drpindex.

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

lo_nd_cn_drpindex = wd_context->get_child_node( name = wd_this->wdctx_cn_drpindex ).

select carrid from sflight into CORRESPONDING FIELDS OF TABLE it_table.

lo_nd_cn_drpindex->bind_table( it_table ).

endmethod.

I guess you are using Dropdown by Index. In that case, refer the code of Dropdown by index and populate the node with the internal table not the attribute.

Edited by: Saurav Mago on Oct 15, 2009 12:54 PM

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi

The issue is solved.

Thanks amit, Rohit and Sourav for the support. Want to give full marks to all, but i can give it to only one of you

@Sourav

I have one more query. I used Drop Down by Index here. you have mentioned how to do it for drop down by key and drop down by index.

In drop down by key cannt i bind the node with the internal table as you have mentioned in drop down by index. i mean to say will the same code that you gave for drop down by index wont work for drop down by key

Regards,

Vinod

Former Member
0 Kudos

hi Vinod,

Same code wont work for both.

In Dropdown by index, we have to fill the Node under which attribute is there and

In Dropdown by key, you can fill the attribute with the values with set_attribute_value_set method of if_wd_context_node_info.

The values can be transferred from internal table into value_set and finally value_set is binded with the Attribute.

Refer this code :

LOOP AT INTERNAL_TABLE_NAME ASSIGNING <FIELD_SYMBOLS_NAME> .

value-key = <FIELD_SYMBOLS_NAME>-FIELD_OF_TABLE." This is field of table

value-value = <FIELD_SYMBOLS_NAME>-FIELD_OF_TABLE.

INSERT value INTO TABLE value_set.

ENDLOOP

Former Member
0 Kudos

hi Sourav,

Thank you. I will try it for drop down by key also with the code you mentioned

Regards,

Vinod

Former Member
0 Kudos

hi,

Refer the Standard SAP Component : WDR_TEST_EVENTS.

Inside this , there are separate views created for various UI elements used.

Please refer this. It will be helpful.

Former Member
0 Kudos

Hi,

As i am new to web dynpro abap, I will definitely refer to it. It will be very useful for me. Thanks once again

Regards,

Vinod

Former Member
0 Kudos

loop at lv_subclass into wa_subclass.

lo_el_catalog->set_attribute(

name = `SUB_CLASS`

value = wa_subclass-sub_class ).

endloop.

u r setting the attribute "SUB_CLASS" , evry time it loops , it sets the attribute to tht value

that is why it sets the attribute to the last value of the dropdown

so for ur specific case , take the reference of the node which is binded with the dropdown

suppose node name is node , thn as replied earlier as well , u take tht node reference and bind ur internal table with the node


lo_nd_cn_node->bind_table( lv_subclass )

revert back , if u need any clarification or any assistance

I hope it wud solve ur problem

regards,

amit

Former Member
0 Kudos

The error in your code lies here :

loop at lv_subclass into wa_subclass.

lo_el_catalog->set_attribute(

name = `SUB_CLASS`

value = wa_subclass-sub_class ).

endloop.

You can't set the values of internal table to attribute. An attribute can have only one value that is the reason why you are getting last value.

Please bind the internal table with the reference of node as mentioned in my previous post.

DATA lo_nd_cn_drpindex TYPE REF TO if_wd_context_node.

lo_nd_cn_drpindex = wd_context->get_child_node( name = wd_this->wdctx_cn_drpindex ).

lo_nd_cn_drpindex->bind_table( it_table ).

<cn_drpindex> is my node under which there is an attribute which is binded to dropdown.

I hope it would help.

former_member40425
Contributor
0 Kudos

Use following code.

DATA : node_info TYPE REF TO if_wd_context_node_info.
  DATA : INTERNAL_TABLE_NAME TYPE TABLE OF TABLE_NAME.
  FIELD-SYMBOLS : <FIELD_SYMBOLS_NAME> TYPE TABLE_NAME.
  DATA : value TYPE wdy_key_value,
         value_set TYPE wdy_key_value_table.
   
  node_info = wd_context->get_node_info( ).
  node_info = node_info->get_child_node( 'NODENAME' ).


LOOP AT INTERNAL_TABLE_NAME ASSIGNING <FIELD_SYMBOLS_NAME> .
    value-key = <FIELD_SYMBOLS_NAME>-FIELD_OF_TABLE." This is field of table
    value-value = <FIELD_SYMBOLS_NAME>-FIELD_OF_TABLE.
    INSERT value INTO TABLE value_set.
  ENDLOOP.
 
  node_info->set_attribute_value_set( name = 'ATTRIBUTE_NAME' " Name of attribute
                                      value_set = value_set ).
I hope it helps.

Regards,

Rohit

Former Member
0 Kudos

bind_table use this method


 SELECT * FROM z2ts_site1 APPENDING TABLE it_site1.

  DATA: lo_nd_cn_sitedescription TYPE REF TO if_wd_context_node,
        lo_el_cn_sitedescription TYPE REF TO if_wd_context_element,
        ls_cn_sitedescription TYPE wd_this->element_cn_sitedescription.
*     navigate from <CONTEXT> to <CN_SITEDESCRIPTION> via lead selection
  lo_nd_cn_sitedescription = wd_context->get_child_node(
  name = wd_this->wdctx_cn_sitedescription ).

  lo_nd_cn_sitedescription->bind_table( it_site1 ).

here I have taken the node refernce and bind my iternal table it_site1 to context node cn_sitedescription

ur dropdown by index is binded to this node ..