Skip to Content
avatar image
Former Member

Get object-reference of UI element

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Sep 19, 2008 at 03:43 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • 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