cancel
Showing results for 
Search instead for 
Did you mean: 

Deleting row in a table

Former Member
0 Kudos

Hi All,

I have a table on screen and a Remove Button. On selecting a row in the table and clicking Remove, the selected row should be deleted from the table. After deleting, an empty space is left. I want the rows below to move up . How do i do that ?

Thanks,

Fathima

Accepted Solutions (1)

Accepted Solutions (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

What method are you using to delete the row? You should be manipulating the content and using the Node API to delete the element itself.

DATA lo_nd_sales_order TYPE REF TO if_wd_context_node.
  DATA lo_el_sales_order TYPE REF TO if_wd_context_element.
  DATA ls_sales_order TYPE wd_this->element_sales_order.
* navigate from <CONTEXT> to <SALES_ORDER> via lead selection
  lo_nd_sales_order = wd_context->get_child_node( name = wd_this->wdctx_sales_order ).
  lo_el_sales_order = lo_nd_sales_order->get_element( ).
  IF lo_el_sales_order IS INITIAL.
    exit.
  ENDIF.
  lo_nd_sales_order->remove_element(
    exporting
      element          = lo_el_sales_order ).

Answers (3)

Answers (3)

uday_gubbala2
Active Contributor
0 Kudos

Hi Fathima,

Its easy to delete selected row(s) from an table. If you are using multiple row selection then you can use the below logic to get he list of all rows selected by the user & then remove them from the context.

METHOD onactiondelete_rows .
  DATA:  wd_node TYPE REF TO if_wd_context_node,
         lt_node1 TYPE ig_componentcontroller=>elements_node,
         wa_temp  TYPE REF TO if_wd_context_element,
         lt_temp  TYPE wdr_context_element_set,
         row_number TYPE i VALUE 0.
 
 
  wd_node = wd_context->get_child_node( name = 'NODE' ).
 
  CALL METHOD wd_node->get_selected_elements
    RECEIVING
      set = lt_temp.
 
  LOOP AT lt_temp INTO wa_temp.
    wd_node->remove_element( EXPORTING element = wa_temp ).
  ENDLOOP.
 
  CALL METHOD wd_node->get_static_attributes_table
    EXPORTING
      from  = 1
      to    = 2147483647
    IMPORTING
      table = lt_node1.
 
  wd_node->bind_table( new_items = lt_node1 ).
ENDMETHOD.

If you are however using only LeadSelection for the table then just get the index/reference of the element at LeadSelection and then use the same for removing the row.

Regards,

Uday

Former Member
0 Kudos

Hi Uday,

I have an issue with the delete funciton,

Initially i used the followinf code for deleting a row from Table UI element.

lo_el_n2 = lo_nd_n2->get_element( ).

LO_ND_N2->REMOVE_ELEMENT( ELEMENT = LO_EL_N2 ).

This is removing the row from table but not from the database table ..for removing form database table i used the following code.

CALL METHOD LO_ND_N2->GET_STATIC_ATTRIBUTES_TABLE

IMPORTING

TABLE = it_n2 .

*delete record from internal table

DELETE TABLE IT_N2 FROM LS_N2.

*DELETE RECORD FROM THE TABLE

DELETE /BI0/PCS_UNIT FROM LS_N2.

This is deleting the row from database table but not from the Table UI element at instance ,when we refresf the Table UI element ,the row is removed...

Can u please tell me How to invoke both the codes into single code..so the when we click on Delete the row shld get deleted from table as well from database..

Regards

Ravikanth

uday_gubbala2
Active Contributor
0 Kudos

Hi Ravikanth,

If you want to have both your table & database in synchronization with each other after the delete operation then you can try do it this way.

1) Use both the REMOVE_ELEMENT & DELETE TABLE syntaxes on the delete button so that both the table & database get affected.

2) Create a supply function for the node which you are using to bind to your table. And now within this supply function write the code for extracting the data from the database and filling your context node.

Now when you press on the delete button just use the DELETE TABLE syntax. This would effectively remove the row from the database. Now call the INVALIDATE method of IF_WD_CONTEXT_NODE using your context nodes reference. This would result in the context nodes data getting invalidated & the supply function getting triggered by the system. This would then fetch the latest data from the database and display in your table.

Regards,

Uday

Former Member
0 Kudos

Dear Fathima,

If i am correct i hope that you want to delete the row in a table when u click(Lead select the table row) and when you press on the Remove button that row needs to be deleted .

Try to do this .

Step1. Intially i Remove button cal the method "Get_selected elements" or Get lead selection once you get the lead selected values into some work area say (ls_structure ).

step 2: now either by means of simple select query u can either delete the row elements.

step 3 : Now after you delete the ls_structure now use that RFC or Bapi or z select query which will fill your table with the updated values. I am sure surely you can solve your problem.

Try this.

Have A GoodDay!

Regards,

Sana

Former Member
0 Kudos

Hi Fathima,

You are not clear like how you are removing the table row.

If you are getting the empty space read the values using 'get_static_attributes_table' into an internal table and delete the rows with spaces and re bind it using 'bind_table'.

Hope this solves your problem.

Regards

Madhu.