Skip to main content

Module 17: Advanced OData Concepts

Advanced OData features allow SAPUI5 applications to be efficient, scalable, and enterprise-ready.
This module covers query options, deep entities, function imports, actions, and robust error handling.


1. OData Query Options Overview

OData supports query options to control:

  • Data volume
  • Data structure
  • Backend processing

Common query options:

  • $filter
  • $select
  • $expand
  • $top
  • $skip
Performance Rule

Always fetch only the data you need.


2. $filter – Server-Side Filtering


What is $filter?

$filter applies conditions on the backend, reducing data transfer.


UI5 Filter Example

var oFilter = new sap.ui.model.Filter(
"Status",
sap.ui.model.FilterOperator.EQ,
"A"
);

this.getView().getModel().read("/SalesOrderSet", {
filters: [oFilter]
});

Multiple Filters

var aFilters = [
new Filter("Customer", FilterOperator.EQ, "C1001"),
new Filter("Amount", FilterOperator.GT, 1000)
];
Best Practice

Always prefer server-side filtering over client-side.


3. $select – Fetch Required Fields Only


Why $select?

  • Reduces payload size
  • Improves performance

UI5 Usage

this.getView().getModel().read("/SalesOrderSet", {
urlParameters: {
"$select": "SalesOrderID,Customer"
}
});
Real Projects

Using $select significantly improves table load times.


4. $expand – Handling Associations


What is $expand?

$expand fetches related entities in a single request.

Example: SalesOrderSet?$expand=Items


UI5 Expand Example

this.getView().getModel().read("/SalesOrderSet('50000001')", {
urlParameters: {
"$expand": "Items"
}
});

Binding Expanded Data

<List items="{Items}">
<StandardListItem title="{Product}" />
</List>
Use Case

Master–Detail applications with header + items.


5. Server-Side Paging


Why Paging?

  • Large datasets
  • Better performance
  • Faster initial load

How UI5 Handles Paging

ODataModel automatically uses:

  • $top
  • $skip

When:

  • Table growing is enabled
  • Scroll-based loading
Developer Advantage

No manual paging logic required.


6. Deep Entity Handling


What is a Deep Entity?

A deep entity contains:

  • Header data
  • Child entities

Structure:

SalesOrder
├─ Header
└─ Items[]

Deep Create Example

var oDeepEntity = {
SalesOrderID: "50000010",
Items: [
{ Product: "P1", Qty: 2 },
{ Product: "P2", Qty: 1 }
]
};

this.getView().getModel().create("/SalesOrderSet", oDeepEntity);
Backend Note

Backend must explicitly support deep insert.


7. Function Imports


What is a Function Import?

Function imports:

  • Perform read-only operations
  • Accept parameters
  • Return data

Typical use cases:

  • Calculations
  • Validations
  • Derivations

Calling Function Import (V2)

this.getView().getModel().callFunction("/GetPrice", {
method: "GET",
urlParameters: {
ProductID: "P100"
},
success: function (oData) {
// Handle result
}
});
Interview Insight

Function imports do not modify data.


8. Actions (Side-Effect Operations)


What is an Action?

Actions:

  • Perform state-changing operations
  • Do not fit standard CRUD

Examples:

  • Approve
  • Reject
  • Post
  • Close

Calling Action (V2)

this.getView().getModel().callFunction("/ApproveOrder", {
method: "POST",
urlParameters: {
SalesOrderID: "50000001"
}
});
SAP Pattern

Actions map to business behavior, not CRUD.


9. Error & Message Handling (Advanced)


Types of Errors

  • HTTP errors
  • Backend validation messages
  • Business errors

Centralized Error Handling

this.getView().getModel().attachRequestFailed(function (oEvent) {
var oResponse = oEvent.getParameter("response");
// Handle globally
});

Parsing OData Messages

var oError = JSON.parse(oResponse.responseText);
var sMessage = oError.error.message.value;
Best Practice

Display user-friendly messages, log technical details.


10. Common Advanced OData Mistakes

Avoid These
  • Client-side filtering of large datasets
  • Missing $select
  • Overusing $expand
  • No backend support for deep entities
  • Ignoring message handling

11. Interview-Grade Explanation

Q: How do you optimize OData calls in SAPUI5?

Answer:

I use server-side filtering with $filter, limit payloads using $select, load related data using $expand only when required, rely on server-side paging, and handle errors centrally to ensure performance and robustness.


12. Summary

  • OData query options optimize data transfer
  • $filter and $select improve performance
  • $expand handles associations
  • Paging is automatic in UI5
  • Deep entities support complex transactions
  • Function imports and actions support business logic
  • Error handling is critical

13. What's Next?

➡️ Module 18: Fiori Elements – Fundamentals

Learning Tip

If you overfetch data, performance will always suffer.