cancel
Showing results for 
Search instead for 
Did you mean: 

Custom button in WD-ALV for inserting a new editable row

former_member210563
Participant
0 Kudos

Hi,

I am in doubt about how to proceed with an ALV component in my view. I have arranged it in my WDDONINT that after a search for data only 2 of the 3 fields are allowed to be edited.

However, I have declared a custom button for Insert Line, which is to be used for inserting a new row where all 3 fields are to be editable.

Will I have to create an event handler for INSLIN function with an insert of a new line ?

The ALV will then have to contain both existing records with display only for the first field and new records that are to be inserted using the Insert Line button. Is that possible ?

The code for WDDOINIT is below:

METHOD wddoinit.



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

* Add toolbar for functionality (INSERT, DELETE etc.)

* and

* Set table fields Editable for start and end date

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





  DATA :  lt_columns TYPE salv_wd_t_column_ref,

          ls_columns TYPE salv_wd_s_column_ref.

  DATA    lo_cmp_usage TYPE REF TO if_wd_component_usage.



* Declarations for additional button for insert new line



  DATA: lr_cmp_usage TYPE REF TO if_wd_component_usage.

  DATA: lr_intf_alv TYPE REF TO iwci_salv_wd_table.



**



  lo_cmp_usage =   wd_this->wd_cpuse_alv_test( ).

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



  DATA lv_value TYPE REF TO cl_salv_wd_config_table.

  lv_value = lo_interfacecontroller->get_model(

  ).



* set header text for the table view



  DATA: lr_table_settings TYPE REF TO if_salv_wd_table_settings.

  DATA: lr_header TYPE REF TO cl_salv_wd_header. lr_table_settings ?= lv_value.



  lr_header = lr_table_settings->get_header( ). lr_header->set_text( 'Assignment of WBS to consultants' ).



  CALL METHOD lv_value->if_salv_wd_column_settings~get_columns

    RECEIVING

      value = lt_columns.



  DATA: lo_sdatum TYPE REF TO cl_salv_wd_uie_input_field.

  DATA: lo_edatum TYPE REF TO cl_salv_wd_uie_input_field.



* Open required fields in existing records for editing



  LOOP AT lt_columns INTO ls_columns.

    CASE ls_columns-id.

      WHEN 'SDATUM'.

        CREATE OBJECT lo_sdatum

          EXPORTING

            value_fieldname = ls_columns-id.

        ls_columns-r_column->set_cell_editor( lo_sdatum ).



      WHEN 'EDATUM'.

        CREATE OBJECT lo_edatum

          EXPORTING

            value_fieldname = ls_columns-id.

        ls_columns-r_column->set_cell_editor( lo_edatum ).

    ENDCASE.



  ENDLOOP.



  CALL METHOD lv_value->if_salv_wd_table_settings~set_read_only

    EXPORTING

      value = abap_false.



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

** Add button for insert line

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



  DATA: l_ref_cmp_usage TYPE REF TO if_wd_component_usage.



  l_ref_cmp_usage =   wd_this->wd_cpuse_alv_test( ).

  IF l_ref_cmp_usage->has_active_component( ) IS INITIAL.

    l_ref_cmp_usage->create_component( ).

  ENDIF.



*Call Get_model() of Interface Controller to set changes to the output

*table



  DATA: l_ref_interfacecontroller TYPE REF TO iwci_salv_wd_table .

  l_ref_interfacecontroller =   wd_this->wd_cpifc_alv_test( ).

  DATA:

    l_value TYPE REF TO cl_salv_wd_config_table.



  l_value = l_ref_interfacecontroller->get_model(

  ).



* Hide not needed buttons on standard toolbar



  lv_value->if_salv_wd_std_functions~set_export_allowed( abap_false ).

  lv_value->if_salv_wd_std_functions~set_edit_append_row_allowed( abap_false ).

  lv_value->if_salv_wd_std_functions~set_edit_insert_row_allowed( abap_false ).

  lv_value->if_salv_wd_std_functions~set_edit_delete_row_allowed( abap_true ).

  lv_value->if_salv_wd_std_functions~set_edit_check_available( abap_false ).



*Add custom button for Insert Line in table



  DATA:lr_function TYPE REF TO cl_salv_wd_function,

       lr_toggle_button TYPE REF TO cl_salv_wd_fe_button,

       lref_toggle_button TYPE REF TO cl_salv_wd_fe_a_button.



  lr_function = l_value->if_salv_wd_function_settings~create_function( id   = 'INSLIN' ).



  CREATE OBJECT lr_toggle_button.

  lref_toggle_button ?= lr_toggle_button.



  lr_toggle_button->set_text( 'Insert Line' ).

  lr_function->set_editor( value = lr_toggle_button  ).







ENDMETHOD.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

step to do:-

1. create two attribute of type wdy_boolean in your node which is mapped with alv data

2. in do init make all 3 column inputfield but

use method

  <inputfield_celleditor_name>-> set_read_only_fieldname(  <give attribute you haev created with type wdy_boolean> ).

3. after using above method your column editable property witll depend on attribute you pass in above method.

4 you can manipulate attribute value as per your need

hope this helps

Answers (1)

Answers (1)

former_member199125
Active Contributor
0 Kudos

Once you added the button in alv tool bar, under your data node add one attribute of type wdy_boolean and bind to read only property of  input field of column editor.

for existing data, pass attribute value as abap_true for display..

for new row under button action, pass one dummy work area to internal table in that pass attribute value as abap_false,so that new column will be in editable mode.

Regards

Srinivas