cancel
Showing results for 
Search instead for 
Did you mean: 

Delete selected elements from table UI element

Former Member
0 Kudos

Hello @all,

i have an UI element table an delete Button. When i push the delete button, the selected elements in the table should be delete. How can i do this???

Regards

Chrisp

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Chrisp,

You need to follow the approach as follows.

1) You read the selected rows in any of the action method.

2) delete the record from internal/database table

3) Bind the updated table to the table ui element.

Make sure the selection is either 0.1 or 0.n of the corresponding context to enable multiple selection of rows in table ui element.

Regards

Anurag Chopra

0 Kudos
Hi Chris,

Please find the code you need to write.

This is the code you need to write in the Delete Action Push Button.

constants : c_delete type c value 'D'.
  DATA lo_nd_zhr_bi_country TYPE REF TO if_wd_context_node.
  DATA lo_el_zhr_bi_country TYPE REF TO if_wd_context_element.
  DATA ls_zhr_bi_country TYPE wd_this->element_zhr_bi_country.
  DATA:lt_selected_elements     TYPE wdr_context_element_set.
  DATA:lt_zhr_bi_country        type table of wd_this->element_zhr_bi_country.

*  DATA:lt_zhr_recs_2process   TYPE table of zhr_bi_country.

  DATA:lt_zhr_recs_2process   TYPE table of wd_this->element_zhr_bi_country.

  DATA lo_nd_zbi_maintain_table TYPE REF TO if_wd_context_node.
  DATA lo_nd_importing TYPE REF TO if_wd_context_node.
  DATA lo_nd_i_zhr_bi_country TYPE REF TO if_wd_context_node.
  DATA lo_el_i_zhr_bi_country TYPE REF TO if_wd_context_element.
  DATA ls_i_zhr_bi_country TYPE wd_this->element_i_zhr_bi_country.

  data: flag type abap_bool.


* navigate from <CONTEXT> to <ZHR_BI_COUNTRY> via lead selection
  lo_nd_zhr_bi_country = wd_context->get_child_node( name = wd_this->wdctx_zhr_bi_country ).

* navigate from <CONTEXT> to <ZBI_MAINTAIN_TABLE> via lead selection
  lo_nd_zbi_maintain_table = wd_context->get_child_node( name = wd_this->wdctx_zbi_maintain_table ).

* navigate from <ZBI_MAINTAIN_TABLE> to <IMPORTING> via lead selection
  lo_nd_importing = lo_nd_zbi_maintain_table->get_child_node( name = wd_this->wdctx_importing ).

* navigate from <IMPORTING> to <I_ZHR_BI_COUNTRY> via lead selection
  lo_nd_i_zhr_bi_country = lo_nd_importing->get_child_node( name = wd_this->wdctx_i_zhr_bi_country ).





* get element via lead selection
  lo_el_zhr_bi_country = lo_nd_zhr_bi_country->get_element(  ).

  lo_nd_zhr_bi_country->get_static_attributes_table( IMPORTING  table = lt_zhr_bi_country ).


  lt_selected_elements = lo_nd_zhr_bi_country->get_selected_elements( INCLUDING_LEAD_SELECTION = ABAP_TRUE )..

  LOOP AT lt_selected_elements into lo_el_zhr_bi_country.
   lo_el_zhr_bi_country->get_static_attributes( IMPORTING static_attributes = ls_zhr_bi_country ).
   if sy-subrc = 0.
     append ls_zhr_bi_country to lt_zhr_recs_2process.
     delete lt_zhr_bi_country where country = ls_zhr_bi_country-country and
                                     dateto = ls_zhr_bi_country-dateto.
   endif.
  ENDLOOP.

  lo_nd_zhr_bi_country->bind_table(  lt_zhr_bi_country[] ).
  lo_nd_i_zhr_bi_country->bind_table(  lt_zhr_recs_2process[] ).



* get element via lead selection
  lo_el_i_zhr_bi_country = lo_nd_i_zhr_bi_country->get_element(  ).

  DATA lo_el_importing TYPE REF TO if_wd_context_element.
  DATA ls_importing TYPE wd_this->element_importing.
  DATA lv_i_indicator LIKE ls_importing-i_indicator.

* navigate from <CONTEXT> to <ZBI_MAINTAIN_TABLE> via lead selection
  lo_nd_zbi_maintain_table = wd_context->get_child_node( name = wd_this->wdctx_zbi_maintain_table ).

* navigate from <ZBI_MAINTAIN_TABLE> to <IMPORTING> via lead selection
  lo_nd_importing = lo_nd_zbi_maintain_table->get_child_node( name = wd_this->wdctx_importing ).

* get element via lead selection
  lo_el_importing = lo_nd_importing->get_element(  ).

* set single attribute
  lo_el_importing->set_attribute(
    EXPORTING
      name =  `I_INDICATOR`
      value = c_delete ).

DATA lo_componentcontroller TYPE REF TO ig_componentcontroller .
lo_componentcontroller =   wd_this->get_componentcontroller_ctr( ).

  lo_componentcontroller->execute_zbi_maintain_table(
  ).


And in the BAPI call the code corresponding to Delete is

FUNCTION zbi_maintain_table.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(I_INDICATOR) TYPE  CHAR1
*"     REFERENCE(I_ZHR_BI_COUNTRY) TYPE  ZT_HR_BI_COUNTRY
*"  EXPORTING
*"     REFERENCE(E_ZHR_BI_COUNTRY) TYPE  ZT_HR_BI_COUNTRY
*"----------------------------------------------------------------------


  TYPES: BEGIN OF ty_zhr_bi_country,
           mandt      LIKE zhr_bi_country-mandt,
           country    LIKE zhr_bi_country-country,
           txtsh      LIKE /bi0/tcountry-txtsh,
           dateto     LIKE zhr_bi_country-dateto,
           member     LIKE zhr_bi_country-member,
           langroup   LIKE zhr_bi_country-langroup,
           continent  LIKE zhr_bi_country-continent,
           datefrom   LIKE zhr_bi_country-datefrom,
         END OF ty_zhr_bi_country.

  DATA: lt_zhr_bi_country TYPE TABLE OF ty_zhr_bi_country.
  DATA: lt_zhr_bi_country1 TYPE TABLE OF ty_zhr_bi_country.

  CASE i_indicator.
    WHEN 'S'.
      lt_zhr_bi_country[] = i_zhr_bi_country[].
      MODIFY zhr_bi_country FROM TABLE lt_zhr_bi_country[].

    WHEN 'D'.
      lt_zhr_bi_country[] = i_zhr_bi_country[].
      DELETE zhr_bi_country FROM TABLE lt_zhr_bi_country[].

    WHEN 'A'.
      lt_zhr_bi_country[] = i_zhr_bi_country[].
      DELETE lt_zhr_bi_country[] WHERE country IS INITIAL.
      INSERT zhr_bi_country FROM TABLE lt_zhr_bi_country.
  ENDCASE.

* Populate the final table which will be displayed on the screen

*select * from zhr_bi_country
*  into corresponding fields of table lt_zhr_bi_country1.

  SELECT
  a~country b~txtsh a~dateto a~member
         a~langroup a~continent a~datefrom
    INTO CORRESPONDING FIELDS OF TABLE lt_zhr_bi_country1
    FROM  zhr_bi_country AS a
    INNER JOIN /bi0/tcountry AS b ON a~country = b~country
                                AND langu = sy-langu+0(1).

  e_zhr_bi_country[] = lt_zhr_bi_country1[].

ENDFUNCTION.

Edited by: CMiddela on Jan 29, 2010 7:37 AM

0 Kudos

Hi Chris,

The logic is all the records selected by the user are filled into the records to be processed internal table.

This internal table is sent as a input field to the RFC function module and corresponding rows are deleted

from the database table.

Hope it helps.

Regards,

Chitrasen

Answers (0)