cancel
Showing results for 
Search instead for 
Did you mean: 

Enable/disable buttons dynamically in view

Former Member
0 Kudos

Hi,

How do I enable or disable the buttons from a particular view dynamically.

Regards,

Ronita

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello,

I suggest you to bind the propertie Enabled from the button with a context attribute of type WDY_BOOLEAN . Then you can change this attribute to abap_true or abap_false depending of your needs.

You can see an example at the component WDR_TEST_EVENTS in the view BUTTON .

Regards.

Answers (2)

Answers (2)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Of the two solutions provided, I would strongly suggest that you take the approach suggested by David Pietroniro.

Both approaches are technically correct, however the recommended approach from SAP is to use the content data binding to the UI element properties whenever possible. This provides a cleaner break between the UI layers, makes your application easier to maintain and understand and also still allows for personalization/configuration of the UI.

The programatic approach that the first poster suggest, should only be used as a method of last resort when your entire UI is dynamically generated and can nto be configured via the View Layout.

IanStubbings
Active Participant
0 Kudos

I always wondered what the recommended approach was - and now I know. Ordinarily I switch between both methods but will prioritise the latter now.

Cheers

Ian

IanStubbings
Active Participant
0 Kudos

Use something similar to this in WDDOMODIFYVIEW method of the view. BTN_TEST is the id of the button.

data Lo_btn_test type ref to cl_wd_button.

lo_btn_test ?= view->get_element( 'BTN_TEST' ).

lo_btn_test->set_enabled( abap_false ).