Skip to Content

Dynamic programming - dynamic creation of a toolbar within a tray

Hi experts,

please forgive the nooby question but cannot find any reference to the task on the SCN.

Shortly; I used to manage dynamic creation of UIElements in WDDOMODIFYVIEW method of a view. In particular, we created a Tray object in this way:

- in "layout" section we created a Transparent container, which is further split into two subContainers (left & right) in order to manage contents on two columns.

- in WDDOMODIFYVIEW, we used this sketch of code:

* Create Tray

       lr_context_elem   =  wd_context->get_element( ).

       lo_container_root ?=  view->get_root_element( ).

*Creation of the Dynamic TRAY

       create object lo_tray


           iv_title           = lv_tray_text

           iv_component_id    = lc_container_bd_cuf "that's the name of the TransparentContainer defined above

           ir_rootuielement   = lo_container_root

           ir_context_element = lr_context_elem

           iv_type            = /sapsrm/ch_wd_ui_elements=>switch_tray

           iv_max_action      = lc_maximize_bd

           iv_min_action      = lc_minimize_bd

           iv_toggle_action   = lc_toggle_bd.

       wd_this->mr_tray_cuf_bd = lo_tray.

Now, my requirement is to add a simple toolbar to the tray. This toolbar should be "binded" to the tray itself and will contain two buttons (say, "Edit" and "Save"). This could be a straightforward task if done in Layout section as a static design operation, but creating and adding a toolbar in dynamic programming is a bit more challenging.

Could anyone help me with suggestions/code examples ?

Thanks you in advance.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Mar 21, 2013 at 10:02 AM

    Ok, I'm stucked as per my requirement, I should create a toolbar with two buttons and bind them to the tray.

    Creating a toolbar with two buttons seems to be quite straightforward.


                 bd_toolbutton_edit TYPE REF TO cl_wd_toolbar_button,

                 bd_toolbutton_save TYPE REF TO cl_wd_toolbar_button.

            bd_toolbar =  cl_wd_toolbar=>new_toolbar( ).

            bd_toolbutton_edit = cl_wd_toolbar_button=>new_toolbar_button( text = 'EDIT' on_action = 'EDIT_BD' ).

            bd_toolbutton_save = cl_wd_toolbar_button=>new_toolbar_button( text = 'SAVE' on_action = 'SAVE_BD' ).

            bd_toolbar->add_toolbar_item( bd_toolbutton_edit ).

            bd_toolbar->add_toolbar_item( bd_toolbutton_save ).

    Now the problem is: how to bind the toolbar to the tray?

    It seems quite easy as the class CL_WD_TRAY offers a method, SET_TOOLBAR.

    Unfortunately, as far as I can see, the existing code (posted above) creates an object LO_TRAY which is declared as:

    data : lo_tray                 type ref to /sapsrm/ch_wd_ui_elements.

    The class /SAPSRM/CH_WD_UI_ELEMENTS does not offer any method to attach a toolbar and casting explictly (my_tray ?= lo_tray) results in a runtime dump.

    Do you have any suggestions on the task?


    Add comment
    10|10000 characters needed characters exceeded

    • Thanks Samuli,

      I solved by adding the Toolbar in the right placement into a TransparentContainer which contains also the Tray.
      I did it via dynamic programming and the solution seems to fit my requirement.

      Thanks again for the support! 😊