Skip to Content
Author's profile photo Former Member

Conditionally editing cells of a ALV table in Web Dynpro for ABAP

So far we have lots of example to make webdynpro row editable, columns editable conditionally.

The below shown example is for editing particular “Cell” value conditionally in a columns of ALV.

Assumed Scenario: Make Material number (MATNR) non-editable if row number is 2, 4 and7 for rest of the rows It should be editable.

Solution:

Step 1.Create webdynpro ALV with normal way.

/wp-content/uploads/2013/05/1_221695.png

Step2.Create attribute ‘READ_ONLY’ of char 01 in a output node.

/wp-content/uploads/2013/05/2_221699.png

Go to the method WDDOINIT and write following.

METHOD wddoinit .

*Data declaration
 
DATA lo_nd_mara TYPE REF TO if_wd_context_node.
 
DATA lt_mara TYPE wd_this->elements_mara.
 
DATA ls_mara TYPE wd_this->element_mara.
 
DATA lo_componentcontroller TYPE REF TO ig_componentcontroller .
 
DATA lo_cmp_usage TYPE REF TO if_wd_component_usage.
 
DATA lo_interfacecontroller TYPE REF TO iwci_salv_wd_table .
 
DATA lv_value TYPE REF TO cl_salv_wd_config_table.
 
DATA lr_column TYPE REF TO cl_salv_wd_column.
 
DATA lr_input TYPE REF TO cl_salv_wd_uie_input_field.* navigate from <CONTEXT> to <MARA> via lead selection
  lo_nd_mara = wd_context->get_child_node( name = wd_this->wdctx_mara ).

*Fetching records from data base table
 
SELECT matnr ersda FROM mara INTO CORRESPONDING FIELDS OF TABLE lt_mara
   
UP TO 10 ROWS.

*Processing Records to set table non editable for 2,4 and 7th row and setting rest of the rows as editable.
 
LOOP AT lt_mara INTO ls_mara.
   
CASE sy-tabix.
     
WHEN 2 OR 4 OR 7.
        ls_mara-read_only = ABAP_TRUE.
     
WHEN OTHERS.
        ls_mara-read_only = ABAP_FALSE.
    ENDCASE.
   
MODIFY lt_mara FROM ls_mara.
  ENDLOOP.

*Bind the value of table
  lo_nd_mara->bind_table( new_items = lt_mara set_initial_elements = abap_true ).

*Instantiate the used component to ensure that the component usage of the ALV is active.
  lo_componentcontroller =   wd_this->get_componentcontroller_ctr( ).
  lo_cmp_usage =   wd_this->wd_cpuse_alv_test( ).
 
IF lo_cmp_usage->has_active_component( ) IS INITIAL.
    lo_cmp_usage->create_component( ).
  ENDIF.

  lo_interfacecontroller =   wd_this->wd_cpifc_alv_test( ).

*Using the interface object reference, calling the method get model will give the object reference for the class CL_SALV_WD_CONFIG_TABLE.
  lv_value = lo_interfacecontroller->get_model(
  ).
*Retrieving column to be in edit mode
 
CALL METHOD lv_value->if_salv_wd_column_settings~get_column
   
EXPORTING
     
id    = ‘MATNR’
    RECEIVING
     
value = lr_column.
*Creating UI Elmenent ‘INPUT FIELD’ to make the column editable
 
CREATE OBJECT lr_input
   
EXPORTING
      value_fieldname =
‘MATNR’.
*Assigning input field to the column
 
CALL METHOD lr_column->set_cell_editor
   
EXPORTING
     
value = lr_input.*To make the required row is editable
  lr_input->set_read_only_fieldname(
value = ‘READ_ONLY’ ).*Enabling editing mode in ALV table
  lv_value->if_salv_wd_table_settings~set_read_only( abap_false ).
 
CALL METHOD lv_value->if_salv_wd_column_settings~delete_column
   
EXPORTING
     
id = ‘READ_ONLY’.

ENDMETHOD.

Create Application and execute ALV:

Output display.

/wp-content/uploads/2013/05/3_221700.png

Note: We can use above example to make whole column editable just by deleting below statement among the above source code,

*To make the required row is editable
  lr_input->set_read_only_fieldname(
value = ‘READ_ONLY’ ).

Output display.

/wp-content/uploads/2013/05/4_221701.png

Regards,

Manjunath M

SAP-Consultant

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.