Skip to Content
0

How to insert data invloving 3 or more entities

Mar 20, 2017 at 04:41 PM

167

avatar image
Former Member

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?

ibasemodelpic.png (20.5 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Krishna Kishor Kammaje
Mar 21, 2017 at 06:00 AM
1

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--
Show 4 Share
10 |10000 characters needed characters left characters exceeded
Former Member

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 ?

0

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).
0
Former Member

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 ?

0

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

0
Mahesh kumar palavalli Mar 21, 2017 at 04:00 PM
1

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

Share
10 |10000 characters needed characters left characters exceeded