cancel
Showing results for 
Search instead for 
Did you mean: 

Delete all entities of a collection in one statement

pallavi_an
Participant
0 Kudos

Hi All,

I have created a web service to create/Update product.

Product - Root entity

Features - Child entity ( 0..n)

In this I have  to delete all child entities of relation Features and create new entities.

lv_feat =  lv_product->get_related_entities ( relation_name = Features ).

               while lv_feat is bound.

                         lv_feat->delete( ).

                         lv_feat = lv_features->get_next( ).

               endwhile.

               lv_bol_core->modify( ).

loop it_feat into wa_feat.

    lv_product->create_related_entity( relation_name = Features ).

endloop.

There are more than 200 entities for deletion. And more than 300 entries for creation. This is taking lot of time( more than 10 sec ). How can I improve its performance?

Is there a way to delete all entities in one method call? I am aware of method CLEAR. I think I can't use this in web service. When I used CLEAR method, after executing the LOOP statement I could see both previous and newly created entries in the relation.

Please provide some suggestions.

Thanks,

Pallavi

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Pallavi,

Create ZCL_CRM_BOL_ENTITY class and super class will be CL_CRM_BOL_ENTITY.

Create an attribute 'GR_BL_ENTITY' type ref to CL_CRM_BOL_ENTITY and two methods GET_INSTANCE and DELETE_FEATURES.

    

Method GET_INSTANCE

Parameters:

     Importing: IR_ENTITY TYPE REF TO CL_CRM_BOL_ENTITY          (Product entity)

     Exporting: RR_ENTITY TYPE REF TO ZCL_CRM_BOL_ENTITY      (Custom BOL entity)

Create method 'DELETE_FEATURES'.

-------------------------------------------------------------------

     FIELD-SYMBOLS: <rel_name> TYPE crmt_relation_name,

                    <rel>      TYPE crmt_genil_cont_relation.

     READ TABLE gr_bol_entity->container_proxy->data_ref->relations

            WITH TABLE KEY relation_name = 'Features' ASSIGNING <rel>.

     IF sy-subrc = 0.

       DELETE <rel>-objects WHERE table_line NE me .

     ENDIF.

------------------------------------------------------------------


<rel>-objects will contain all the features entity.

Now call these methods:

DATA: lr_product_entity type ref to cl_crm_bol_entity,

          lr_custom_bol_entity type ref to zcl_crm_bol_entity.

lr_product_entity ?= 'Get Product Entity'.

lr_product_entity ?= zcl_crm_bol_entity=>get_instance( EXPORTING ir_entity = lr_product_entity )..

lr_custom_bol_entity->delete_features( ).

Regards,

Ankit Gupta

pallavi_an
Participant
0 Kudos

Hi Ankit,

Thanks for your suggestion. Actually I had done one mistake in my code.

lv_feat =  lv_product->get_related_entities ( relation_name = Features ).

               while lv_feat is bound.

                         lv_feat->delete( ).

                         lv_feat = lv_features->get_next( ).

                         lv_bol_core->modify( ).

               endwhile.

               lv_bol_core->modify( ).

I had put modify statement inside while loop.

I did the same mistake inside loop while creating entities.

loop it_feat into wa_feat.

    lv_product->create_related_entity( relation_name = Features ).

   lv_bol_core->modify( ).

endloop.

lv_bol_core->modify( ).


Now I have put modify statement after loop. So it is taking 2 seconds to process 300 entries. I tried your way too. It works fine. thanks for your help.


Many Thanks ,

Pallavi

Former Member
0 Kudos

Hi Pallavi,

Thanks for marking it helpful.

But in problem description you did not mentioned that your are using lv_bol_core->modify() method in while loop.

-----------------------------------------------

lv_feat =  lv_product->get_related_entities ( relation_name = Features ).

               while lv_feat is bound.

                         lv_feat->delete( ).

                         lv_feat = lv_features->get_next( ).

               endwhile.

               lv_bol_core->modify( ).

--------------------------------------------------

In my solution there is no need to iterate each and every entity from collection (No need of while loop for delete the entities ). You can delete all the entities in one statement. I think it will increase the performance.

Regards,

Ankit Gupta

pallavi_an
Participant
0 Kudos

Hi Ankit,

I agree your suggestion is efficient. When I checked the total time for updating one product with 300 features, both approaches took 2sec.

So, I choose to put modify outside the loop. Its my mistake not to mention about Modify statement in the original post. I apologise for that.

Thanks and Regards,

Pallavi

Answers (0)