cancel
Showing results for 
Search instead for 
Did you mean: 

issue while deleting a row from a table

Former Member
0 Kudos

Dear friends,

i am getting an issue while deleting a row from a table, pls check screen shots , the first screen shot is my table contents

when i delete 2 row , the second row is deleting properly like below screen shot

but i want like below screen shot , Col1 contents should be like pic 1 . could any one pls let me know how to solve this issue.

Thanks

Vijaya

Accepted Solutions (1)

Accepted Solutions (1)

ramakrishnappa
Active Contributor
0 Kudos

Hi Vijaya,

Actually, you are not trying to delete whole entry of 2nd row, instead you are clearing other columns value and retaining the key COL1 at 2nd row

Is it internal table? if so


  data ls_wa like line of lt_data.

          clear ls_wa.

          "Now, we need to modify data of 2 nd line

          ls_wa-col1 = 2. "if col1 is numeric

         

          modify lt_data from ls_data transporting all fields.

Hope this helps you.

Regards,

Rama

Former Member
0 Kudos

hi rama

how to capture the selected row of the table , here i can delete 2nd row, 3rd row.... it depends on user, could you pls let me know how to capture selected and then i have to delete that row

Thanks

Vijaya

former_member184578
Active Contributor
0 Kudos

Hi,

You can simply read the context node using wizard, which will give you the selected row values( get_static_attributes( ) method ).

Or, you can use get_lead_selection_index( )method of context node to get the selected row index.

Regards,

Kiran

ramakrishnappa
Active Contributor
0 Kudos

Hi Vijaya,

Let us say user has selected a row / many rows and  click on delete button. To clear the data of selected row(s), write the below logic


data lo_node type ref to if_wd_context_node.
data lo_el   type ref to if_wd_context_element.

data ls_data type wd_this->element_my_node.
data ls_temp  like ls_data.

DATA lt_selected_el   TYPE wdr_context_element_set."selected elements

lo_node = wd_context->get_child_node( name = wdctx_my_node ).

  lo_nd->get_selected_elements(
            RECEIVING set = lt_selected_el ).

LOOP AT lt_selected_el INTO lo_el.
              lo_el->get_static_attributes(
                           importing
                      static_attributes = ls_temp ).

"clear data
clear ls_data.

ls_data-col1 = ls_temp-col1.

"set the cleared data back to context

  lo_el->set_static_attributes(
  Exporting
  static_attributes = ls_data ).

ENDLOOP.

Replace the "my_node" with your context node name.

It works for multiple rows as well.

Hope this helps you.

Regards,

Rama

Answers (3)

Answers (3)

former_member222068
Active Participant
0 Kudos

Hi Vijaya,

1. Get the selected row first.

lo_el_delete = wdevent->get_context_element( 'CONTEXT_ELEMENT' ).

lo_el_delete->get_static_attributes(  importing static_attributes = ls_delete

).

2. Clear the values of all the attributes apart from column1.

ls_delete-column1 = 'Column1'.

ls_delete-column2 = ' '.

ls_delete-column3 = ' '.

ls_delete-column4 = ' '.

3. set the data to the node at the same index

Thanks & Regards,

Sankar Gelivi

Former Member
0 Kudos

Hi vijaya,

please try this code, it will help you.

DATA : it_rows  TYPE wdr_context_element_set,

          wa_rows LIKE LINE OF it_rows.

   DATA lo_nd_table TYPE REF TO if_wd_context_node.

    DATA lt_table TYPE wd_this->elements_table.

   DATA lo_el_table TYPE REF TO if_wd_context_element.

   DATA ls_vbap TYPE wd_this->element_table.

DATA: ld_index TYPE i.

data value TYPE sy-index.

* navigate from <CONTEXT> to <table> via lead selection

   lo_nd_table= wd_context->get_child_node( name = wd_this->wdctx_table ).

* @TODO handle non existant child

* IF lo_nd_table IS INITIAL.

* ENDIF.

* get element via lead selection

* alternative access  via index

* lo_el_table = lo_nd_table->get_element( index = 1 ).

* @TODO handle not set lead selection

   IF lo_el_table IS INITIAL.

   ENDIF.

* navigate from <CONTEXT> to <table> via lead selection

   lo_nd_table = wd_context->get_child_node( name = wd_this->wdctx_table ).

* @TODO handle non existant child

* IF lo_nd_table IS INITIAL.

* ENDIF.

   lo_nd_table->get_static_attributes_table( IMPORTING table = lt_table ).

* @TODO handle non existant child

* IF lo_nd_table IS INITIAL.

* ENDIF.

** @TODO compute values

** e.g. call a model function

*

* navigate from <CONTEXT> to <table> via lead selection

   lo_nd_table = wd_context->get_child_node( name = wd_this->wdctx_table ).

* @TODO handle non existant child

* IF lo_nd_table IS INITIAL.

* ENDIF.

** @TODO compute values

** e.g. call a model function

*

it_rows  =  lo_nd_table>get_selected_elements( ).

   CALL METHOD lo_nd_table->GET_LEAD_SELECTION_INDEX

   RECEIVING

     INDEX  = value .

  LOOP AT it_rows INTO wa_rows.

     CALL METHOD wa_rows->get_static_attributes

       IMPORTING

              static_attributes = ls_table.

     READ TABLE lt_table INTO ls_table WITH KEY col1 = ls_table-col1.

      ld_index = value.

          ENDLOOP.

   CLEAR : ls_table-col2,

         ls_table-col2.

   MODIFY lt_table INDEX ld_index FROM ls_table.

  lo_nd_table->bind_table( new_items = lt_table set_initial_elements = abap_true ).

Former Member
0 Kudos

Hi vijaya laxmi,

try this.

Loop at lt_table into ls_table.

if sy-tabix ne 1.

clear : ls_table-col2,ls_table-col3.

modify lt_table from ls_table.

endif.

endloop.

Regards,

Ravikiran.K