ERPClimb logoERPClimb
SAPUI5 and SAP Fiori Tools
RAP / CDS / ODataintermediate 9 min read

SAPUI5 and Fiori Tools Part 5: OData V4 Read, Create, Update and Errors

Preview · a free account unlocks the full lesson

Key takeaway

Work with a RAP OData V4 service from SAPUI5: configure the V4 model, read lists and single entities with $select, create with list bindings, update with two-way binding, submit batch groups and handle errors and messages.

In this lessonShow sections

Visual overview

SAPUI5 and Fiori Tools Part 5: OData V4 Read, Create, Update and Errors — learning sheetFlow: Configure the V4 model (code example) → Bind the list with $count and a sorter → Add Create with oListBinding.create and a "changes" group → Add Save (submitBatch) and Cancel (resetChanges). Key ideas: CONFIGURE THE MODEL; READ; CREATE; UPDATE. Watch out: Errors come back as messages — show them via the message model, don't swallow them.ERPClimb.com / RAP / LESSON 5/7 / LEARNING SHEETSAPUI5 and Fiori Tools Part 5: OData V4 Read, Create,Update and Errors1 · HOW IT FLOWS1Configure the V4model (codeexample)2Bind the listwith $count anda sorter3Add Create withoListBinding.createand a…4Add Save(submitBatch)and Cancel…2 · KEY IDEAS EXPLAINEDConfigure The Model"sap.app" → dataSources → mainServicewith uri (service root) and type"OData", odataVersion "4.0"."sap.ui5" → models → ""(default) with dataSource "mainService"and settings (e.g. operationMode…ReadList: <Table items="{path:'/PurchaseRequest', parameters: {$orderby:'RequestID desc', $count: true}}">.Single:view.bindElement("/PurchaseRequest(RequestUUID=…)").Createconst oContext = oListBinding.create({Description: "Laptops", CurrencyCode:"EUR" });UpdateWith two-way binding (default for V4 inputs),changing an Input updates the context property.With an update group set to "$auto" it…3 · REMEMBER · WATCH OUTRememberThe OData V4 model is configured in manifest.json as a data source +default model.Read via bindings (list binding, element binding) — not manualrequests.Create with oListBinding.create(); update with two-way binding; sendwith submitBatch for deferred groups.!Watch outErrors come back as messages — showthem via the message model, don'tswallow them.4 · IN A REAL PROJECTA freestyle app used jQuery.ajax calls to the OData service, built URLs manually and showed "Error"alerts for every failure. Performance was poor because every call fetched all fields, and users never saw theactual validation messages from RAP. Rewritten with the OData V4 model, autoExpandSelect and list/element…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

Part 3 introduced binding. Now it's time to build the data layer of a freestyle app on the RAP service ZAPI_PURCHREQ (V4, no draft) — or a UI service if the app uses draft instead.

Configuring the model happens in manifest.json. Under "sap.app", the dataSources section needs a mainService entry with the uri (the service root) and type "OData" with odataVersion "4.0". Under "sap.ui5", the models section needs a default model, named "", with dataSource set to "mainService" and settings such as operationMode: "Server", autoExpandSelect: true, and an updateGroupId. autoExpandSelect is particularly valuable because it builds $select and $expand automatically from the bindings in use, which is a significant performance win.

Reading data works through bindings rather than manual requests. A list uses something like <Table items="{path: '/PurchaseRequest', parameters: {$orderby: 'RequestID desc', $count: true}}">, while a single entity uses view.bindElement("/PurchaseRequest(RequestUUID=…)"). Filtering and sorting are applied with sap.ui.model.Filter and sap.ui.model.Sorter on the list binding, and both execute on the server rather than the client.

Free account

Create a free account to keep reading

You have read the opening of this lesson. A free ERPClimb account unlocks the rest of it, every other lesson and topic, and your learning history, so you can pick up exactly where you stopped. No card needed.

  • Full explanation
  • Code example
  • Real project scenario
  • Common mistakes
  • Best practices
  • Interview angle

One tap with Google works too. Every topic keeps its first lesson open to everyone.

Keep exploring

Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.