cancel
Showing results for 
Search instead for 
Did you mean: 

Edit few fields in an ALV table

Former Member
0 Kudos

Hi,

I am working on a table maintenance kind of application using ABAP web dynpro.

I have created an application using ALV, and also I could make all columns as editable.

But, I want to edit only 4 fields out of 7 in a row, when the same row is selected. Not all the columns in editable mode.

Also I want to default some of the fields which are grayed out in the same row. How to default them?

Could anyone help me about how to do this?

Thanks.

Sreekanth

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Sreekanth,

For this type of scenarios, in the WDDOINIT of your view make all the fields readonly.

Next, OnLeadSelect event of ALV, you need to write the code where it enables the few of your fields in edit mode and others as non editable.

How to generate a OnLeadSelect event?

1) For this, Create a eventhandler under methods tab of your view.

2) Besided the method you will be having some other columnns like Event name and component controller etc.

Press F4 and select the OnLeadSelect event of SALV_TABLE component controller.

This makes you ALV to register for OnLeadSelect event.

What code to be writtenn in that?

1) Declare the references to the ALV interfaces.

2) Get the current model of the ALV

3) Now get all the columns of the ALV into an internal table.

4) Loop all the columns now, and based on the column, call method set_cell_editor as TRUE.

How to Default values of the cell.

Here When you create a node and its attributes, Under the properties of the attributes, write the Default value and save the context.

I hope i have cleared all the points, and All the Best..

Regards,

Shashikanth. D

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Sreekanth,

To make ALV fields editable try using this code.

*filling the alv table

data lo_cmp_usage type ref to if_wd_component_usage.

lo_cmp_usage = wd_this->wd_cpuse_use_alv( ).

if lo_cmp_usage->has_active_component( ) is initial.

lo_cmp_usage->create_component( ).

endif.

data: l_ref_interfacecontroller type ref to iwci_salv_wd_table .

l_ref_interfacecontroller = wd_this->wd_cpifc_use_alv( ).

data: lr_salv_wd_table type ref to iwci_salv_wd_table,

r_table type ref to cl_salv_wd_config_table.

  • get reference to ALV component interface

lr_salv_wd_table = wd_this->wd_cpifc_use_alv( ).

  • get ConfigurationModel from ALV Component

r_table = lr_salv_wd_table->get_model( ).

  • init ColumnSettings

data: lr_column_settings type ref to if_salv_wd_column_settings,

  • lr_column type ref to cl_salv_wd_column.

lr_col_header type ref to cl_salv_wd_column_header.

lr_column_settings ?= r_table.

  • Make ALV Editable...

call method r_table->if_salv_wd_table_settings~set_read_only

exporting

value = abap_false. or abap_true.

If you want some of the columns to be editable and some as greyed loop get the column reference and write the conditions as what should happen when we click on some condition.

Try using this code Hope this helps you

Regards,

Sana.

arjun_thakur
Active Contributor
0 Kudos

Hi Sreekanth,

Please refer to this article:

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/f0625002-596c-2b10-46af-91cb31b7...

I hope it helps.

Regards

Arjun

Edited by: Arjun on Jan 6, 2009 9:11 AM

Former Member
0 Kudos

Hi,

For the Editable Row,

Create a context attribute called 'READ_ONLY'.

Initially populate this READ_ONLY by looping through the table accross all rows.

When you get the column references, Loop through this columns and set the columns for which you

want them in "INPUT" by creating the object of type 'INPUT_FIELD" for the others make them as TEXT_VIEW type.

Now for the table, use the SET_READ_ONLY (for fieldname) to 'READ_ONLY' and bind the attribute

READ_ONLY of context to the each column reference method 'SET_READONLY' method.

DATA:
    lt_colref TYPE salv_wd_t_column_ref,
    ls_colref TYPE salv_wd_s_column_ref,
    lv_id TYPE string,
    lr_colref TYPE REF TO cl_salv_wd_column,
    lr_input TYPE REF TO cl_salv_wd_uie_input_field,
    lr_cv type ref to cl_salv_wd_cv_standard.

  DATA lv_tabix type i.

  loop at lt_efforts into ls_efforts.
    lv_tabix = sy-tabix.
    if sy-tabix = lv_count.
      ls_efforts-READ_ONLY = abap_false.
    else.
      ls_efforts-READ_ONLY = abap_true.
    endif.
    modify lt_efforts from ls_efforts index
              lv_tabix transporting READ_ONLY.
  endloop.

  CALL METHOD LO_ND_EFF->BIND_TABLE
    EXPORTING
      NEW_ITEMS            = lt_eff
      SET_INITIAL_ELEMENTS = ABAP_TRUE.
*    INDEX                =


  CALL METHOD wd_comp_controller->gref_model_efforts->if_salv_wd_column_settings~get_columns
    RECEIVING
      value = lt_colref.


  LOOP AT lt_colref INTO ls_colref.
    lv_id = ls_colref-id.
    lr_colref = ls_colref-r_column.

    case lv_id.

      when 'COL1'.
        CREATE OBJECT lr_input
          EXPORTING
            value_fieldname = lv_id.
        CALL METHOD lr_colref->set_cell_editor
          EXPORTING
            value = lr_input.
        CALL METHOD LR_INPUT->SET_READ_ONLY_FIELDNAME
          EXPORTING
            VALUE = 'READ_ONLY'.

      when 'BEGDA'.

        CREATE OBJECT lr_input
          EXPORTING
            value_fieldname = lv_id.

        CALL METHOD lr_colref->set_cell_editor
          EXPORTING
            value = lr_input.
        CALL METHOD LR_INPUT->SET_READ_ONLY_FIELDNAME
          EXPORTING
            VALUE = 'READ_ONLY'.

      when 'ENDDA'.

        CREATE OBJECT lr_input
          EXPORTING
            value_fieldname = lv_id.

        CALL METHOD lr_colref->set_cell_editor
          EXPORTING
            value = lr_input.

        CALL METHOD LR_INPUT->SET_READ_ONLY_FIELDNAME
          EXPORTING
            VALUE = 'READ_ONLY'.


    endcase.

    CLEAR lv_id.
    CLEAR lr_colref.

  ENDLOOP.

*Set the table Editable
lo_value->if_salv_wd_table_settings~set_read_only( value = abap_false ).

Regards,

Lekha.