0

I want to pass an amount of storage units in one step. I need all storage units at once in the CREATE_ENTITY method in my OData service implementation (CREATE_ENTITY, or CREATE_DEEP_ENTITY, or...?), because I have to make a comparison of some values.

I tried a batch request. This doesn't work, because the CREATE_ENTITY method was called for each storage unit. So I could access only one storage unit in each call.

I also searched for tutorials concerning deep_entities. But I only find some with deep structures (head - items). But I have a flat structure (key: storage Unit) and want to pass this as table/array to my CREATE_ENTITY method. It should be possible to do this in SAPUI5.

As workaround I could pass all storage units into a string and pass this to the CREATE_ENTITY method. But that seems quite amateurish to me.

Here is how I invoke CREATE method:

onStartVert: function () {
    this.oContext = this.getModel().createEntry("/LenumIPunktSet", {
        success: this._successSave.bind(this),
        error: this._errorSave.bind(this)
    });
    var oBindingPath = {
        path: this.oContext.getPath()
    };
    this.getView().bindObject(oBindingPath);
    var sLenum;
    for (var i = 0; i < this._data.LePool.length; i++) {
        sLenum = this._data.LePool[i].lenum;
        this.getModel().create("/LenumIPunktSet", {
            lenum: sLenum
        });
    }
    this.getModel().submitChanges();
    this.getRouter().navTo("iPunkt02");
},

The signature for the CHANGESET_PROCESS method is:

CT_CHANGESET_DATA   TYPE /IWBEP/IF_MGW_CORE_SRV_RUNTIME=>TY_T_CHANGESET_DATA    
/IWBEP/CX_MGW_BUSI_EXCEPTION        Business Exception
/IWBEP/CX_MGW_TECH_EXCEPTION        Technical Exception

So, by now there is no table IT_CHANGESET_REQUEST available. My entity type has only this one field (lenum) I need as key.

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
Julia
  • 49
  • 1
  • 1
  • 9

1 Answers1

1

The key is to implement a changeset.

In your DPC_EXT redefine the following three methods:


The method CHANGESET_BEGIN will activate the batch processing.

METHOD /iwbep/if_mgw_appl_srv_runtime~changeset_begin.
    cv_defer_mode = 'X'.
ENDMETHOD.
METHOD /iwbep/if_mgw_appl_srv_runtime~changeset_end.
* empty
ENDMETHOD. 

The method changeset_process will contain the logic. it_changeset_request contains all entities which are part of this batch request.

METHOD /iwbep/if_mgw_appl_srv_runtime~changeset_process.
    LOOP AT it_changeset_request ASSIGNING FIELD-SYMBOL(<fs_changeset_request>).
        " <fs_changeset_request>-request_context->get_request_details( ) << which entity is it?
        " <fs_changeset_request>-operation_type << is it CREATE, UPDATE or DELETE?
        " <fs_changeset_request>-entry_provider->read_entry_data( ... ) << read entity into structure
    ENDLOOP.
ENDMETHOD.

See this blog for some details.

Marc
  • 6,051
  • 5
  • 26
  • 56
  • Thank you so much. I will try this. – Julia Jul 30 '20 at 12:47
  • Thank you, for your answer. I implemented these methods, but it seems that in method "changeset_process" I there is only a changing table "it_changeset_data" available. And this one is empty. Do you have any idea what I made worng? – Julia Jul 31 '20 at 10:42
  • How do you trigger the CREATE in the frontend? Can you update your question? If everything is set up correctly then every create call will be bundled into a single $batch request (you can see this in the network tab). Then in the backend `it_changeset_request ` should contain all created (or updated or deleted) entities. – Marc Jul 31 '20 at 11:14
  • Sorry, there is a little mistake in the comment above and I cant change it anymore: In method _/iwbep/if_mgw_core_srv_runtime~changeset_process_ is a changing table _CT_CHANGESET_DATA_ . And this one is empty when I watch at it in debugger. I dont find many information regarding this table. Only _it_changeset_request_, but this one is not available as importing or changing parameter. – Julia Jul 31 '20 at 11:16
  • Ah I see your problem. Yes, `changeset_process` exists twice. First from the interface `/IWBEP/IF_MGW_APPL_SRV_RUNTIME`. Second from the interface `/IWBEP/IF_MGW_CORE_SRV_RUNTIME`. Use the **first** one (as can be seen in my answer). It will contain the importing parameters. Also use the **first** one for `changeset_begin` and `changeset_process`. – Marc Jul 31 '20 at 11:21
  • Ah ok, I changed it. I don't see yet that this methods which I just redefined are called. But I will go on trying. Many many thanks for your help. Let me know if I can show my appreciation! – Julia Jul 31 '20 at 11:40
  • Did you delete the "wrong" changeset_begin/process/end? – Marc Jul 31 '20 at 11:52
  • No, not yet. I will delete the wrong definitions ASAP and give feedback. Thank you! – Julia Jul 31 '20 at 12:21