cancel
Showing results for 
Search instead for 
Did you mean: 

Enable/Disable check box field in ALV table

mahesh_jagnani
Participant
0 Kudos

Hi Expert,

I have a requirement in which we have to dispay an ALV table which contains threee coulmn whcih are check box.I done that.

Now the problem is that user shouild check only one check box at a time.In my case he can check all three check box.

Can you please tell how to restrict the user to check multiple check box.

Pleaae suggest.

Thanks

Mahesh

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

In this case, you need to create three other variables in the same node to which ALV is bound.

Now, when you have created the check box reference for columns, pass the respective field names to this method CL_SALV_WD_UIE_CHECKBOX->SET_READ_ONLY_FIELDNAME.

Now,

Loop at itab into watab.

if wa_itab-check1 = abap_true.   "checked
wa_itab-check2 = abap_false.   "unchecked.
wa_itab-check3 = abap_false.   "unchecked.
if wa_itab-check2 = abap_true.
wa_itab-check1 = abap_false.   "unchecked.
wa_itab-check3 = abap_false.   "unchecked.
if wa_itab-check3 = abap_true.
wa_itab-check1 = abap_false.   "unchecked.
wa_itab-check2 = abap_false.   "unchecked.
endif.
modify itab from watab.
endloop.

You can achieve this way. Also check if you use of TRI state checkbox usage.

mahesh_jagnani
Participant
0 Kudos

Hi Lekha,

Thanks.

Actulaly my requirement is to make enable/disable the check box at row level.Can u also tell how to tarck the action once user click the check box.

Can you please tell how we can do.

Mahesh

Edited by: mahesh jagnani on Feb 17, 2012 1:29 PM

Former Member
0 Kudos

Hi mahesh,

Follow the below procedure, I have tried it and it worked.

Here i have taken a node with name CHECKNODE and assigned the chekced fieldname to attribute check

which is of type wdy_boolean.

First implement the ON_DATA_CHECK event of ALV component.

And in your wdafteraction method call the DATA_CHECK eventhandler.


        method WDDOAFTERACTION .

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

  lo_interfacecontroller->data_check(
  ).
endmethod.          

Now in your DATA_CHECK eventhandler do the following.


  DATA lo_nd_checknode TYPE REF TO if_wd_context_node.
  DATA lo_el_checknode TYPE REF TO if_wd_context_element.
  DATA ls_checknode TYPE wd_this->element_checknode.
  DATA lt_checknode TYPE wd_this->elements_checknode.
* navigate from <CONTEXT> to <checknode> via lead selection
  lo_nd_checknode = wd_context->get_child_node( name = wd_this->wdctx_checknode ).

* @TODO handle not set lead selection
  IF lo_nd_checknode IS INITIAL.
  ENDIF.

* get element via lead selection
  lo_el_checknode = lo_nd_checknode->get_element(  ).

* @TODO handle not set lead selection
  IF lo_el_checknode IS INITIAL.
  ENDIF.

  CALL METHOD LO_ND_checknode->GET_STATIC_ATTRIBUTES_TABLE
*  EXPORTING
*    FROM   = 1
*    TO     = 2147483647
  IMPORTING
    TABLE  = lt_checknode
    .
 data : ls_modified_cells TYPE salv_wd_s_table_mod_cell.
 data : var type c.

loop at r_param->t_modified_cells INTO ls_modified_cells.

 loop at lt_checknode into ls_checknode.
   if sy-tabix = ls_modified_cells-index.
     else.
      if ls_checknode-check = 'X'.
        var = '1'.
        endif.
     endif.
   endloop.

 if var = '1'.
    loop at lt_checknode into ls_checknode.
   if sy-tabix = ls_modified_cells-index.
     ls_checknode-check = ''.
     modify lt_checknode from ls_checknode.
     endif.
   endloop.
   endif.
  endloop.
  lo_nd_checknode->bind_table( lt_checknode ).
"Now if only one checkbox is checked it appears as checked
 "If already a checkbox is checked 
"and someother checkbox is checked the second checkbox would not appear as checked.
"You can also show some popup to user to warn 

Former Member
0 Kudos

Hi,

Change the code inside loop to get the selected checkbox checked and only one at a time.

loop at r_param->t_modified_cells INTO ls_modified_cells.

 loop at lt_mara into ls_mara.
   if sy-tabix = ls_modified_cells-index.
     ls_mara-check = 'X'.
     else.
      ls_mara-check = ''.
     endif.
     modify lt_mara from ls_mara.
   endloop.


  endloop.
  lo_nd_mara->bind_table( lt_mara ).

mahesh_jagnani
Participant
0 Kudos

Hi,

Thanks..

But i ahve to make the enable/disable the cell depending on the checked/unchecked.

How it can bde done.

Mahesh

Former Member
0 Kudos

Hi,

You can enable the cell or disable it by using the method SET_ENABLE_FIELDNAME method and pass the

attribute to it.

if i understood you correctly, If the check box is checked you want to disable it and if not checked you

want it enabled, If this is what you need then above method will do it.

If this not what you need , brief me what you need exactly.