cancel
Showing results for 
Search instead for 
Did you mean: 

Create Deep Entity - Custom code

Former Member
0 Kudos

Hi!

Just getting started with OData and NW GW, and as such I'm using a SAP CAL instance of ABAP/BW 7.40 on HANA Trial

I have come so far in my training endeavors that I need to build a function to create new Header and Item data in one call.

I'm trying to follow this blog but in that example the number of items per header are fixed, and I need to be able to create n-numbers of items (just as in BAPI_SALESORDER_CREATEFROMDAT2).

Also, I will define number ranges in NRO and use function "NUMBER_GET_NEXT" in order to increment each new HeaderID.

Any ideas on how to do this?

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Magnus,

I've checked the referenced blog and I can't see anything that suggests that item count is fixed. Can you share your understanding of why you think this is so? Other than changing the cardinality, it would be very difficult to define a service that had a fixed item count (and this could only be 1).

Also, I would not advise you to use the key/value based item entities as in this example. That is very bad practice in OData as there is no definite entity exposed. It seems to have been copied from one of the worst examples of OData services in Fiori (Timesheets). There is a reason why SAP wrote it that way, for custom services the definition should be more-specfic, i.e. properties of entities describe what they are!

Regards

Ron.

Former Member
0 Kudos

Hi Ron!

I'm actually trying to use your "Outside-In" approach 

Anyway, I had another look and as you pointed out... The cardinality is 1:n in the example.

What I'm really doing is following the 2012 H2Guide - Create Complex Business Entities

I might have posted in the wrong sub-forum since what I'm after is an approach to create the function that create the Header and connected Items in one go.

My custom tables look like this

LIST_HEADER HeaderID, HeaderData1,HeaderData2...

LIST_ITEM HeaderID, ItemID, ItemData1,ItemData2....

Former Member
0 Kudos

Possibly a misunderstanding here (by one of us), but I think you want to post more than one order plus items at a time? That is a different scenario.

If this is so, you cannot do it in the way you are attempting. The clue is in the method name CREATE_DEEP_ENTITY (singular) - you create one starting entity and all of the required sub-branches.

If you wish to place more than one deep insertion into a request, you have to consider $batch or a revision of your model. For the latter you could define an entity called MassInsertOrder, which would thereby enable you to have the orders and items as the sub-branches. MassInsertOrder is a virtual entity and does not represent a persistent backend object - as such you could only POST to it or return a dummy on GET.

$batch is a safer option as it supports SAP LUW processing and won't commit until the whole request is done.

Re; the H2Guide, it's rather old and overly complex. It doesn't use service builder and could be done with a lot less coding. Maybe not the best example if you are still learning, but I know there aren't many examples to crib from. I'm not sure why you have a problem with the backend creation function, the example code here uses a useable function for the job.

If I were you I would get a single deep inserted order working before considering any mass processing - you would not need to rework much, if anything.

Former Member
0 Kudos

It's actually a misunderstanding (English is not my mother-tongue )

I am looking for a simple way to create the function to post 1Header and its nItems to my custom Header and Item tables.

Yeah, the example code uses the BAPI_SALESORDER_CREATEFROMDAT2 but, since I'm in a trial version of SAP NW ABAP 7.40, No ECC Data exists...

Thought there would be other examples of Header-Item "creation-modules" that I could implement for my custom tables.

I'm trying to invent the wheel again on purpose, in order to really grasp the subject, knowing that in a customer project, Function Modules will already be in place for most of our desired OData actions.

Former Member
0 Kudos

OK, if you are not constrained by an actual ECC instance, you can just insert directly into custom tables. I don't consider the use of embedded functions necessary for proving that data is received and stored if you are just testing the service concept. It's not going to help you learn any extra in Gateway/OData terms to build FM's.

Good luck

Ron.