cancel
Showing results for 
Search instead for 
Did you mean: 

ALV editable Checkbox Column-ON_DATA_CHECK - how do we make editable

Former Member
0 Kudos

Hi,

I am developing a ALV by whihc row should be editable on checkbox click.

below is piece of code in ON_DATA_CHECK.

Field which I want to make editable is TDURAT.

SEPLAN is checkbox Column.

What else am i misisng?

LOOP AT r_param->t_modified_cells INTO wa_modified_data.
    CASE wa_modified_data-attribute.
      WHEN 'SEPLAN'.
        lv_index = wa_modified_data-index.
        READ TABLE lt_alvdata INTO ls_alv_data INDEX lv_index.
*** We need to check if the checkbox is checked/unchecked by the user
        ASSIGN wa_modified_data-r_value->* TO <fs>.
*** If it is checked then we need to make the 2 date columns as editable
        IF <fs> = 'X'.
          ls_alv_data-tdurat = ''.
*** If it is unchecked then we need to make the 2 date columns as non-editable
        ELSE.
          ls_alv_data-tdurat = 'X'.
        ENDIF.

        MODIFY lt_alvdata FROM ls_alv_data INDEX lv_index TRANSPORTING tdurat.
      WHEN 'PSTART'.
        lv_index = wa_modified_data-index.
        READ TABLE lt_alvdata INTO ls_alv_data INDEX lv_index.

        ASSIGN wa_modified_data-r_value->* TO <fs>.
        ls_alv_data-pfinis = <fs> + 7.
        lv_date1 = <fs>.
        ls_alv_data-pfinis = lv_date1 + 7.
        MODIFY lt_alvdata FROM ls_alv_data INDEX lv_index TRANSPORTING pfinis.

    ENDCASE.
  ENDLOOP.

Accepted Solutions (1)

Accepted Solutions (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Correct me if I am wrong, but you are only showing us part of the code. You seem to have a correct check on the checkbox value, but then you are setting a variable called LS_ALV_DATA. You don't show us any code how you are using LS_ALV_DATA or how you are controlling the editable functionality on TDURAT. There isn't really enough information here to comment further.

Former Member
0 Kudos

Thomas,

Thank you for the comment.Here is detailed Info.

This is for an editable ALV.

I need a checkbox as one of the column and 2 columns should become editable upon Checkbox selection.

For this I followed ALV tutorial (https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/3133474a-0801-0010-d692-81827814a5a1) and made columns editable.

Following some suggestions from sdn I did following things

1- created checkbox column SEPLAN field type CHAR1

2- Added an additional attribute READ_ONLY type boolean to existing context

3- Two fields which I want to make editable are TDURAT & PDURAT

4- lt_alvdata is the table whic holds data with checkbox Clicks.

Here is the full code.

METHOD ondatacheck .
  DATA lo_nd_alv_data TYPE REF TO if_wd_context_node.
  DATA lo_el_alv_data TYPE REF TO if_wd_context_element.
  DATA ls_alv_data TYPE wd_this->element_alv_data.
  DATA lt_alvdata TYPE TABLE OF wd_this->element_alv_data.
* navigate from <CONTEXT> to <ALV_DATA> via lead selection
  lo_nd_alv_data = wd_context->get_child_node( name = wd_this->wdctx_alv_data ).
*Get the data from context node
  CALL METHOD lo_nd_alv_data->get_static_attributes_table
    IMPORTING
      table = lt_alvdata.
  DATA: wa_modified_data TYPE salv_wd_s_table_mod_cell,
           lv_index TYPE i VALUE 0,
           lv_date TYPE date,
           wd_node TYPE REF TO if_wd_context_node.
  DATA : lv_date1 TYPE sy-datum.
  FIELD-SYMBOLS: <fs> TYPE data.

  LOOP AT r_param->t_modified_cells INTO wa_modified_data.
    CASE wa_modified_data-attribute.
      WHEN 'SEPLAN'.
        lv_index = wa_modified_data-index.
        READ TABLE lt_alvdata INTO ls_alv_data INDEX lv_index.
        ASSIGN wa_modified_data-r_value->* TO <fs>.
        IF <fs> = 'X'.
          ls_alv_data-tdurat = ''.
        ELSE.
          ls_alv_data-tdurat = 'X'.
        ENDIF.
        MODIFY lt_alvdata FROM ls_alv_data INDEX lv_index TRANSPORTING tdurat.
    ENDCASE.
  ENDLOOP.
  lo_nd_alv_data->bind_table( lt_alvdata ).

ENDMETHOD.

Rgds

Vara

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

You seem to actually be setting the value of tdurat based upon the checkbox selection value of SEPLAN. Don't you want to set your READ_ONLY attribute of your context?

Former Member
0 Kudos

Thomas,

Yes I corrected it and have set to READ_ONLY.

How do I proceed now.

In an other WD I have used Checkbox enabling/disabling I used.It worked perfectly..

LOOP AT lt_columns INTO ls_columns .
    CASE ls_columns-id  .
WHEN 'CHECK'.
DATA: lr_chkbox1 TYPE REF TO cl_salv_wd_uie_checkbox.
        CREATE OBJECT lr_chkbox1
          EXPORTING
            checked_fieldname = ls_columns-id.
        ls_columns-r_column->set_cell_editor( lr_chkbox1 ).
*"binding the read only property
        lr_chkbox1->set_read_only_fieldname( 'READ_ONLY' ).
endcase.

endloop.

I am trying similar way but getting confused on placing READ_ONLY attribute .Also, I am receiving a dump at

l_column_settings ?= lo_value.


DATA: lt_columns TYPE salv_wd_t_column_ref ,
        ls_columns TYPE salv_wd_s_column_ref .
  DATA: lo_value TYPE REF TO cl_salv_wd_config_table.
  DATA: lo_ref_interfacecontroller TYPE REF TO iwci_salv_wd_table .
  DATA: l_column_header  TYPE REF TO cl_salv_wd_column_header .
  DATA: l_column_settings TYPE REF TO if_salv_wd_column_settings.
  DATA: lr_column TYPE REF TO cl_salv_wd_column.
  lo_ref_interfacecontroller = wd_this->wd_cpifc_alv( ).
  lo_value = lo_ref_interfacecontroller->get_model( ).
  l_column_settings ?= lo_value.
  lt_columns = l_column_settings->get_columns( ) .


LOOP AT lt_columns INTO ls_columns .
    CASE ls_columns-id  .
      WHEN 'TDURAT' .
        DATA: lr_chkbox1 TYPE REF TO cl_salv_wd_uie_checkbox.
        DATA:lr_input_field TYPE REF TO cl_salv_wd_uie_input_field.
        lr_column = l_column_settings->get_column( 'TDURAT' ).
        CREATE OBJECT lr_input_field
          EXPORTING
            value_fieldname = 'TDURAT'.
        lr_column->set_cell_editor( lr_input_field ).
        lr_chkbox1->set_read_only_fieldname( 'READ_ONLY' ).
    ENDCASE.
  ENDLOOP.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

I see a couple of problems with your code. First you don't even need l_column_settings ?= lo_value.

Just lt_columns = lo_value->IF_SALV_WD_COLUMN_SETTING~get_columns( ) . will do. You don't have to cast to access an interface.

Next in your code you are setting the read-only method on the lr_chkbox1 object.

lr_chkbox1->set_read_only_fieldname( 'READ_ONLY' ).

Shouldn't you be setting that on the lr_input_field object? I don't even see lr_chkbox1 being instaniated in this code snippet, so imagine this would just short dump.

Former Member
0 Kudos

Thomas,

I have made the changes you have recommended to code. Now I don't get a DUMP.

However for Lr_column we don't have set_read_only_fieldname method.

I have gone in to the methods for cl_salv_wd_column and found set_visible but this is not meeting my requirement.

Which method do i use with READ_ONLY such that only that cell becomes editable?

lo_value = lo_ref_interfacecontroller->get_model( ).

lt_columns = lo_value->IF_SALV_WD_COLUMN_SETTINGs~get_columns( ) .

LOOP AT lt_columns INTO ls_columns .
    CASE ls_columns-id  .
      WHEN 'TDURAT' .
        DATA:lr_input_field TYPE REF TO cl_salv_wd_uie_input_field.
        lr_column = lo_value->IF_SALV_WD_COLUMN_SETTINGs~get_column( 'TDURAT' ).
        CREATE OBJECT lr_input_field
          EXPORTING
            value_fieldname = 'TDURAT'.
        lr_column->set_cell_editor( lr_input_field ).
*lr_column->SET_VISIBLE( 'READ_ONLY' ).
    ENDCASE.
  ENDLOOP.

rgds

Vara

Edited by: Vara K on Jul 7, 2009 11:49 PM

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

You don't set read-only on the column, but on the cell editor for the column. In this case it would be lr_input_field.

Former Member
0 Kudos

Thomas,

This worked! & almost there but it is doing other way around.

When I click checkbox it is making it read only instead of editable.

What could be the mistake i am doing ?

I have READ_ONLY value as 'X' for that row.

In order to make alv editable previously while search I did following

lr_table_settings ?= l_value.
  lr_table_settings->set_read_only( abap_false ).

  lr_table_settings->set_design( cl_wd_table=>e_design-alternating ).
  l_value->if_salv_wd_std_functions~set_edit_append_row_allowed( abap_false ).
  l_value->if_salv_wd_std_functions~set_edit_insert_row_allowed( abap_false ).
  l_value->if_salv_wd_std_functions~set_edit_delete_row_allowed( abap_false ).
  l_value->if_salv_wd_std_functions~set_edit_check_available( abap_false ).

LOOP AT lt_columns INTO ls_columns .
    CASE ls_columns-id  .
      WHEN 'TDURAT' .
        DATA:lr_input_field TYPE REF TO cl_salv_wd_uie_input_field.
        lr_column = lo_value->if_salv_wd_column_settings~get_column( 'TDURAT' ).
        CREATE OBJECT lr_input_field
          EXPORTING
            value_fieldname = 'TDURAT'.
        lr_input_field->set_read_only_fieldname( 'READ_ONLY' ).
        lr_column->set_cell_editor( lr_input_field ).


    ENDCASE.
  ENDLOOP.

rgds

Vara

Edited by: Vara K on Jul 8, 2009 12:30 AM

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Sounds like you have your condition switched on the setting of the read only value. Just flip flop the IF check.

Former Member
0 Kudos

Hi Vara,

I have READ_ONLY value as 'X' for that row.

passing 'X' to the READ_ONLY attribute will make the field close for editing. Pass space or abap_false to make it editable.

Regards,

Radhika.

Former Member
0 Kudos

Thank you Thomas.

Radhika,

Thank you for the info.

Answers (0)