cancel
Showing results for 
Search instead for 
Did you mean: 

How to enable /disable the row in ALV?

Former Member
0 Kudos

Hi Experts,

I have gone through some threads on this but I did not find useful to my requirement.

My requirement is:

Consider two columns : one is set delete column (a button) and another editable field.

When the user presses on set delete button. The editable field should be disabled and it should be enabled whenever the user presses the button again.

Kindly let me know the solution.

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hallo Vineeth,

I am surprised to see that you couldnt find solution for your requirement. This has been discussed several times.

For your problem.

1.)you can add a attribute to your node which is binded to the alv data node.

For example :

col-readonly type wdy_boolean.

I assume you already have a method like configure_alv.

2)Just bind the inputfield read_only property to the newly added attribute.

lr_input_field->set_read_only_fieldname( 'COL_READONLY' ).

3)On delete button event handler, set the attribute value as you desired. You can use code generator (ctrl + f7 ) to generate getter and setter for your attribute.

PS: you can supply a default valuein the context to start the input field enabled or disabled.

Answers (3)

Answers (3)

gill367
Active Contributor
0 Kudos

Hi,

As i am also new to web dynpro abap. I found it a gud thing to learn about ALV grid.

So, I tried doing it like that and found that its not at all difficult.

Here is the procedure that i followed.

1. Create a context node with two attribute from any table structure and one attribute of type wdy_boolean for controlling the

enable property of input field.

2. i used the supply function to fill the node. Here is the code for the same.

data lt_dealer type wd_this->Elements_zdealer.             "My node name is zdealer
 DATA ls_dealer LIKE LINE OF lt_dealer.
select * from zdealer into corresponding fields of table lt_dealer.

loop at lt_dealer into ls_dealer.
  ls_dealer-enable = abap_true.                             "to enable all the fields initially
  modify lt_dealer from ls_dealer.
  endloop.
 node->bind_table( lt_dealer ).

3. create view container UIelment in the view and embed table view of the ALV used comp.

4. add interface controller of SALV_WD_TABLE to the used controller in the view and also add comp controller of our

local comp to the used controller list of interface contrl of Used comp. And then map the data node to the node we have filled in

the supply function.

5. go to the wddoinit method to configure the ALV grid. means adding button and input field and binding the enable property of

input field. Here is the code for the same.


data lo_cmp_usage type ref to if_wd_component_usage.
  lo_cmp_usage =   wd_this->wd_cpuse_alv( ).
  if lo_cmp_usage->has_active_component( ) is initial.
    lo_cmp_usage->create_component( ).
  endif.
  DATA lo_INTERFACECONTROLLER TYPE REF TO IWCI_SALV_WD_TABLE .
  lo_INTERFACECONTROLLER =   wd_this->wd_cpifc_alv( ).

    DATA lo_value TYPE ref to cl_salv_wd_config_table.
    lo_value = lo_interfacecontroller->get_model(
    ).
lo_value->IF_SALV_WD_TABLE_SETTINGS~SET_CELL_ACTION_EVENT_ENABLED( abap_true ).
lo_value->IF_SALV_WD_TABLE_SETTINGS~SET_READ_ONLY( ABAP_FALSE ).
data btn type ref to cl_salv_wd_uie_button.
data inp type ref to cl_salv_wd_uie_input_field.
data col1 type ref to cl_salv_wd_column.
data col type ref to cl_salv_wd_column.
data col2 type ref to cl_salv_wd_column.
call method lo_value->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN
exporting
  id = 'NAME'                         "col name is NAME (col with button)
  receiving
  value = col.
call method lo_value->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN
exporting
  id = 'LOCATION'                "col name is LOCATION (col with input field)
  receiving
  value = col1.
call method lo_value->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN
exporting
  id = 'ENABLE'                   "this col is used to control the enable property of input field and we will make it invisible.
  receiving
  value = col2.
create object btn.
CREATE OBJECT INP
EXPORTING
  VALUE_FIELDNAME = 'LOCATION'.
inp->set_enabled_fieldname( 'ENABLE' ).
COL1->SET_CELL_EDITOR( INP ).
btn->SET_TEXT_FIELDNAME( 'NAME' ).
 col->set_cell_editor( btn ).
col2->set_visible( '01' ).                     " making the enable col invisible

Now you need to create one eventhanlder for the action of cell action.

for this create an eventhandler and then even col there select ON_CELL_ACTION for the inerface cntrl of ALV.

now write the code in this eventhandler for enabling or disabling the input field after checking the current value and

row number from which the button was clicked. code for the same.

DATA lo_INTERFACECONTROLLER TYPE REF TO IWCI_SALV_WD_TABLE .
  lo_INTERFACECONTROLLER =   wd_this->wd_cpifc_alv( ).

    DATA lo_value TYPE ref to cl_salv_wd_config_table.
    lo_value = lo_interfacecontroller->get_model(
    ).
data inp type ref to cl_salv_wd_uie_input_field.
data col1 type ref to cl_salv_wd_column.
data str type string.
str = R_PARAM->COLUMN.
data indx type i.
  indx = r_param->index.               " this will get the row number
  DATA lo_nd_zdealer TYPE REF TO if_wd_context_node.
  DATA lo_el_zdealer TYPE REF TO if_wd_context_element.
  DATA ls_zdealer TYPE wd_this->element_zdealer.
  DATA lv_value LIKE ls_zdealer-enable.
* navigate from <CONTEXT> to <ZDEALER> via lead selection
  lo_nd_zdealer = wd_context->get_child_node( name = wd_this->wdctx_zdealer ).     
lo_el_zdealer = lo_nd_zdealer->get_element( index = indx ).     " get the corresponding element.
lo_el_zdealer->get_attribute(
    EXPORTING
      name =  `ENABLE`
  importing
      value = lv_value ).

IF str EQ 'NAME'.

  if lv_value eq abap_true.
lo_el_zdealer->set_attribute(
    EXPORTING
      name =  `ENABLE`

      value = abap_false ).
else.
  lo_el_zdealer->set_attribute(
    EXPORTING
      name =  `ENABLE`

      value = abap_true ).
  endif.
ENDIF.

this will solve it.

Thanks and Regards,

Sarbjeet singh

Former Member
0 Kudos

Hi vineeth ,

wht you need to do is in the event handler of the butto you have to read the status of the editable field and based on this you have to change it.

Do as per recommended like adding a attribute READ_ONLY of type WDY_BOOLEAN in your node,

Suppose initial all are editable

If you are using table UI element :-

Get the details of the particular row by get attributes .

If READ_ONLY = ' '. " if false then change it to

READ_ONLY = 'X'.

Do the reverse also.

If you are using ALV:-

1. Implement button in a column using cl_salv_wd_uie_button.

Then in the ON_CLICK method in the ( event handler of the button ) get the R_PARAM and INDEX and according to that read the details of the field attribute READ_ONLY and change accordingly like above.

Reply if in case if you have any issue with coding.

Thanks & Regards,

Monishankar C

sahai
Contributor
0 Kudos

HI,

DATA:LT_COLUMNS TYPE SALV_WD_T_COLUMN_REF,
  LS_COLUMNS TYPE SALV_WD_S_COLUMN_REF.

LOOP AT LT_COLUMNS INTO LS_COLUMN .


    CASE LS_COLUMN-ID .
      WHEN 'ATTRIBUTE NAME' "COLUMN NAME YOU WANT TO ,AKE ENABLE  DISABLE 
          LR_CHECKBOX->SET_READ_ONLY_FIELDNAME( VALUE = 'READ_ONLY' )." READ ONLY IS THE ADDITIONAL ATTRIBUTE ADDED OF TYPE CHAR01 
          LS_COLUMN-R_COLUMN->SET_CELL_EDITOR( LR_CHECKBOX ).
          FREE LR_CHECKBOX.
ENDCASE.

HOP THIS MAY BE HELPFULL TO YOU

REGARDS,

SAHAI.S