cancel
Showing results for 
Search instead for 
Did you mean: 

Implementing delete,create and update for associated entities

0 Kudos

Hi everyone,

- I have 2 entities : "products" based on "product" entity type (based on table ztable1) and "products2" entity set based on "product2" entity type (uses ztable2).

- I have an association between these two entities and association set between the entity sets as well, and the navigation property is also defined. I have currently implemented the "GET_ENTITY" and "GET_ENTITY_SET" methods of the associated property and they are working fine.

- I have to achieve the following: when i press delete in my SAP UI5 app, it deletes the appropriate field of "ztable1" and also the corresponding records in "ztable2".

  I already have the FIORI app which implements the ODATA service of delete for the entity set= "products". How can i achieve this for its association ("products2") as well?

Any help would be appreciated!

Accepted Solutions (0)

Answers (2)

Answers (2)

AshwinDutt
Active Contributor
0 Kudos

Hello Verma,

Deletion happens just on passing the Key('s).

As i understand, basically there would be some relationship between the tables and hence you would have created entities out of them and created association between them.

What is the Key for both tables ?

Do you have all the Key('s) in hand before you fire delete ? If yes its easy to delete.

Regards,

Ashwin

0 Kudos

Yes Ashwin. I understand that. Sorry i forgot to post. That was my main question. What is the odata query format for deleting from both the main table and the associated table? I didn't know where to fetch the 'key' value from for the associated set. For ex: for deleting from just the main entity we'd use delete option in REST client and use the query  /<entity set 1>('key'). How to do this for the main and associated entity sets both?

AshwinDutt
Active Contributor
0 Kudos

There is no such ready made query exists for deleting from both the main table and the associated table as you are expecting using Navigation Property.


It all depend on how delete operation is modeled and implemented in your case. Its case to case basis.

Query has to be build as per our requirement.

If you know Key fields of both table table->

DELETE DelOrderSet(SOId='1024') This would delete SO and Its all Items

DELETE DelOrderSet(SOId='1024',SOItm='10') This would delete only particular Item alone for SO number 1024

Now how your tables are associated ?

SB9
Active Participant
0 Kudos

You have to handle it through code. Delete main entity and all the associated child entities in the delete method of main entity.

In case you have queries on the delete, read the below oData specification.

11.4.5 Delete an Entity

A successful DELETE request to an entity's edit URL deletes the entity. The request body SHOULD be empty.  Singleton entities cannot be deleted.

On successful completion of the delete, the response MUST be 204 No Content and contain an empty body.

Services MUST implicitly remove relations to and from an entity when deleting it; clients need not delete the relations explicitly.

Services MAY implicitly delete or modify related entities if required by integrity constraints. If integrity constraints are declared in $metadata using a ReferentialConstraint element, services MUST modify affected related entities according to the declared integrity constraints, e.g. by deleting dependent entities, or setting dependent properties to null or their default value.

EkanshCapgemini
Active Contributor
0 Kudos

Hi Harshit,

I agree with Soujanya, this functionality needs to be handled at the ABAP level because its a part of business logic. Ideally the business logic part should sit at backend level and preferably not at UI level.

If you have a RFC FM which performs the delete operation, you need to Delete the product from both the tables in order to maintain integrity constraints. This way, you would need to fire delete only on 'product' entity but the ABAP code would delete the entity from product2 as well.

The OData specifications also convey the same.

Regards,

Ekansh

Former Member
0 Kudos

Same for create and update?

We should create/update main and all associated entities in the corresponding create/update methods of the main entity itself?

EkanshCapgemini
Active Contributor
0 Kudos

Hi Vrundha,

We have CREATE_DEEP_ENTITY for create scenarios with associations. For update scenario, you would update using single entities. Suppose there is one change in 'product' entity and another change in 'product2' entity, these 2 changes are separate changes related to their respective entities. So you need to trigger 2 update calls on respective entities or use $batch to combine those.

Now I come to business logic separation part, If the case is like on creation of 'product' entity there is an impact of this on 'product2' entity(some value gets changed in product2 or anything else), this needs to be handled in backend itself. This is a part of business logic.

Hope it clarifies.

Regards,

Ekansh

vijaybhaskarraju_vegesana
Active Participant
0 Kudos

Hi Harshit,

-> First of all how the entry is deleting from "ztable1".

-> The same code can be applied by replacing the table "ztable1" with "ztable2"

-> Write your code in the method/remote function call and call the same method in the  delete method of service builder where the code has already been written for deleting the entry in "ZTABLE1".

Regards,

Vijay

0 Kudos

- for deleting from "ztable1" - I am checking using odata queries in REST client. If it works fine,  I'll incorporate it into FIORI app. On this note, what is the odata query for deleting from both the main table and the associated table? I could not find this. For ex: for getting the associated data we use:  /<entityset1>('<key>')/<navigation property name from entityset 1 to entity set 2> . This was my main query.