cancel
Showing results for 
Search instead for 
Did you mean: 

Get object-reference of UI element

alberto_colonna
Associate
Associate
0 Kudos
176

Hello,

Is there a method which gives me the object-reference of an UI-element when I know the ID of this element?

For example I have a button with the ID "bt_ok". Now I want to have the reference of this object, but I only know it's ID.

Is there a possibility to do this?

Best regards & Thanks

Accepted Solutions (0)

Answers (1)

Answers (1)

alejandro_bindi
Active Contributor
0 Kudos

Yes, but you can only do this inside method WDDOMODIFYVIEW. Here's a sample code:


* This ID belongs to a Transparent Container UI element
  CONSTANTS:
    lc_header_id        TYPE string VALUE 'TCN_HEADER'.
  DATA:
    lr_view_elem        TYPE REF TO cl_wd_uielement.

*   You cast to generic cl_wd_uielement class since setting enabled property is a common operation. 
*   In case you need to do something more specific you would cast to the UI element's specific subclass
    lr_view_elem ?= view->get_element( id = lc_header_id ).
    lr_view_elem->set_enabled( value = abap_true ).

Regards

former_member189058
Active Contributor
0 Kudos

Hi,

Adding to Alejandro Bindi's code

you can even code it in any other method if you have the view instance available.

create a context attribute of type ref to if_wd_view, say view_01.

In do modify,

Save view reference in the attribute as follows:



wd_context->set_attribute(
  exporting
     name = `view_01`
     value = view ).

alejandro_bindi
Active Contributor
0 Kudos

Yes Reema, that may work, but it's not a good practice. There's a reason the view reference is available in WDDOMODIFYVIEW only.

Besides, in case you still want to do this, it's preferable to save the if_wd_view view reference as a controller attribute rather than saving it in the context, because it's faster and easily accesible.

Edited by: Alejandro Bindi on Sep 19, 2008 7:16 PM