cancel
Showing results for 
Search instead for 
Did you mean: 

Table column and DropDownByKey and wddomodifyview?

Former Member
0 Kudos

Hi there,

OK, forgive me for the silly question but I really need to get this right. I just wanted to do a small "proof of concept" that shows how easy it is to put a DropDownByKey into a Table Column. So I have followed and read some of the forum entries for similar things in this forum BUT still cannot find my answer....

So basically I have a small Z table that has 2 entries in it, user details and one of the fields in LAND1 showing the country key for the user. As a proof of concept I want the table in the webdynpro application to show the 2 user entries and then in the LAND1 column have a DROPDOWNBYKEY that DEFAULTS to showing what country the user belongs to, but also allows the user to CHANGE the entry.

I have everything working fine, the table is populated with the 2 users from the Z table and in the LAND1 column I have a DROPDOWNBYKEY.........but the problem is I want to know how to have the country the user is in DEFAULT in the row when the page loads. So basically the drop down is there but is BLANK to the user view, but you can then do a drop down and view all the countries.

So put another way if the user in the table has a LAND1 entry of "AT", I want the default in that table row for the drop down to be "Austria".....not just blank......

I have come from a very strong BSP background and I used to do this sort of thing in the render_cell_start method.....

Do I need to use CELL VARIANTS for this? Perhaps in the WDDOMODIFYVIEW I need to get a reference to the table column etc.....and then use the CL_WD_DROPDOWN_BY_KEY class to set the displayed value by default (like method SET_SELECTED_KEY?)

So all is fine except for the fact that I want the table row to default the drop down to the correct entry in the table....

Here is the code to populate the countries.....just for interest.....

SELECT *

INTO TABLE lt_t005t

FROM t005t

where spras = 'EN'.

SORT lt_t005t BY land1 ASCENDING.

LOOP AT lt_t005t INTO ls_t005t.

CLEAR ls_value.

ls_value-key = ls_t005t-land1.

ls_value-value = ls_t005t-landx.

APPEND ls_value TO lt_value_set[].

ENDLOOP.

lx_countries_node = wd_context->get_node_info( ).

lx_countries_node = lx_countries_node->get_child_node( name = 'COUNTRIES' ).

lx_countries_node->set_attribute_value_set( name = 'KEY'

value_set = lt_value_set ).

Any help would be greatly appreciated, thanks a million

Regards

Lynton

Accepted Solutions (1)

Accepted Solutions (1)

former_member515618
Active Participant
0 Kudos

Hi Lynton,

Before binding the data to the context node that holds data in the table. Loop at that internal table find the country code key and pass it to land1. This would default the country. Once it is dont bind the table.

Do the above in WDDOINIT method.

Regards,

Sravan

Former Member
0 Kudos

Hi there,

To be perfectly honest I still don't understand how I am to get a REFERENCE to the current table cell....

I will try code something now....

Thanks anyway

Lynton

former_member515618
Active Participant
0 Kudos

Hi Lynton,

What i understand for the attached code is that, the node that has dropdown list and the node that has the table data are different.

node USER holds the data to be displayed as table and node COUNTRY has the dropdown list of countries.

What i understand is node USER has a Country field which needs to be displayed as dropdown and when view is rendered it must have the users default country.

Please correct me if iam wrong.

To achieve the above In WDDOINIT, do the following.

1. Firstly build the dropdown list for the filed 'Country'.

METHOD dd_country.

DATA: lx_current_controller TYPE REF TO if_wd_controller,

lx_node TYPE REF TO if_wd_context_node_info,

lx_element TYPE REF TO if_wd_context_element,

ls_value TYPE wdy_key_value,

lt_value_set TYPE wdy_key_value_table,

lt_t005t TYPE TABLE OF t005t,

ls_t005t LIKE LINE OF lt_t005t.

lx_current_controller = wd_this->wd_get_api( ).

SELECT *

INTO TABLE lt_t005t

FROM t005t

where spras = 'EN'.

SORT lt_t005t BY land1 ASCENDING.

LOOP AT lt_t005t INTO ls_t005t.

CLEAR ls_value.

ls_value-key = ls_t005t-land1.

ls_value-value = ls_t005t-landx.

APPEND ls_value TO lt_value_set[].

ENDLOOP.

lx_node = wd_context->get_node_info( ).

lx_node = lx_countries_node->get_child_node( name = 'USER' ).

lx_node->set_attribute_value_set( name = '<Country_Field>'

value_set = lt_value_set ).

ENDMETHOD.

2. Secondly get the data to be displayed in the table. Say lt_user.

Loop at lt_user into ls_user.

get the default country code say ( Andorra, Key 'AD' ).

ls_user-country = 'AD'.

modify lt_user by ls_user.

endloop.

The above 2 steps would buld the dropdown and also the default country.

Hope this helps.

Regards,

Sravan Varagani

Former Member
0 Kudos

Hi there,

Thanks for you reply, much appreciated I actually only read it now because I came back onto the thread to write what my solution was.....but you were spot on, thanks.

For those who have a similar problem to what I had, here is my final piece of code that worked 100% for me...

BTW: I have ONE node now with NO sub nodes or anything, just a simple table structure .....the one field LAND1 in the structure is the one that needs the drop down....

When I look at the answer now is is very simple, thanks to all those that pushed me in the right direction

BTW: This was always meant to just be a proof of concept.....so nothing hectic application wise....

METHOD wddoinit.

  DATA: lx_current_controller TYPE REF TO if_wd_controller,
        lx_node               TYPE REF TO if_wd_context_node,
        lx_node_info     TYPE REF TO if_wd_context_node_info,
        lt_users              TYPE TABLE OF zlogos_user_test,
        ls_value              TYPE wdy_key_value,
        lt_value_set          TYPE wdy_key_value_table,
        lt_t005t              TYPE TABLE OF t005t,
        ls_t005t              LIKE LINE OF lt_t005t.

  lx_current_controller = wd_this->wd_get_api( ).

  SELECT *
    INTO TABLE lt_t005t
      FROM t005t
        WHERE spras = 'EN'.

  SORT lt_t005t BY land1 ASCENDING.

  LOOP AT lt_t005t INTO ls_t005t.
    CLEAR ls_value.
    ls_value-key   = ls_t005t-land1.
    ls_value-value = ls_t005t-landx.
    APPEND ls_value TO lt_value_set[].
  ENDLOOP.

  lx_node_info = wd_context->get_node_info( ).
  lx_node_info = lx_node_info->get_child_node( name = 'USERS' ).
  lx_node_info->set_attribute_value_set( name = 'LAND1'
                                              value_set = lt_value_set ).
  SELECT *
    INTO TABLE lt_users
      FROM zlogos_user_test.

  lx_node = wd_context->get_child_node( name = 'USERS' ).

  lx_node->bind_table(
            new_items            =  lt_users
            set_initial_elements = abap_true ).

ENDMETHOD.

Regards

Lynton

Answers (2)

Answers (2)

former_member515618
Active Participant
0 Kudos

Hi Lynton,

The above attached piece of code must be done in the WDDOINIT of the that view. If done in WDDOMODIFY, setting of the attribute valued is done upon every activity.

To set the default values:

In the hook method WDDOINIT, take the reference to the field defined as dropdown and do the following.

lx_countries_node->set_static_attribute( name = 'KEY' value = < Key > ).

Regards,

Sravan Varagani

Former Member
0 Kudos

Hi there,

Thanks, that looks more like we heading in the right direction....but forgive me for another stupid question....

You said...."take the reference to the field defined as dropdown and do the following.

lx_countries_node->set_static_attribute( name = 'KEY' value = < Key > )."

I understand what you are doing there but I'm not sure how the LOOP should look.....

Here is my code below...

METHOD wddoinit.

  DATA: lx_current_controller TYPE REF TO if_wd_controller,
        lx_node               TYPE REF TO if_wd_context_node,
        lx_countries_node     TYPE REF TO if_wd_context_node_info,
        lx_element            TYPE REF TO if_wd_context_element,
        lt_users              TYPE TABLE OF zlogos_user_test,
        ls_value              TYPE wdy_key_value,
        lt_value_set          TYPE wdy_key_value_table,
        lt_t005t              TYPE TABLE OF t005t,
        ls_t005t              LIKE LINE OF lt_t005t.

  lx_current_controller = wd_this->wd_get_api( ).

  SELECT *
    INTO TABLE lt_t005t
      FROM t005t
        where spras = 'EN'.

  SORT lt_t005t BY land1 ASCENDING.

  LOOP AT lt_t005t INTO ls_t005t.
    CLEAR ls_value.
    ls_value-key   = ls_t005t-land1.
    ls_value-value = ls_t005t-landx.
    APPEND ls_value TO lt_value_set[].
  ENDLOOP.

  lx_countries_node = wd_context->get_node_info( ).
  lx_countries_node = lx_countries_node->get_child_node( name = 'COUNTRIES' ).
  lx_countries_node->set_attribute_value_set( name = 'KEY'
                                              value_set = lt_value_set ).

  lx_node = wd_context->get_child_node( name = 'USERS' ).

  SELECT *
    INTO TABLE lt_users
      FROM zlogos_user_test.

  lx_node->bind_table(
            new_items            =  lt_users
            set_initial_elements = abap_true ).

ENDMETHOD.

I would like to do exactly what you recommended in the above code but am not sure how you would like me to LOOP through the records and get a reference to the dropdownbykey SPECIFIC COLUMN and CELL....

Would you be so kind as to add some psuedocoe to my code above to show me how to go about getting this correct?

Your help is greatly appreciated

Lynton

Former Member
0 Kudos

Hi,

Try to call method to populate countries in wddoinit method of the view and and in method when u r filling table control form z table u assign country along with uname to thier respective attr of node which u r using as datasource for table control.

Former Member
0 Kudos

Hi there,

You say I must do something when I populate the table control......well the code below binds to the table......what now?.......do you have any code that demonstrates such a thing?

SELECT *

INTO TABLE lt_users

FROM zlogos_user_test.

lx_node->bind_table(

new_items = lt_users

set_initial_elements = abap_true ).

Thanks anyway

Lynton