cancel
Showing results for 
Search instead for 
Did you mean: 

Deleting Entities from a Collection

Former Member
0 Kudos

Hi Gurus

From the codes given below, i am successful in removing an entity from the collection (as seen from the debugger).

But as soon as i press Run on the debugger, the entity is still present (The attribute of the entity i opt to delete is being displayed in the web ui).

I want to permanently remove the entity from the collection.

Thanks in advance!

DATA: lr_col_wrap   TYPE REF TO cl_bsp_wd_collection_wrapper,

         lr_parent   TYPE REF TO cl_crm_bol_entity,

         lr_entity   TYPE REF TO cl_crm_bol_entity,

         lr_coll     TYPE REF TO if_bol_bo_col,

         lv_name     TYPE        string.

Data: lv_tdid       type TDID,

       lv_conclines  type CRMDT_CONC_TEXTLINES,

       lv_concfmt    type CRMDT_ITF_STRING.

   TRY.

* Get Collection Wrapper

       lr_col_wrap = typed_context->bttext->get_collection_wrapper( ).

       lr_entity ?= lr_col_wrap->get_current( ).

       CHECK lr_entity IS BOUND.

       lr_parent = lr_entity.

* read parent's entity

       WHILE lr_parent IS BOUND.

         lv_name = lr_parent->get_name( ).

         IF lv_name = 'BTTextH'.

           lr_entity ?= lr_parent.

           EXIT.

         ENDIF.

         lr_parent = lr_parent->get_parent( ).

       ENDWHILE.

       CHECK lr_parent IS BOUND.

       TRY.

           lr_coll = lr_parent->get_related_entities( iv_relation_name = 'BTTextHAll' ).

         CATCH cx_crm_genil_model_error.

       ENDTRY.

* get first entity

       lr_entity ?= lr_coll->get_first( ).

* loop and read the text

       WHILE lr_entity IS BOUND.

          lr_entity->IF_BOL_BO_PROPERTY_ACCESS~GET_PROPERTY_AS_VALUE( exporting iv_attr_name = 'TDID'  IMPORTING ev_result = lv_tdid ).

                IF lv_tdid = 'S005'.

                

* remove the entity

                     lr_coll->remove( lr_entity ).

                     lr_entity ?= lr_coll->get_current( ).

                else.

                      lr_entity ?= lr_coll->get_next( ).

                endif.

       ENDWHILE.

     CATCH cx_sy_move_cast_error.

       RETURN.

   ENDTRY.

Accepted Solutions (1)

Accepted Solutions (1)

former_member188098
Active Contributor
0 Kudos

Hi Lronmac,

After deleting entry from collection(after endwhile),display(add) new collection to display from which entry is deleted(lr_coll).You are not displaying your collection thats why deleted entry comming.try with ADD_COLLECTION or PUBLISH_CURRENT method of IF_BOL_BO_COL to display new collection.

       WHILE lr_entity IS BOUND.

          lr_entity->IF_BOL_BO_PROPERTY_ACCESS~GET_PROPERTY_AS_VALUE( exporting iv_attr_name = 'TDID'  IMPORTING ev_result = lv_tdid ).

                IF lv_tdid = 'S005'.

                 * remove the entity

                     lr_coll->remove( lr_entity ).

                     lr_entity ?= lr_coll->get_current( ).

                else.

  lr_entity ?= lr_coll->get_next( ).

                endif.

       ENDWHILE.

Regards,

Harish Kumar

Former Member
0 Kudos

Hi Harish,

A million thanks for the advice. I will let you know through this trend if i was successful with the additional codes.

regards,

Lronmac.

Answers (1)

Answers (1)

atulJaiswal
Participant
0 Kudos

Hi Lronmac,

Your logic is correct. This is how you should be deleting the entities from the collection.

However i would like to ask if you really need to delete logs? Since you are trying to delete TDID S005' which is note/text Logs.

Regards,

Atul

Former Member
0 Kudos

Hi Atul,

Thank you for the reply. yes i need to delete the logs in a particular event in CRM as this is the requirement from our customer.