SAP Netweaver Gateway and OData. Section IX. How to Include Several Entities in a Single OData Service Operation

Multiple Operations in one Call

In SAP Netweaver and OData Services, how can I add several entities (relationship data) in a single operation?

The background of today’s post: I had to update one of the entity sets with numerous entries in a single call (one header and multiple line items) while working on a Fiori PoC (Proof of Concept) for a customer. I attempted to use Create Operation on an entity set that contained many entries, but for some reason, only the first record was ever supplied to the model when the call was made. Once more, we must call the Create/edit Header operation first, followed by the Call Create/Update Items Operations call, if we wish to create or edit one header and several items.

Following some investigation, I discovered that SAP has the ability to perform these kinds of tasks in an OData Model. We refer to this as DEEP INSERT.

In order to update business data where there is a parent-child relationship and we want to create all relevant data in one call, we will learn how to define and call a DEEP INSERT operation in this exercise.

In my circumstance, I’m trying to assign multiple components to an ALM Order (SAP transaction IW31/32). extensively utilized for work orders. Therefore, in this case, the heading is an order operation and the items are components that are assigned to the order operation.

When you open an existing order in transaction IW32/33, select the Operations tab, and double click on it, you will be sent to the operation’s details page, where you can add components.

odata service
add multiple rows in an entity without having to call CREATE/UPDATE operations multiple times.

This talk aims to explain how to construct an operation in the data model that allows us to add numerous rows to an entity without requiring repeated calls to the CREATE/UPDATE procedures.

If you are unfamiliar with OData and SAP Netweaver Gateway, please see How to construct your first OData Service.

Using Services in my Proof of Concept

In my instance, the data model looks like this.

data model
OData Services
Hierarchy of business data

Notification of Services Order of Services The SR_ServiceOrder_Operation operationSR_ServiceOrder_ComponentSet is the navigation. (Reference: SR_SERVICEORDER_COMPONENTSET; Technical Name)SR_ServiceOrder_Component components

To get the technical name of the navigation that is marked in green above, take a snapshot of the DATA MODEL.

DATA MODEL for identifying the technical name

First, redefine the method “CREATE_DEEP_ENTITY” in the DPC Extension class of the backend OData service (IWBEP/IF_MGW_APPL_SRV_RUNTIME).

I hope you are familiar with CRUD functions. If not, look at OData’s CRUD Operations.

Initially, we must design a structure that precisely captures the XML representation of the data that the user interface will send.

The simple solution to determine the structure is as follows:

Gateway Client and conduct a $expand query on the header entity set.

Orderid=’4927185′,Activity=’0010′) in the SR_ServiceOrder_OperationSet (/sap/opu/odata/SAP/Z_SERVICE_REQUEST_SRV_03)?$expand=SR_ComponentSet_ServiceOrder

(In the example above, the item is the SR_ServiceOrder_ComponentSet entity set, and the header is the SR_ServiceOrder_OperationSet entity set. The data for the header entity set is located in the section with the key, (Orderid=’4927185′,Activity=’0010′).I hope that by now, everyone is aware of these. Guys, get moving! Part IX is where we are right now.

Now, in order to post data, we must call the POST method and modify the URI to point to the header. For the system to call the DEEP INSERT method, the updated URI from the user interface (frontend) should be as follows.

SAP Z Service Request SRV 03 Operation Set /sap/opu/odata/SAP/ServiceOrder_OperationSet

Please Note: Based on the URI, MODEL determines whether to call a DEEP INSERT method or a CREATE/UPDATE method. If MODEL discovers the $expand argument in the URI, it invokes the DEEP INSERT method; otherwise, it calls the standard CREATE/UPDATE action.Thus, it is imperative that the UI developer provide the URI in the correct manner.

There will be a response to this inquiry.This response can be used as a request, and a POST method can be executed.MODEL is aware that this,

IO_DATA_PROVIDER

The XML payload is obtained from the user interface (UI) using the importing parameter IO_DATA_PROVIDER in the class. A local structure that can house the data from the UI payload must be created.

We have established a structure called “zpm_sr_service_order_operation” with the following structure in response to my request.

OData handling

The field that is highlighted and intended to contain multiple entries must have the same name as the navigation’s technical name.(In this case, one-level relationship data are being discussed. The same procedure must be used if multi-level relationship data is required.

DATA MODEL for identifying the technical name

Put the reasoning in the method itself: /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_DEEP_ENTITY

DATA: BEGIN OF lw_data.
             INCLUDE TYPE zpm_sr_service_order_operation.
DATA: END   OF lw_data.

Please take note that the entity type of the operation (Header) in the preceding definition is represented by the Include type zpm_sr_service_order_operation, and the entity type of the components (Items) is represented by the table type zpm_sr_service_order_comp_tt. The field that would house the ITEM data—in our case, the components—should have the same name as the navigation, such as SR_ServiceOrder_ComponentSet.

TRY.
          io_data_provider->read_entry_data(
              IMPORTING
                   es_data                      = lw_data ).
          CATCH /iwbep/cx_mgw_tech_exception.    "
ENDTRY.

The code mentioned above will read the XML payload from the user interface, convert it, and then populate the lw_data local structure. The deep structure that we have already defined is the lw_data. If we dig deeper, we can create or post data in SAP by calling our own unique FM/BAPI.

The correct response data must be entered into the exporting parameter ER_DEEP_ENTITY once the BAPI/custom FM has completed the data posting. The local variable IW_DATA and the exporting parameter ER_DEEP_ENTITY will share the same structure. All we have to do is invoke the extension class’s standard method “COPY_DATA_TO_REF” like follows:

copy_data_to_ref(
         EXPORTING
                is_data = lw_data
         CHANGING
                cr_data = er_deep_entity ).
copy_data_to_ref

Note that the approach we are re-implementing is generic in nature and may be applied to a variety of DEEP INSERTs on various entity sets inside that service. As a result, we must write our code inside of an appropriate IV_ENTITY_SET_NAME check. Since the “SR_ServiceOrder_OperationSet” is the IV_ENTITY_SET_NAME in my scenario, all of my reasoning should fall into the check for this entity set.

The way this function handles exceptions is another crucial aspect. For informing the user of any errors on the user interface, the method provides two exceptions: /IWBEP/CX_MGW_BUSI_EXCEPTION & /IWBEP/CX_MGW_TECH_EXCEPTION. Use the appropriate exception class depending on whether it is a technical or business exception.

In my instance, because my API has built-in validations that allow it to return failure messages, I have handled it as

DATA:  ls_t100key TYPE scx_t100key.
ls_t100key-msgid = ls_return-id.
ls_t100key-msgno = ls_return-number.
ls_t100key-attr1 = ls_return-message.

*ls_return is the BAPI return structure

RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
EXPORTING
textid = ls_t100key.

Step 2: UI development with the SAPUI5 viewpoint

Collect all of the input data that is needed to construct the data, then format the data using the entity set and navigation that the service maintains. If there are inconsistencies, XML cannot parse it. SAP has not disclosed any restrictions on the Deep Entity Create set. Here, we attempted to create a Deep Entity at level 4.

Data must be organized in the parent-child relationship manner as indicated below:

sapui5

Root Element CreateData (1:1)

requestChildSO: CreateData’s offspring (1:1)

functioningChild: The one making the requestChildSO (1:n)

child: the kid involved in the operationChild (in 1:n)

level n

See Also: An ABAPer’s Challenge in Building Their First SAPUI5 App.

sapui5 for abapers

It has a depth of n levels. Thus, there are no restrictions. In a similar manner, CreateData will parse XML input that is needed for creation.
Here is the call model for creating data.Root Parent Entity set is called EntitySet.

Call Model for creation of Data

Get the Source Code by Clicking Here.

I hope this post may be useful to you if you find yourself in a similar circumstance to mine.We’re all new to SAPUI5 and OData, and we pick up new skills every day.Please share with us any recent insights you may have gained from using SAP.We are pleased to publish it under your name.Every post we write is the result of extensive planning, testing, and writing.It would be greatly appreciated by our team if you could forward this link to at least five friends or coworkers who you believe would find our content useful.

you may be interested in this blog here:-

SAP ABAP OData APIs: Unlocking the Power of Integration

SAP GST Configuration Step-by-Step Guide: Mastering GST Integration in SAP

Seamless Data Integration: Mastering Data Import in Salesforce

Related Posts

SAP XI/PI – Invoice Attachment Transfer from ARIBA to VIM

The documents that are connected to the invoice in the Ariba Network system should be transferred to the VIM system via PI Integration as part of the Ariba Supplier Invoice…

Attachments for SAP XI/PI – ARIBA Invoices sent via PI to S/4HANA

Integration with SAP systems has never been more intriguing, especially with Ariba, Workday, Concur, Successfactors, Fieldglass, Hybris, and other satellite cloud solution vendors banging on doors every day. 🙂 I…

Leave a Reply

Your email address will not be published. Required fields are marked *

You Missed

SAP XI/PI – Invoice Attachment Transfer from ARIBA to VIM

  • By Varad
  • November 8, 2024
  • 2 views
SAP XI/PI – Invoice Attachment Transfer from ARIBA to VIM

11 Steps to Include a New Field in an Already-Existing SAP LSMW Batch Input Recording

  • By Varad
  • November 6, 2024
  • 3 views

Part 23 of ABAP for SAP HANA. How Can AMDP Be Used to Access Database Schema Dynamically?

  • By Varad
  • November 4, 2024
  • 3 views

S/4HANA VDM 1 Employing CDS Virtual Data Model for Embedded Analytics

  • By Varad
  • November 1, 2024
  • 5 views