cancel
Showing results for 
Search instead for 
Did you mean: 

enable/disable button

Former Member
0 Kudos

Hi all,

I want to disable the UIELEMENT "BUTTON" at runtime...depending on whether the table in that particular view is populated or not.How can i do that.Please help..

its like if there is no data in the table, then the button responsible for action should be disabled.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

hi,

->Just Bind your button' Visible Property with Wdui_visibility Property to make it Visible / Invisible.

-> For enable/disable bind Enable Propety with Wdy_boolean .

-> When you are populating Values into your Table, Just check after that whether Table is empty or not Like : if lt_table is initial ( lt_table is internal table having data which is further binded with Node of Table).

->If table has no value , set the visibility propery as 01. ( 02 for Visible)

->For Setting Visible , you can use Code Wizard ( Control +F7).

thanx.

arjun_thakur
Active Contributor
0 Kudos

Hi Abhishek,

Create an attribute of wdy_boolean type and bind it with the enable property of the button.

Now in your code check if the internal table that is binded to the table node is not empty set the value of that attribute as 'X' else ' '.

Refer the code:



if itab[] is not initial. "itab name of internal table binded to the table

DATA:
elem_context TYPE REF TO if_wd_context_element,
stru_context TYPE if_v_main=>element_context ,
item_enable LIKE stru_context-enable.
* get element via lead selection
elem_context = wd_context->get_element( ).

CALL METHOD elem_context->set_attribute
EXPORTING
VALUE = 'X'
name = `ENABLE` 
.

else.

DATA:
elem_context TYPE REF TO if_wd_context_element,
stru_context TYPE if_v_main=>element_context ,
item_enable LIKE stru_context-enable.
* get element via lead selection
elem_context = wd_context->get_element( ).

CALL METHOD elem_context->set_attribute
EXPORTING
VALUE = ' '
name = `ENABLE`
.

endif.

Use code wizard (ctrl + F7) to set the value of the attribute.

I hope it helps.

Regards

Arjun

Edited by: Arjun Thakur on Apr 6, 2009 3:07 PM

Former Member
0 Kudos

Hi,

For the enable/disbale of the button create a context attributeBTN_ENABLE as wdy_boolean and bind the Enabled property of button to this.

IN WDDOMODIFYVIEW -

DATA: lr_button type ref to cl_wd_button,
lr_view_ele type ref to IF_WD_VIEW_ELEMENT,           " View UI element
lv_btn_enable  type wdy_boolean.                


***Hide/Unhide the SAVE button
  CALL METHOD VIEW->GET_ELEMENT
    EXPORTING
      ID      = 'BUTTON'               "Button Id
    RECEIVING
      ELEMENT = lr_view_ele.


lr_button ?= lr_view_ele.

if lt_table is initial.

* Hide the button
lv_btn_enable = abap_false. 

        CALL METHOD wd_context->SET_ATTRIBUTE
          EXPORTING
            VALUE = lv_btn_enable
            NAME  = `BTN_ENABLE`

        CALL METHOD lr_btn->SET_ENABLED
          EXPORTING
            VALUE = lv_btn_enable.

else.
* show the buttton
lv_btn_enable = abap_true. 

        CALL METHOD wd_context->SET_ATTRIBUTE
          EXPORTING
            VALUE = lv_btn_enable
            NAME  = `BTN_ENABLE`

        CALL METHOD lr_btn->SET_ENABLED
          EXPORTING
            VALUE = lv_btn_enabled.

endif.

Regards,

Lekha.