cancel
Showing results for 
Search instead for 
Did you mean: 

Update operation of Multiple Items using Deep entity method, code based approach

former_member209217
Active Contributor
0 Kudos

Hello Everyone,

I am aware that create_deep_entity method is generally used for creating deep entities in OData. However , If we need to perform an update operation on multiple items without using $Batch functionality we need to manually implement a code based approach on  create_deep_entity method using extension _*EXT class. How can this be achieved ?Generally this method gets called when we are performing a deep entity operation and the same cannot be applied while doing an update  request on multiple items. Please advice.

Best Regards,

Lakshman.

Accepted Solutions (1)

Accepted Solutions (1)

JyotiD
Active Participant

Hi Laksham,

How about writing an additional piece of code to identify if request is for create or update in Create Deep Entity itself.

As when creating you will not be having key value, and when updating you should be having key value for which you are updaing.

Lets say after reading Payload in structure.


io_data_provider->read_entry_data( IMPORTING es_data = ls_struct ).

if ls_struct-key is initial.  "Create

<Your Create Logic>

elseif ls_struct-key is not initial. "Update

<Your Update Logic>

endif.

Regards,

Tarun

former_member209217
Active Contributor
0 Kudos

Hi Tarun,

Agree it as an alternative , but per coding standards will it always work. There should be some official way to do that. Any Ideas?

And one more question, We are doing an update operation and we're  going to select PUT operation. But create_deep_entity is purely for POST operation. In what way this is going to be trigerred during an PUT operation and we dont have a method like update_deep_entity as well?

Best Regards,

Lakshman.

EkanshCapgemini
Active Contributor
0 Kudos

Hi Lakshman,

There is no such thing like 'Deep Update' for OData v2 and thus not supported in SAP Gateway as well. As per the standard, 'Create_Deep_Entity' is for CREATE operation only thus can not be triggered by PUT operation. However you can use it as a workaround. In this case, you have to trigger a POST call for both the operations(Create/Update).

The recommended approach as per the standards is to use $batch 'changeset at once'.

Regards,

Ekansh

JyotiD
Active Participant
0 Kudos

Hi Laksham,

Well I don't found Update deep entity method in framework, so had to go with this workaround and It saved me many time without any issues.

As per this you will have to use POST operation only in both case (Create, Update).

Only diff will be in your Payload, while Create you don't have to pass header key(i.e. null values) and when doing Update provide the value against key Property in Payload.

Eg. You are working with SO and SO Item, so when you are creating new sales order you have to pass null values for sales document (vbeln) in your payload, so your logic will do an create operation and new sales order will be created.

and when updating sales order, pass the sales document in payload, identify it in create deep entity method and your update logic will be executed.

Once using POST, create deep entity method is triggered you can identify within code, which operations to be performed.

Ashwin Dutt REkansh Saxena  Even I would like to know, if there is better or official approach for this.

Regards,

Tarun

EkanshCapgemini
Active Contributor
0 Kudos

Hi Tarun,

The standard way to achieve this would be using $batch with 'chagneset at once/changeset in differ mode' . You can find more details about this in the below mentioned blog link

However there is some performance gain in using Deep_Insert workaround in contrast to batch.

This topic has already been discusses quite a lot in past. One can check this link (one of many on same topic )

Regards,

Ekansh

former_member209217
Active Contributor
0 Kudos

Yes, This has been widely discussed in the forums.

Thanks everyone for your help.

Answers (2)

Answers (2)

EkanshCapgemini
Active Contributor

Hi Lakshman,

The easiest way would be to have an additional property of flag which contains the operation that you are trying to perform ('C' = Create, 'U' = Update). Now when you hit the POST call with navigation property of your line items, you can check the flag and change your functionality accordingly in the Deep_Insert method.

Let us know if we failed to understand your question in the correct way.

Regards,

Ekansh

former_member209217
Active Contributor
0 Kudos

Ekansh,You're clear on what I have asked. Even I had the same thought , An additional property as an entity .But what would be the best way to update this flag.

You mean in the front end itself we're going to design POST and PUT  URL in such a way that this Flag  parameter is populated based on the operation we perform? Am I Right

EkanshCapgemini
Active Contributor
0 Kudos

Yes, you are correct.

JyotiD
Active Participant
0 Kudos

My Bad. Already quite a lot happened in discussion, I can see now....

Ashg1402
Contributor
0 Kudos

Hi lakshman,

  I also face the same problem some time back, there is no official way to do so as there is not such provided in '_EXT' class. I will agree with the approach suggested by TARUN.

Regards

Ashish