Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
fabio_dimicco2
Explorer

Introduction 

During my experience as a Web Dynpro for ABAP developer, I often had the doubt if it was better to use the UI element DropDownByKey or its brother DropDownByIndex.    

In these last days, I realized that I always prefer and use the DropDownByKey, it doesn’t matter if the list is inside a table, an ALV table or a simple element in a view. Clearly the index approach is also working well but I feel it as a more complex task that requires spending more time, and I’m wondering to know about your experience.

As a reference, I’m sharing below the step-by-step guide to build a DDL even without necessarily entering the fixed values ​​associated to a domain of the field.

Implementation  

First of all, I created a WDA with its Assistance Class used to encapsulate the reading of a couple of well-known tables like MARA and T134T (Material Type Descriptions).  

The idea is to display all MARA records changing the field MTART in a DropDownByKey.         

I added the component usage SALV_WD_TABLE to create an ALV table and in assistance class I have implemented two methods:   

Method FILL_TABLE    

(output parameter --> ET_MARA  Type  MARA_TAB):

METHOD fill_table.
SELECT * FROM mara INTO TABLE et_mara.
ENDMETHOD.

Method GET_TYPE_MATERIAL

(output parameter --> LT_VALUE_SET  Type WDY_KEY_VALUE_TABLE):

METHOD get_type_material.
DATA: lt_t134t            TYPE TABLE OF t134t.
*  field-symbols: <fs_t134t> type t134.
FIELD-SYMBOLS: <fs_t134>  TYPE t134t.
DATA ls_value             TYPE wdy_key_value.
SELECT * FROM t134t INTO TABLE lt_t134t WHERE spras = 'E'.
SORT lt_t134t BY mtart.
LOOP AT lt_t134t ASSIGNING <fs_t134>.
MOVE <fs_t134>-mtart TO ls_value-key.
MOVE <fs_t134>-mtbez TO ls_value-value.
APPEND ls_value TO lt_value_set.
ENDLOOP.
ENDMETHOD.

I have created a context in Component controller called ALV_TABLE with structure of MARA table.

Now in the HANDLEDEFAULT method of my WINDOWS I’m calling a component controller method where we will call the two assistance class methods:

DATA lo_nd_alv_table TYPE REF TO if_wd_context_node.
DATA lt_alv_table TYPE wd_this->elements_alv_table.
*   navigate from <CONTEXT> to <ALV_TABLE> via lead selection
lo_nd_alv_table = wd_context->get_child_node( name = wd_this->wdctx_alv_table ).
lo_nd_alv_table->get_static_attributes_table( IMPORTING table = lt_alv_table ).
lt_alv_table = wd_assist->fill_table( ).
lo_nd_alv_table->bind_table( new_items = lt_alv_table set_initial_elements = abap_true ).
DATA lr_node_info TYPE REF TO if_wd_context_node_info.
DATA lt_value_set TYPE wdy_key_value_table.
lr_node_info = lo_nd_alv_table->get_node_info( ).
*------------------------------------------------------------------*
* set sales district ddl
*------------------------------------------------------------------*
lt_value_set = wd_assist->get_type_material( ).
*--- set attribute info
lr_node_info->set_attribute_value_set( name = `MTART` value_set = lt_value_set ).

How you can see, we are binding the context ALV_TABLE calling method wd_assist->fill_table( ).The last three rows are used to set values in my drop down by key.  

And this is the result:   


7 Comments
Labels in this area