cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic creation of menus...

Former Member
0 Kudos

Hi,

How to create menus dynamically?

Can anyone provide me the code to create menus dynamically.

Regards,

Srinu

Accepted Solutions (0)

Answers (3)

Answers (3)

uday_gubbala2
Active Contributor
0 Kudos

Coding to create the MenuItem dynamically:

method WDDOMODIFYVIEW .
  check first_time = abap_true.
 
  data: lr_menu type ref to cl_wd_menu,
        lr_menu_item type ref to cl_wd_menu_action_item,
        lv_str type string,
        lt_carrid type standard table of sflight-carrid,
        wa_carrid type sflight-carrid.
 
*** Fetch few carrid values which would be used as texts while creating menu items
  select distinct carrid from sflight up to 5 rows into table lt_carrid.
 
*** Get the reference of the Menu created at design time. We need to add menu items to this element
  lr_menu ?= view->get_element( id = 'MENU1' ).
 
  loop at lt_carrid into wa_carrid.
*** Menu item expects the text to be passed to it in a string variable. So swap the variables...
    lv_str = wa_carrid.
*** Create a new instance of the MenuActionItem
    lr_menu_item = cl_wd_menu_action_item=>new_menu_action_item( ).
*** Add text to the created MenuActionItem
    lr_menu_item->set_text( value = lv_str ).
***  Finally associate the created MenuActionItem with the layout's Menu element
    lr_menu->add_item( exporting index     = sy-index
                                 the_item  = lr_menu_item ).
  endloop.
endmethod.

So now when I test my component the all textviews in the CARRID column would be having 5 menuitems created with the values as in internal table lt_carrid.

uday_gubbala2
Active Contributor
0 Kudos

Coding to fill my table with data (supply function method):

method SUPPLY_DATA .
  data: lt_data type wd_this->elements_sflight.
 
  select carrid
         connid
         fldate
         price from sflight into table lt_data.
  node->bind_table( new_items = lt_data ).
endmethod.

uday_gubbala2
Active Contributor
0 Kudos

Hi Srinu,

Hi Kumar,

Just created a dumb example to try paste in here. I am displaying data from SFLIGHT in my table. I want to create MenuItem's dynamically for my first columns textview. (i.e., CARRID) I have created a Menu with id "MENU1" for the textview T1_CARRID. So now I need to create corresponding MenuItems for this menu dynamically. Below is the coding with which I am filling my table (done using a supply function method) & my coding for creating the MenuItems.

Regards,

Uday