cancel
Showing results for 
Search instead for 
Did you mean: 

How to make entire row as editable when insert row is pressed in ALV?

gopalkrishna_baliga
Participant
0 Kudos

Hi Experts,

I have a ALV webdynpro report. It has following columns:

CARRID key

CONNID key

FLDATE key

PRICE

CURRENCY

PLANETYPE

SEATSMAX

SEATSOCC

When the report loads, only non-key fields are editable.

But when the insert row or append row push button is pressed I want to make all the columns of the new row fully editable.

Insert and append row are ALV standard buttons.

It will be great if some code snippets are provided.

Thanks & Regards

Gopal

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

There are already postings on the same..

Create a attribute READ_ONLY char 1 for the current node sturcture.

First time, you need to pass X for this value..so that they are non editbale..At the time of inert row.. you need to pass as space(abap_false) to this record and use bind element. Then the entrie row becomes editable.

Please check out for my replies in this thread -

Regards,

Lekha.

gopalkrishna_baliga
Participant
0 Kudos

Hi Lekha,

I have searched the forum but did not any answer to my problem.

I want to make editable only a set of cells in a row.

For example:

If my ALV has 3 rows. First two rows are existing one and last row is the new one (just inserted).

Now in the first two rows I want only the non key columns to be enabled for edit. If first three columns are key fields then they should be read only while remaining should be editable.

However in case of the last row (new row) all the columns should be editable.

Is this possible?

If I use the solution using a READ_ONLY field in my context then it makes the entire row editable or non-editable.

I hope you understand my problem

Thanks

Gopal

Edited by: gopalkrishna baliga on Oct 29, 2010 7:50 AM

Former Member
0 Kudos

hi,Gopal

In your last post, you said:

I want to make editable only a set of cells in a row. 1st row: non-key fields. last row: all fields

About this requirement, i do suggest that you can add one context attribute named "is_new_row" to your table context node structure.

This context attribute can be used to control whether the row is "old" record or "complete new" row which you press "add row".

Then, you can bind this attribute to your first 3 input fields(alv cell)'s read-only property. That means if it is new row, the 3 fields should be ready-for input.

About how to bound, you can refer to:


"lr_input is the input field which will be set as cell editor of alv cell
lr_input->set_read_only( abap_true ).

lr_column->set_cell_editor( lr_input ).

More important: you know, as you add new context attribute to your table-context node, when you show alv, there will be more columns which is just "is_new_row".

So, you need to "delete" which means don't permit it is displayed in alv.

CALL METHOD l_value->if_salv_wd_column_settings~delete_column
        EXPORTING
          id = lv_fieldname.

Hope it can help you a little.

best wishes.

gopalkrishna_baliga
Participant
0 Kudos

Hi Tang,

I tried the way you have mentioned (see my code below). But this is making all the rows of the table editable.

What am i doing wrong here?

Basically I am not able to handle this:

How to loop through the entire node table (ALV table)? Then check if the READ_ONLY field in that row is checked 'X'.

If checked then for this row set all the columns editable.

Else if the READ_ONLY field in that row is NOT checked then for this row, set first three columns to be non editable and rest all columns editable.

My code:

*... ALV Component Usage

lr_comp_alv = wd_this->wd_cpuse_alv_tab( ).

if lr_comp_alv->has_active_component( ) is initial.

lr_comp_alv->create_component( ).

endif.

lr_comp_if_alv = wd_this->wd_cpifc_alv_tab( ).

*... Configure ALV

lr_config = lr_comp_if_alv->get_model( ).

*Get the context node information

node_sflight = wd_context->get_child_node( name =

wd_this->wdctx_sflight_tab ).

lr_info = node_sflight->get_node_info( ).

lt_node_info = lr_info->get_attributes( ).

loop at lt_node_info into ls_node_info.

ls_name-name = ls_node_info-name.

append ls_name to lt_name.

endloop.

  • Setup read only flag for the new row

LOOP AT r_param->t_inserted_rows ASSIGNING <wa_row>.

node_sflight = wd_context->get_child_node( name =

wd_this->wdctx_sflight_tab ).

elem_sflight = node_sflight->get_element( index = <wa_row>-index ).

elem_sflight->set_attribute(

EXPORTING

value = ABAP_FALSE

name = 'READ_ONLY' ).

ENDLOOP.

*Get all the columns to make row editable

call method lr_config->if_salv_wd_column_settings~get_columns

receiving

value = i_columns.

*Now loop the columns table and change the cell editor of a column

loop at i_columns into x_columns.

lr_column = x_columns-r_column.

lv_tabix = sy-tabix.

read table lt_name into ls_name index lv_tabix.

create object lr_input

exporting

value_fieldname = ls_name-name.

call method lr_column->set_cell_editor

exporting

value = lr_input .

end loop.

Former Member
0 Kudos

hi,Gopal.

After checked your requirement, i propose one EXAMPLE code, you can take a reference


* Set ALV display properties
  l_value = io_alv_controller->get_model( ).

*   Delete the added "is_new_row" attribute    
    CALL METHOD l_value->if_salv_wd_column_settings~delete_column
        EXPORTING
          id = 'is_new_row'.

* Get ALV columns
  CALL METHOD l_value->if_salv_wd_column_settings~get_columns
    RECEIVING
      value = lt_columns.


* Loop columns
  LOOP AT lt_columns INTO ls_column.

    lr_column = ls_column-r_column.


*   Init input control
    CREATE OBJECT lr_input
      EXPORTING
        value_fieldname = ls_column-id.

    lr_column->set_cell_editor( lr_input ).

*   Set read only
    "1.get the "Read_only" attribute of context, let's name it as "is_new_row"
    " i am sure you are very familiar with this for getting the context attribute
    
    if "your column name is your 3 key-column. 
       lr_input->set_read_only( is_new_row ).
    else."that means all the left-fields        
       lr_input->set_read_only( abap_false ).
    endif.

    ENDIF.

  ENDLOOP.

Hope it can help you a little.

Best wishes.

gopalkrishna_baliga
Participant
0 Kudos

Hi Tang,

I tried your code but it is making all the columns of all the rows editable.

See my code below. What am I doing wrong?

*Get all the columns to make row editable

call method lr_config->if_salv_wd_column_settings~get_columns

receiving

value = i_columns.

data: v_count type i,

v_itr type i.

*get number of rows in the table including the new record if insert row is selected

v_count = node_sflight->GET_ELEMENT_COUNT( ).

  • Loop through each row

v_itr = 1.

WHILE v_itr <= v_count.

elem_sflight = node_sflight->get_element( index = v_itr ).

v_itr = v_itr + 1.

  • Get the is_new_row value

elem_sflight->get_attribute(

EXPORTING

name = 'is_new_row'

IMPORTING

value = lv_read_only ).

*Now loop the columns table and change the cell editor of a column

loop at i_columns into x_columns.

lr_column = x_columns-r_column.

create object lr_input

exporting

value_fieldname = x_columns-id.

call method lr_column->set_cell_editor

exporting

value = lr_input .

*is_new_row is 'X' (existing row) then

IF lv_read_only = 'X' .

IF x_columns-ID = 'MANDT' OR x_columns-ID = 'CONNID'

OR x_columns-ID = 'CARRID' OR x_columns-ID = 'FLDATE'.

lr_input->set_read_only( abap_true ).

ENDIF.

ELSE.

    • To make the required row is editable

lr_input->set_read_only( abap_false ).

ENDIF.

endloop.

*ENDWHILE.

Former Member
0 Kudos

Hi,

As per your requiremnt, You need only some set of cells in arow to be editable and others are non-editable...Is that so..

As there are key and Non Key fields. Take 2 readonly variables one for each set of group.

For Key fields, bind READONLY and NonKEYFIELDS bind READONLY1 vairables while looping the columns.

Now, As per teh requriement set both of them as either true or false..and modify the table.

There is other way to do this...Use the Cell Variants.

Regards,

Lekha.

gopalkrishna_baliga
Participant
0 Kudos

Hi Lekha,

I am really sorry if my requirement is not clear.

Here it is again.

When I load the report the report pulls existing records from the backend table and displays in the ALV table.

At present there are 4 existing entries.

User can also enter a new entry in the ALV table by clicking the "Insert Row" or "Append row" buttons.

Let us assume that the user has inserted a new row. Therefore now the ALV table will have total 5 entries. 4 entries are the one that the report has pulled from backend table and 1 entry is the new row.

Now ALV should display the rows as mentioned below.

1. For existing 4 rows make the key fields non editable and non-key fields editable.

2. For the new row, make all the fields editable.

I hope now the requirement is clear.

Thanks & Regards

Gopal

Former Member
0 Kudos

Hi,

In teh node to which the ALV is bound, Take 2 READ_ONLY variables of type WDY_BOOLEAN.

One for Key fields and other for Non-Key fields.

I have one key field 'TYPE' and other Nonkey field 'TYPE1'

Initially when the report is shown -

Here is the entire code


 DATA lt_test_1 TYPE wd_this->elements_test_1.
  DATA ls_test_1 TYPE wd_this->element_test_1.
  DATA lo_nd_test_1 TYPE REF TO if_wd_context_node.

  ls_test_1-type = 'test'.
  ls_test_1-type1 = 'test1'.
  ls_test_1-read_only1 = abap_false.  "Non key-editable
  ls_test_1-read_only = abap_true.  "Key-Non editable
  APPEND ls_test_1 TO lt_test_1.
  CLEAR ls_test_1.

  ls_test_1-type = 'testt'.
  ls_test_1-type1 = 'test2'.
  ls_test_1-read_only1 = abap_false.  "Non key-editable
  ls_test_1-read_only = abap_true.  "Key-Non editable
  APPEND ls_test_1 TO lt_test_1.
  CLEAR ls_test_1.

* navigate from <CONTEXT> to <TEST_1> via lead selection
  lo_nd_test_1 = wd_context->get_child_node( name = wd_this->wdctx_test_1 ).

  lo_nd_test_1->bind_table( lt_test_1 ).

  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 lv_value TYPE REF TO cl_salv_wd_config_table.
  lv_value = lo_interfacecontroller->get_model(
  ).

  DATA lt_cols TYPE salv_wd_t_column_ref.
  DATA ls_cols TYPE salv_wd_s_column_ref.

  CALL METHOD lv_value->if_salv_wd_column_settings~get_columns
    RECEIVING
      value = lt_cols.

  DATA lr_input TYPE REF TO cl_salv_wd_uie_input_field.

  LOOP AT lt_cols INTO ls_cols.

    CASE ls_cols-id.

      WHEN 'TYPE'.  "KEY FIELD

        CREATE OBJECT lr_input
          EXPORTING
            value_fieldname = ls_cols-id.

        CALL METHOD ls_cols-r_column->set_cell_editor
          EXPORTING
            value = lr_input.


        CALL METHOD lr_input->set_read_only_fieldname
          EXPORTING
            value = 'READ_ONLY'.  "KEY


      WHEN 'TYPE1'.  "NON KEY FIELD

        CREATE OBJECT lr_input
          EXPORTING
            value_fieldname = ls_cols-id.

        CALL METHOD ls_cols-r_column->set_cell_editor
          EXPORTING
            value = lr_input.


        CALL METHOD lr_input->set_read_only_fieldname
          EXPORTING
            value = 'READ_ONLY1'.  "NON KEY

    ENDCASE.

  ENDLOOP.


  CALL METHOD lv_value->if_salv_wd_table_settings~set_read_only
    EXPORTING
      value = abap_false.

  DATA lr_insert TYPE REF TO cl_salv_wd_fe_button.
  DATA lr_function TYPE REF TO cl_salv_wd_function.

  CREATE OBJECT lr_insert.

  CALL METHOD lv_value->if_salv_wd_function_settings~create_function
    EXPORTING
      id    = 'ADD'
    RECEIVING
      value = lr_function.

  CALL METHOD lr_function->set_editor
    EXPORTING
      value = lr_insert.

CALL METHOD lr_insert->set_text
  EXPORTING
    value  = 'Add'.

*Add button

if r_param->id = 'ADD'.

  DATA lo_nd_test_1 TYPE REF TO if_wd_context_node.
* navigate from <CONTEXT> to <TEST_1> via lead selection
  lo_nd_test_1 = wd_context->get_child_node( name = wd_this->wdctx_test_1 ).

  DATA lt_test_1 TYPE wd_this->elements_test_1.
  DATA ls_test_1 TYPE wd_this->element_test_1.
  DATA lr_element type ref to if_wd_context_element.

DATA lv_count type i.
CALL METHOD   lo_nd_test_1->get_element_count
  receiving
    count  = lv_count.
    lv_count = lv_count + 1.

  lo_nd_test_1->get_static_attributes_table( IMPORTING table = lt_test_1 ).

  ls_test_1-read_only  = abap_false.  "both editable
  ls_test_1-read_only1  = abap_false.
  append ls_test_1 to lt_test_1.
   lo_nd_test_1->bind_table( lt_test_1 ).
endif.

In Add button functinality, You can refine the code.

Please try this out..

Regards,

Lekha.

Edited by: Lekha on Nov 16, 2010 6:28 PM

gopalkrishna_baliga
Participant
0 Kudos

Hi Lekha,

I think you have created a new button called "ADD". When the user presses "ADD" button your ADD method is called where a new row is added with all fields of the new row made read only.

In my case I am using the ALV standard button "Insert Row". I have written a event handler code on "ON_DATA_CHECK".

But the problem is that t is triggered only After the call for checking the data modification.

Will your logic work for standard function also?

Thanks

Gopal

Former Member
0 Kudos

Hi,

It is for custom button called ADD. not for standard one. as per your requirement you need to use Custom button to handle things.

Regards,

Lekha.

Former Member
0 Kudos

Hi,

Please find this link it will helps you.

<-- removed by moderator -->

Edited by: Neil Gardiner on Nov 4, 2010 10:28 AM