cancel
Showing results for 
Search instead for 
Did you mean: 

Editable row in ALV

Former Member
0 Kudos

Hi All,

Is there any possibility that only a particular row can be made editable on clicking of a button.

i.e; for example, if i click on display button, the data displayed in ALV should be in read only mode.

But when i click on add button, only the new row inserted should be in editable mode.

Kindly, let me know if this can be achieved.

Thanks in Advance.

Regards,

Durga.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

HI,

See this WIKI [ How to use attribute properties in the WD ALV component|http://wiki.sdn.sap.com/wiki/display/WDABAP/SAPListViewer-ALV#SAPListViewer-ALV-HowtouseattributepropertiesintheWDALVcomponent%3F]

You can bind your attribute property like Read_only,visibility,enabled to the UI Element property.

Former Member
0 Kudos

Thanks for the reply.

But as per the code in link provided, it makes the whole coloumn as editable. My requirement is only to make the attributes of the particular new row editable and all others as read only.

Kindly help.

Former Member
0 Kudos

Hi,

No it is not true.

If you read the wiki correctly. you can iterate through your node and bind the attribute properties at node level.

you can do the following.

initial all the elements and attributes are read_only = abap_true.

ls_attribute_properties-read_only = abap_true.

in this way all the all cell_editors are read_only.

On button add action, you are adding a element to the node and bind that element property ls_attribute_properties-read_only = abap_false.

make sure that only the newly added element property is set to false and rest are untouched.

Example code is added.

code to set the attribute properties in all the elements in a node.

data:
    lr_node type ref to if_wd_context_node,
    ls_attribute_properties type wdr_context_prop_for_node,
    lt_attribute_properties type wdr_context_prop_for_node_tab,
    l_element  type i,
    l_elements type i.


"get the context node
lr_node = wd_context->get_child_node( 'DATA' ).

"get number of elements
l_elements = lr_node->get_element_count( ).

  do l_elements times.
    add 1 to l_element.
    clear ls_attribute_properties.
    ls_attribute_properties-element_index = l_element.
    do 1 times. "times depends on the number of attributes in the element
      case sy-index.
        when 1.
          ls_attribute_properties-attribute_name = 'GEBOORTEDATUM'.
      endcase.
      ls_attribute_properties-visible   = abap_true.
      ls_attribute_properties-read_only = abap_true.
      ls_attribute_properties-enabled   = abap_true.
      insert ls_attribute_properties into table lt_attribute_properties.
    enddo.
  enddo.
  lr_node->set_attribute_props_for_node( lt_attribute_properties ).

code to set the attribute properties in one element in a node after you press add button (insert a row ).

DATA lo_nd_data TYPE REF TO if_wd_context_node.
  DATA lo_el_data TYPE REF TO if_wd_context_element.

  DATA ls_data TYPE wd_this->element_data.
  DATA lt_properties TYPE wdr_context_properties_tab.
  DATA ls_properties TYPE wdr_context_properties.

  ls_properties-attribute_name = 'GEBOORTEDATUM'.
  ls_properties-required = abap_false.
  ls_properties-read_only = abap_false.
  ls_properties-visible = abap_true.
  ls_properties-enabled = abap_true.

  APPEND ls_properties TO lt_properties.

* navigate from <CONTEXT> to <DATA> via lead selection
  lo_nd_data = wd_context->get_child_node( name = wd_this->wdctx_data ).

* append a line to the node
  lo_el_data = lo_nd_data->bind_structure( new_item = ls_data set_initial_elements = abap_false  index = 1 ).
  lo_el_data->set_attribute_props_for_elem(
      properties  = lt_properties
*      keep_others = ABAP_FALSE
         ).

code fragment in Configure_ALV method.

loop at lt_columns into lo_column.
        " input field
        create object lo_input_field
          exporting
            value_fieldname = lo_column-id.
        CONCATENATE lo_column-id ':READ_ONLY' INTO lv_read_only.
        lo_input_field->set_read_only_fieldname( lv_read_only ).
        lo_column-r_column->set_cell_editor( lo_input_field ).
  endloop.

PS: In my context ,the node name is DATA and it has a attribute GEBOORTEDATUM.

DATA node has external binding with ALV DATA node.

Edited by: Baskaran Senthivel on Dec 1, 2010 3:43 PM

Former Member
0 Kudos

Thanks once again for your replies.

But am still not able to get the actual functionality needed.

I am pasting the code i have written, can you please let me know where am i going wrong. As I am new please help me in sorting out this.

The below part of the code is in Display_ALV button (configuring ALV).

CN_ALV is my node containing 5 attributes.

{* configuring ALV

DATA lo_cmp_usage TYPE REF TO if_wd_component_usage.

lo_cmp_usage = wd_this->wd_cpuse_zalv( ).

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_zalv( ).

DATA lo_value TYPE REF TO cl_salv_wd_config_table.

lo_value = lo_interfacecontroller->get_model( ).

CALL METHOD lo_value->if_salv_wd_std_functions~set_export_allowed

EXPORTING

value = abap_false.

lo_value->if_salv_wd_std_functions~set_pdf_allowed( abap_false ).

  • set visible row count

DATA: lr_table_settings TYPE REF TO if_salv_wd_table_settings.

lr_table_settings ?= lo_value.

lr_table_settings->set_visible_row_count( '6' ).

lr_table_settings->set_fixed_table_layout( ).

lr_table_settings->set_read_only( abap_false )."

lr_table_settings->set_scrollable_col_count( '5' ).

    • Set Row Design

CALL METHOD lr_table_settings->set_design

EXPORTING

value = cl_wd_table=>e_design-alternating.

          • set column details

DATA: lr_column_settings TYPE REF TO if_salv_wd_column_settings,

lr_column TYPE REF TO cl_salv_wd_column,

lr_column_header TYPE REF TO cl_salv_wd_column_header,

lr_alv_input_field TYPE REF TO cl_salv_wd_uie_input_field.

lr_column_settings ?= lo_value.

**********************************************************************

DATA:

lo_nd_cn_alv TYPE REF TO if_wd_context_node,

ls_attribute_properties TYPE wdr_context_prop_for_node,

lt_attribute_properties TYPE wdr_context_prop_for_node_tab,

lo_column type salv_wd_s_column_ref,

lt_columns type salv_wd_t_column_ref,

l_element TYPE i,

l_elements TYPE i,

lv_read_only TYPE string.

"get the context node

lo_nd_cn_alv = wd_context->get_child_node( name = wd_this->wdctx_cn_alv ).

"get number of elements

l_elements = lo_nd_cn_alv->get_element_count( ).

DO l_elements TIMES.

ADD 1 TO l_element.

CLEAR ls_attribute_properties.

ls_attribute_properties-element_index = l_element.

DO 5 TIMES. "times depends on the number of attributes in the element

CASE sy-index.

WHEN 1.

ls_attribute_properties-attribute_name = 'PERNR'.

WHEN 2.

ls_attribute_properties-attribute_name = 'ENAME'.

WHEN 3.

ls_attribute_properties-attribute_name = 'BTRTL'.

WHEN 4.

ls_attribute_properties-attribute_name = 'BTEXT'.

WHEN 5.

ls_attribute_properties-attribute_name = 'AEDTM'.

ENDCASE.

ls_attribute_properties-visible = abap_true.

ls_attribute_properties-read_only = abap_true.

ls_attribute_properties-enabled = abap_true.

INSERT ls_attribute_properties INTO TABLE lt_attribute_properties.

ENDDO.

ENDDO.

lo_nd_cn_alv->set_attribute_props_for_node( lt_attribute_properties ).

lt_columns = lr_column_settings->get_columns( ).

LOOP AT lt_columns INTO lo_column.

" input field

CREATE OBJECT lr_alv_input_field

EXPORTING

value_fieldname = lo_column-id.

CONCATENATE lo_column-id ':READ_ONLY' INTO lv_read_only.

lr_alv_input_field->set_read_only_fieldname( lv_read_only ).

lo_column-r_column->set_cell_editor( lr_alv_input_field ).

ENDLOOP.

The below part of the code is in ADD new row button

DATA lo_nd_cn_alv TYPE REF TO if_wd_context_node.

DATA lo_el_cn_alv TYPE REF TO if_wd_context_element.

DATA ls_cn_alv TYPE wd_this->element_cn_alv.

  • navigate from <CONTEXT> to <CN_ALV> via lead selection

lo_nd_cn_alv = wd_context->get_child_node( name = wd_this->wdctx_cn_alv ).

DATA lv_count TYPE i.

lv_count = lo_nd_cn_alv->get_element_count( ).

lv_count = lv_count + 1.

**********************************************************************

DATA lt_properties TYPE wdr_context_properties_tab.

DATA ls_properties TYPE wdr_context_properties.

ls_properties-attribute_name = 'PERNR'.

ls_properties-required = abap_false.

ls_properties-read_only = abap_false.

ls_properties-visible = abap_true.

ls_properties-enabled = abap_true.

APPEND ls_properties TO lt_properties.

  • append a line to the node

lo_el_cn_alv = lo_nd_cn_alv->bind_structure( new_item = ls_cn_alv

set_initial_elements = abap_false

index = lv_count ).

lo_el_cn_alv->set_attribute_props_for_elem(

properties = lt_properties

  • keep_others = ABAP_FALSE

).

lo_nd_cn_alv->set_lead_selection_index( lv_count ).

**********************************************************************

DATA lo_interfacecontroller TYPE REF TO iwci_salv_wd_table .

lo_interfacecontroller = wd_this->wd_cpifc_zalv( ).

DATA lo_value TYPE REF TO cl_salv_wd_config_table.

lo_value = lo_interfacecontroller->get_model( ).

CALL METHOD lo_value->if_salv_wd_table_settings~set_first_visible_row

EXPORTING

value = lv_count.

}

Thanks in Advance.

Regards,

Durga.

former_member429661
Participant
0 Kudos

Hi Baskaran,

i tried your example. But it did not work. Don't no where my fault is...

It is my extension to the example from Thomas Jung ([SE16|http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/bf20e84f-0901-0010-fe9e-91d100013a59])

Problem is: all columns are editable. Not only the nonkey columns.

* get instance of new node
  dyn_node = wd_context->get_child_node( name = tablename ).

* bind internal table to context node
  dyn_node->bind_table( <tab> ).

* connect to the component usage of the alv
  DATA: l_ref_cmp_usage TYPE REF TO if_wd_component_usage.
  l_ref_cmp_usage = wd_this->wd_cpuse_alv( ).

  IF l_ref_cmp_usage->has_active_component( ) IS INITIAL.
    l_ref_cmp_usage->create_component( ).
  ENDIF.

* through the interface controller of the alv component set the data node dynamically
  DATA: l_ref_interfacecontroller TYPE REF TO iwci_salv_wd_table .
  l_ref_interfacecontroller = wd_this->wd_cpifc_alv( ).
  l_ref_interfacecontroller->set_data( r_node_data = dyn_node ).


  IF wd_comp_controller->url_edit = 'SAP_EDIT'.
*  *****************************************************************************
*    Define function to insert, update, delete
*  *****************************************************************************
    DATA: lr_table_settings TYPE REF TO if_salv_wd_table_settings.
    DATA lr_buttonui TYPE REF TO cl_salv_wd_fe_button.
    DATA button1 TYPE REF TO cl_salv_wd_function.

    DATA: ls_attribute_properties TYPE wdr_context_prop_for_node,
          lt_attribute_properties TYPE wdr_context_prop_for_node_tab.

    DATA: wd_table TYPE REF TO iwci_salv_wd_table.
    DATA: alv_config_table  TYPE REF TO cl_salv_wd_config_table.
    DATA: lr_std_functions  TYPE REF TO if_salv_wd_std_functions.

    DATA: lt_columns TYPE salv_wd_t_column_ref,
          lr_column TYPE REF TO cl_salv_wd_column,
          ls_columns TYPE salv_wd_s_column_ref,
          lr_input TYPE REF TO cl_salv_wd_uie_input_field,
          lv_read_only TYPE string.

    FIELD-SYMBOLS: <wa_def> LIKE LINE OF wd_this->flddescr.

    wd_table = wd_this->wd_cpifc_alv( ).
    alv_config_table = wd_table->get_model( ).
    lr_table_settings ?= alv_config_table.
    lr_std_functions ?= alv_config_table.

*  *****************************************************************************
*   set read only mode to false (and display edit toolbar)
*  *****************************************************************************
    lr_table_settings->set_read_only( abap_false ).
    
    lt_columns = alv_config_table->if_salv_wd_column_settings~get_columns( ).

*   ... for all columns....
    LOOP AT lt_columns INTO ls_columns.
      CLEAR ls_attribute_properties.

      READ TABLE wd_this->flddescr ASSIGNING <wa_def> INDEX sy-tabix.

*     set editor an connect to the properties
      lr_column = ls_columns-r_column.

      CONCATENATE ls_columns-id ':READ_ONLY' INTO lv_read_only.

      CREATE OBJECT lr_input
        EXPORTING
          value_fieldname = ls_columns-id.

      lr_input->set_read_only_fieldname( lv_read_only ).

      CALL METHOD lr_column->set_cell_editor
        EXPORTING
          value = lr_input.

*     depending of key-column make it read_only or not
      IF <wa_def>-keyflag ne abap_true. " no key
        ls_attribute_properties-attribute_name = ls_columns-id.
        ls_attribute_properties-visible   = abap_true.
        ls_attribute_properties-enabled   = abap_true.
        ls_attribute_properties-read_only = abap_false. "this should be editable

        INSERT ls_attribute_properties INTO TABLE lt_attribute_properties.

      ELSE.
        ls_attribute_properties-attribute_name = ls_columns-id.
        ls_attribute_properties-visible   = abap_true.
        ls_attribute_properties-enabled   = abap_true.
        ls_attribute_properties-read_only = abap_true.
        INSERT ls_attribute_properties INTO TABLE lt_attribute_properties.
      ENDIF.
    ENDLOOP.

*   set  properties for for all columns
    dyn_node->set_attribute_props_for_node( lt_attribute_properties )."set all properties for all columns

  ENDIF.

Edited by: Bernward Henkel on Dec 22, 2010 10:26 AM

Former Member
0 Kudos

Hallo Bernward,

I see one essential difference.

ls_attribute_properties-element_index is not set and it is necessary if you use set_attribute_props_for_node.

My code is like this

data:
    lr_node type ref to if_wd_context_node,
    ls_attribute_properties type wdr_context_prop_for_node,
    lt_attribute_properties type wdr_context_prop_for_node_tab,
    l_element  type i,
    l_elements type i.


"get the context node
lr_node = wd_context->get_child_node( 'DATA' ).

"get number of elements
l_elements = lr_node->get_element_count( ).

  do l_elements times.
    add 1 to l_element.
    clear ls_attribute_properties.
    ls_attribute_properties-element_index = l_element.
    do 1 times. "times depens on the number of attributes in the element
      case sy-index.
        when 1.
          ls_attribute_properties-attribute_name = 'GEBOORTEDATUM'.
      endcase.
      ls_attribute_properties-visible   = abap_true.
      ls_attribute_properties-read_only = abap_true.
      ls_attribute_properties-enabled   = abap_true.
      insert ls_attribute_properties into table lt_attribute_properties.
    enddo.
  enddo.
  lr_node->set_attribute_props_for_node( lt_attribute_properties ).

so change your code like this

ls_attribute_properties-element_index = <replace with index of the current element in the nodet>
*     depending of key-column make it read_only or not
      IF <wa_def>-keyflag ne abap_true. " no key
        ls_attribute_properties-attribute_name = ls_columns-id.
        ls_attribute_properties-visible   = abap_true.
        ls_attribute_properties-enabled   = abap_true.
        ls_attribute_properties-read_only = abap_false. "this should be editable
 
        INSERT ls_attribute_properties INTO TABLE lt_attribute_properties.
 
      ELSE.
        ls_attribute_properties-attribute_name = ls_columns-id.
        ls_attribute_properties-visible   = abap_true.
        ls_attribute_properties-enabled   = abap_true.
        ls_attribute_properties-read_only = abap_true.
        INSERT ls_attribute_properties INTO TABLE lt_attribute_properties.
      ENDIF.

former_member429661
Participant
0 Kudos

Hi Baskaran,

strike!!! That was the problem. 1mio. point s for you! How can ic give you the point ?

Thanks a lot..

--Berndward

Former Member
0 Kudos

>

> Hi Baskaran,

>

> strike!!! That was the problem. 1mio. point s for you! How can ic give you the point ?

>

> Thanks a lot..

>

> --Berndward

Hallo Berndward,

Good to hear that it is working for you. You cannot give points as because you have replied in Durga's discussion.

Your 1mio. point s are enough for me !!

Former Member
0 Kudos

Hello,

I have used a similar logic for making the row editable in my ALV table output.

my doubt is that: do we need to 'refresh' the ALV display or do some configuration after implementing the below mentioned code? because the row/columns are still 'uneditable' in my ALV table output.

data:

lr_node type ref to if_wd_context_node,

ls_attribute_properties type wdr_context_prop_for_node,

lt_attribute_properties type wdr_context_prop_for_node_tab,

l_element type i,

l_elements type i.

"get the context node

lr_node = wd_context->get_child_node( 'PO_HEADER_INFO' ).

"get number of elements

l_elements = lr_node->get_element_count( ).

do l_elements times.

add 1 to l_element.

clear ls_attribute_properties.

ls_attribute_properties-element_index = l_element.

do 49 times. "times depends on the number of attributes in the element

case sy-index.

when 1.

ls_attribute_properties-attribute_name = 'ORDER_NUMBER'.

WHEN 2.

ls_attribute_properties-attribute_name = 'PRODUCTION_PLANT'.

WHEN 3.

ls_attribute_properties-attribute_name = 'MRP_CONTROLLER'.

      • attribute 4 to attribute 48 ***

WHEN 49.

ls_attribute_properties-attribute_name = 'READ_ONLY'.

when OTHERS.

endcase.

ls_attribute_properties-enabled = abap_true.

ls_attribute_properties-visible = abap_true.

ls_attribute_properties-read_only = ABAP_FALSE.

insert ls_attribute_properties into table lt_attribute_properties.

  • CLEAR ls_attribute_properties-attribute_name.

enddo.

enddo.

lr_node->set_attribute_props_for_node( lt_attribute_properties ).

Thanks in Advance!!!

Ravish

Former Member
0 Kudos

Hallo Ravish,

My suggestion is to start new discussion as this is someone else discussion.

The logic which you posted seems correct to set the attributes of all elements in the node. Further i cannot conclude based on this peice of code where you might go wrong.

Have configured the alv input enabled and i assume that you use inputfield as cell-editor.

Have binded the cell-editor readonly property to the attribute readonly property.

So please post in your new discussion about the alv configuration coding involving looping the columns and bindings etc.

Cheers

Answers (1)

Answers (1)

Former Member
0 Kudos

HI,

You can make it by adding a attribute READ_ONLY in your context node.

The attribute is of type WDY_BOOLEAN.

Now when you are populating your data in context node , you make the value of attribute READ_ONLY ABAP_TRUE or ABAP_FALSE.

like:-

IF (CONTEXT_NODE NAME -ATTRIBUTE NAME) is NOT INITIAL.

(CONTEXT_NODE)-READ_ONLY = ABAP_TRUE.

ELSE.

IF {CONTEXT_NODE NAME-ATTRIBUTE NAME} IS INITIAL.

-READ_ONLY = ABAP_FALSE.

ENDIF.

ENDIF.

Based on the value of READ_ONLY your alv row will become read only or editable.

Now when you are displaying your alv:-

LO_CMP_USAGE = WD_THIS->WD_CPUSE_ALV_COMP( ).

IF LO_CMP_USAGE->HAS_ACTIVE_COMPONENT( ) IS INITIAL.

LO_CMP_USAGE->CREATE_COMPONENT( ).

ENDIF.

LO_INTERFACECONTROLLER = WD_THIS->WD_CPIFC_ALV_COMP( ).

LO_INTERFACECONTROLLER->SET_DATA(

  • only_if_new_descr = " wdy_boolean

R_NODE_DATA = { YOUR NODE NAME } " ref to if_wd_context_node

).

DATA LV_VALUE TYPE REF TO CL_SALV_WD_CONFIG_TABLE.

LV_VALUE = LO_INTERFACECONTROLLER->GET_MODEL(

).

DATA: LS_COLUMN TYPE SALV_WD_S_COLUMN_REF,

LT_COLUMNS TYPE SALV_WD_T_COLUMN_REF.

DATA: LR_COLUMN TYPE REF TO CL_SALV_WD_COLUMN.

DATA LR_INPUT_FIELD TYPE REF TO CL_SALV_WD_UIE_INPUT_FIELD.

DATA: LR_TABLE_SETTINGS TYPE REF TO IF_SALV_WD_TABLE_SETTINGS.

  • configure columns

LR_COLUMN_SETTINGS ?= LV_VALUE.

LT_COLUMNS = LR_COLUMN_SETTINGS->GET_COLUMNS( ).

LOOP AT LT_COLUMNS INTO LS_COLUMN .

CASE LS_COLUMN-ID .

{ Now if you want particular activity in any column then do it by each column id }

WHEN {column name A }.

CREATE OBJECT LR_INPUT_FIELD EXPORTING VALUE_FIELDNAME = LS_COLUMN-ID .

LR_COLUMN = LV_VALUE->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN( ID = LS_COLUMN-ID ).

LR_COLUMN->SET_CELL_EDITOR( LR_INPUT_FIELD ).

LR_INPUT_FIELD->SET_READ_ONLY_FIELDNAME( VALUE = 'READ_ONLY' ).

{ As you have to make a column input field to make it editable}

WHEN 'READ_ONLY'.

LS_COLUMN-R_COLUMN->SET_VISIBLE( IF_WDL_CORE=>VISIBILITY_NONE ).

CASE OTHERS.

CREATE OBJECT LR_INPUT_FIELD EXPORTING VALUE_FIELDNAME = LS_COLUMN-ID .

LR_COLUMN = LV_VALUE->IF_SALV_WD_COLUMN_SETTINGS~GET_COLUMN( ID = LS_COLUMN-ID ).

LR_COLUMN->SET_CELL_EDITOR( LR_INPUT_FIELD ).

LR_INPUT_FIELD->SET_READ_ONLY_FIELDNAME( VALUE = 'READ_ONLY' ).

ENDCASE.

  • set read only mode to false (and display edit toolbar)

LR_TABLE_SETTINGS ?= LV_VALUE.

LR_TABLE_SETTINGS->SET_READ_ONLY( ABAP_FALSE ).

ENDLOOP.

Now when you want to make a row read_only or editable , then in that particular event ( as in your case clicking of a button)

change the value of attribute READ_ONLY to ABAP_TRUE or ABAP_FALSE accordingly.

Thanks and let me know if you have any concerns.