cancel
Showing results for 
Search instead for 
Did you mean: 

How to insert data invloving 3 or more entities

Former Member
0 Kudos

In the picture you can see a simplified oData model of my service.

What I want to do is to create an IbaseHeader with Ibase Items (deep insert) and then once it has been created I want to add it as an object to an existing Work Order(Objects tab in the transaction IW32).

How do I do that?

Should I call the create deep entity IbaseHeader + Items from my SAPUI5 app and then on the "success" callback, call update method on the WorkOrderObject entity?

Or should I batch it in LUW and process it together in one go? If yes then how to do that exactly?

If anyone is aware of any FIORI apps doing something similar could you point me towards it?

Accepted Solutions (1)

Accepted Solutions (1)

kammaje_cis
Active Contributor

I would suggest you to process in batch.

In Your Gateway Code

In ChangeSet_Begin, for the mentioned entitites set deferred flag to true.

In Changeset_Process, collect all the changes and perform Create as well as WorkOrder update.

In Changeset_End, Commit all.

Your Gateway Request Body will look like this. (pseudocode). Basically single Batch and single changerequest. If you want sample request bodies, use CORE_SAMPLES test cases in Gateway Client.

--BatchRequest-1

--ChangeSet-1

POST IbaseHeader   (this is a deep call)

--ChangeSet-1

PUT WorkOrderObject

--ChangeSet-1--

--BatchRequest-1--
Former Member
0 Kudos

Thanks, that makes sense. Just wondering how to call that from UI5. oModel.create() for the deep insert but then I need the ID of the created IbaseHeader to update the WorkOrderObject with it .Can you write some pseudocode how that would look like ?

kammaje_cis
Active Contributor
0 Kudos

You need to start using 'BatchId'. Here is the pseudocode.

1. Set BatchID 'abc' as 'deferred'. (API on V2 odata model)
2. Create call mentioning batchID 'abc'
3. Update call mentioning batchID 'abc'
4. call submitchanges on odata model mentioning batchid 'abc'. (This is when create and update are sent as a single batch request).
Former Member
0 Kudos

Thanks. That's what I was thinking. There is only one bit I am missing. Where and how to pass the ID of the created IbaseHeader to the update of the WorkOrderObject as it is not known on the client side. Will that happen in changeset_process ?

kammaje_cis
Active Contributor
0 Kudos

In the changset_process, you first write code for creating IbaseHeader , so that you get the ID, then you call the update on WorkOrderObject.

Answers (1)

Answers (1)

maheshpalavalli
Active Contributor

it is recommended to use the batch approach.

Use OData model v2 version which has automatic batch handling and just loop through all the records and call odatamodel create method for all the entities at a time. Then a batch request is sent to backend.

Now in the backend, assuming it sap abap, implement, changeset begin and changeset process which belongs to APPL interface(not core, check for blogs in google, you will get plenty ). Now in the chageset begin, you need to set cv_defer as abap_true and in the chageset process method, you will find all the records that you have sent from the ui5 batch in an importing internal table.

Let me know if you need any help.

Best Regards,
Mahesh