Beyond ABAPdesigned by@Tejoram97
Beyond ABAP / SAPUI5 / UI5 Tooling, TypeScript & Custom Controls

UI5 Tooling, TypeScript & Custom Controls

SAPUI5 · SAP Fiori UI5 and Mobile ·

Open the interactive lesson →
  1. Why the UI5 CLI matters
  2. ui5.yaml in depth
  3. Development server and middleware
  4. Custom build tasks
  5. Build: preload, self-contained and what ends up in dist
  6. Deployment: ABAP repository and HTML5 Application Repository
  7. TypeScript with UI5
  8. Custom controls in depth
  9. Fragments, reuse components and libraries
  10. UI5 versions, long-term maintenance and UI5 2.x
  11. Interview questions

How a professional freestyle UI5 project is set up, built and shipped: the UI5 CLI and ui5.yaml, the development server and its middleware, custom build tasks, build variants, deployment to the ABAP repository and to the SAP BTP HTML5 Application Repository, TypeScript, custom controls in depth, reuse through fragments, components and libraries, and UI5 versions including what UI5 2.x changes. The running example is the Sales Order Approval dashboard (sales.dashboard), a freestyle app for managers that reads the RAP service ZUI_SalesOrder_O4 (orders with SalesOrderID, CustomerID, NetAmount, Status N / A / R and the action approve). Basics such as the project structure, index.html, MVC and a first custom control are on SAPUI5 › 03 · SAPUI5 Fundamentals and 04 · Data, Binding & Navigation; the Fiori tools wizards are on SAP Fiori › 04 · SAP Fiori Tools & Flexible Programming Model.

Part 1 – Why the UI5 CLI matters

A UI5 app is just files in webapp/, but the browser cannot use TypeScript, a production system should not load 150 single files, and the local machine cannot call the S/4HANA system directly because of CORS. The UI5 CLI (npm package @ui5/cli, called UI5 Tooling until 2025; command ui5) solves this: it serves the project locally through a configurable middleware chain and builds an optimised dist/ folder through a configurable task pipeline. Both are driven by one file, ui5.yaml.

UI5 CLI overview: ui5.yaml drives ui5 serve (middleware chain to the browser) and ui5 build (task pipeline to dist), which is then deployed to ABAP or BTP

Command

What it does

Typical use

ui5 init

Creates ui5.yaml for a folder that has webapp/manifest.json (or a library src/)

Once, for a hand-made project

ui5 serve [--open index.html]

Starts the development server (default port 8080), everything in memory

Daily development; generated apps call it through fiori run / npm start

ui5 build [self-contained | jsdoc]

Runs the build tasks and writes dist/

Before every deployment

ui5 use [email protected]

Sets framework.name and version in ui5.yaml

Switch the UI5 version

ui5 add sap.f sap.ui.table

Adds framework libraries to ui5.yaml

When the app needs a new library

ui5 tree, ui5 config

Shows the dependency tree / CLI settings

Troubleshooting

  • Versions: UI5 CLI v4 (July 2024) is the stable line – npm latest is 4.1.0 in November 2026; it needs Node.js 20.11+ or 22+ and introduced specVersion: "4.0". v5 is published under the npm tag next as an alpha (5.0.0-alpha.x; Node.js 22.22.3+ / 24.15+ / 26+, specVersion: "5.0", a new component project type, build caching) – not for production builds yet.
  • UI5 CLI vs Fiori tools: @sap/ux-ui5-tooling (Fiori tools) builds on the UI5 CLI and adds the fiori command, the fiori-tools-proxy and fiori-tools-preview middlewares and the deploy-to-abap task. Generated apps use both; the concepts on this page are the same either way.
  • Install the CLI as a devDependency (npm i -D @ui5/cli) so that every developer and the CI pipeline use the same version; a global installation is only a convenience.

Part 2 – ui5.yaml in depth

ui5.yaml describes one project (application, library, theme-library or module) and optionally extensions (custom tasks, custom middleware, project shims), separated by ---. Generated apps often have three variants: ui5.yaml (development with proxy), ui5-local.yaml (local UI5 sources, mock data) and ui5-deploy.yaml (build and deployment); select one with --config ui5-deploy.yaml.

specVersion: "4.0"
type: application                     # application | library | theme-library | module
metadata:
name: sales.dashboard               # lower case, usually the manifest sap.app.id
framework:                            # which UI5 to serve and build against
name: SAPUI5                        # or OpenUI5 – the two cannot be mixed
version: "1.136.0"                  # 1.136 = long-term maintenance (until Q4/2032)
libraries:
- name: sap.m
- name: sap.f
- name: sap.ui.core
- name: themelib_sap_horizon
- name: sap.ushell
development: true               # only loaded when this is the root project (FLP sandbox)
resources:
configuration:
paths:
webapp: webapp                  # source folder (default)
builder:
resources:
excludes:
- "/test/**"                    # do not ship test pages
- "/localService/**"            # nor mock data
server:
settings:
httpPort: 8080
customMiddleware:
- name: fiori-tools-proxy
afterMiddleware: compression
configuration:
backend:
- path: /sap
url:  https://my-s4-dev.example.com

Section

Purpose

Interview point

specVersion

Version of the configuration format, not of UI5

4.0 is required to build UI5 2.x libraries

type

Project type; decides the default folder layout and build tasks

application = webapp/; library = src/ + test/

framework

UI5 distribution, version and libraries the CLI downloads (npm packages @openui5/* / @sapui5/*)

Replaces a CDN bootstrap during development

builder

Excludes, component preload settings, custom bundles, customTasks, minification excludes

Where build behaviour is changed

server

Ports and customMiddleware

Proxy, live reload, TypeScript transpiling

kind: extension

Defines a task, middleware or project shim inside the same file or an npm package

Separated by ---

  • Workspace: ui5-workspace.yaml (UI5 CLI v3+) lets an app use a library from a sibling folder during development instead of the npm or deployed version – useful when the dashboard and a reuse library are developed together (Part 9).
  • Common mistake: a framework.version that does not exist in the chosen distribution, or OpenUI5 while the app uses SAPUI5-only libraries such as sap.viz or sap.ui.comp – the server then fails with "library not found".

Part 3 – Development server and middleware

ui5 serve is an Express-based server. Every request runs through an ordered list of middleware functions; each one either answers the request or calls next(). Standard middleware serves your files, the UI5 framework and themes; custom middleware is inserted with beforeMiddleware or afterMiddleware.

Middleware chain of ui5 serve: csp, compression, custom proxy, cors, custom transpile, serveResources, serveThemes, serveIndex; custom middleware example

Middleware

Source

Why the dashboard needs it

fiori-tools-proxy

@sap/ux-ui5-tooling

Forwards /sap/opu/odata4/... to the S/4HANA system (avoids CORS) and /resources to the UI5 CDN

fiori-tools-preview / fiori-tools-appreload

@sap/ux-ui5-tooling

FLP sandbox preview and reload on save; the package also has fiori-tools-servestatic

ui5-tooling-transpile-middleware

community (ui5-community)

Transpiles TypeScript on the fly (Part 7)

sap-fe-mockserver

@sap-ux/ui5-middleware-fe-mockserver

Answers OData V2/V4 requests from localService mock data

ui5-middleware-livereload

community

Reloads the browser when a file changes

Writing your own middleware

Example: during development the dashboard should show a banner "DEV – mock approvals". A tiny middleware adds a response header that the app reads; in production the header is absent.

# ui5.yaml – the extension is defined in the same file, after ---
server:
customMiddleware:
- name: dev-banner-header
afterMiddleware: compression
configuration:
text: "DEV – mock approvals"
---
specVersion: "4.0"
kind: extension
type: server-middleware
metadata:
name: dev-banner-header
middleware:
path: lib/middleware/devBanner.js
// lib/middleware/devBanner.js – ES module, specVersion 3.0+
export default function ({ log, options }) {
const text = options.configuration?.text ?? "DEV";
return function devBanner(req, res, next) {
res.setHeader("X-Dashboard-Env", text);   // read by the app with fetch(...).headers
log.verbose(`banner header for ${req.path}`);
next();                                   // always pass on, or the request hangs
};
}
  • Order matters: a middleware placed after serveResources never sees requests that serveResources already answered. Put proxies early (after compression).
  • Middleware runs only on the developer's machine. The production equivalents are the Fiori launchpad / ICF on ABAP and the app router on BTP.

Part 4 – Custom build tasks

The build is a sequence of tasks that read and write resources in a virtual workspace. A custom task is a JavaScript function registered in builder.customTasks and positioned with beforeTask or afterTask. Typical uses: transpiling TypeScript, zipping dist/ for the HTML5 repository (ui5-task-zipper), uploading to ABAP (deploy-to-abap), or writing build information into the app.

Example: the dashboard's About dialog shows the Git commit of the build. A custom task writes buildInfo.json into the workspace.

# ui5.yaml
builder:
customTasks:
- name: write-build-info
afterTask: replaceVersion
configuration:
file: /resources/sales/dashboard/buildInfo.json
---
specVersion: "4.0"
kind: extension
type: task
metadata:
name: write-build-info
task:
path: lib/tasks/writeBuildInfo.js
// lib/tasks/writeBuildInfo.js
export default async function ({ workspace, taskUtil, options, log }) {
const { createResource } = taskUtil.resourceFactory;
const info = {
commit: process.env.GIT_COMMIT ?? "local",   // set by the CI pipeline
builtAt: new Date().toISOString()
};
await workspace.write(createResource({
path: options.configuration.file,           // virtual paths are always POSIX
string: JSON.stringify(info, null, 2)
}));
log.info(`build info written: ${info.commit}`);
}
  • The task receives workspace (the project's resources), optionally dependencies (only if it exports determineRequiredDependencies, specVersion 3.0+), taskUtil, options.configuration and log.
  • Task order: standard tasks run in a fixed order (Part 5); a custom task must reference an existing task name or an earlier custom task, otherwise the build stops with an error.
  • Community tasks and middleware are third-party npm packages: check their licence and maintenance before a productive project depends on them.

Part 5 – Build: preload, self-contained and what ends up in dist

Three build variants: default build with Component-preload.js, self-contained build with sap-ui-custom.js, jsdoc build with api.json

Task (application, in order)

Default

What it does

escapeNonAsciiCharacters

on

Escapes non-ASCII characters in .properties files

replaceCopyright, replaceVersion

on

Fills ${copyright} and ${version} placeholders

minify

on

Minifies JS, keeps X-dbg.js and a source map for each file

generateFlexChangesBundle

on

Bundles key-user / developer adaptation changes into changes/flexibility-bundle.json

enhanceManifest

on

Adds information to manifest.json (e.g. supported locales)

generateComponentPreload

on

Writes Component-preload.js with all modules, XML views, fragments and i18n files

generateStandaloneAppBundle, transformBootstrapHtml

self-contained only

Bundles the needed framework modules into resources/sap-ui-custom.js and rewrites index.html

generateBundle

with config

Custom bundles from builder.bundles

generateCachebusterInfo

off

Writes sap-ui-cachebuster-info.json (enabled by deploy configs)

generateVersionInfo, generateApiIndex

jsdoc only

Version and API index data

ui5 build --clean-dest                          # default build, empty dist/ first
ui5 build self-contained --clean-dest           # standalone app incl. needed UI5 parts
ui5 build --config ui5-deploy.yaml              # build (and deploy) with the deploy variant
ui5 build --exclude-task=minify                 # e.g. for a debugging build
ui5 serve --config ui5-local.yaml               # local UI5 + mock data
  • Why the preload matters: without it the browser requests every controller, view and i18n file separately – often 50–150 requests. With Component-preload.js it is one request, cached by the browser (more on SAPUI5 › 06 · Testing, Performance & Best Practices).
  • Debugging a built app: sap-ui-debug=true (or sap-ui-debug=sales/dashboard/ for just your modules) makes UI5 load the -dbg.js files; source maps also let the browser show readable code without it.
  • Common mistake: deploying webapp/ instead of dist/. The app works but is slow, and test and mock files are shipped to production.

Part 6 – Deployment: ABAP repository and HTML5 Application Repository

The same dist/ can go to two kinds of target. Which one is decided by where the users' launchpad runs: the dashboard for S/4HANA on-premise or private cloud goes into the ABAP repository; an app that runs in SAP Build Work Zone on SAP BTP goes into the HTML5 Application Repository. The basic commands are on SAPUI5 › 04 · Data, Binding & Navigation; here is what happens underneath.

Deployment to the ABAP repository with deploy-to-abap and to the BTP HTML5 Application Repository with an MTA

ABAP repository

# ui5-deploy.yaml (generated by "fiori add deploy-config", values are examples)
specVersion: "4.0"
metadata:
name: sales.dashboard
type: application
builder:
resources:
excludes:
- /test/**
- /localService/**
customTasks:
- name: deploy-to-abap
afterTask: generateCachebusterInfo
configuration:
ignoreCertError: false
target:
url:  https://my-s4-dev.example.com
client: "100"
credentials:                          # never hard-code passwords
username: env:ABAP_DEPLOY_USER
password: env:ABAP_DEPLOY_PASSWORD
app:
name: ZSO_DASH                      # BSP application, max. 15 characters
description: Sales Order Approval dashboard
package: ZSD_UI
transport: <transport request>

Step

Happens where

Note

Build

Local / CI (ui5 build)

Runs the normal tasks, then deploy-to-abap

Upload

OData service /UI5/ABAP_REPOSITORY_SRV

Must be active (SICF / service activation); user needs S_DEVELOP for the package and a transport

Store

BSP application ZSO_DASH in the MIME repository

Recorded in the transport request Dev → QA → Prod

Index

SAPUI5 application index

Updated automatically; after manual uploads run /UI5/APP_INDEX_CALCULATE

Serve

ICF node /sap/bc/ui5_ui5/sap/zso_dash/

Launchpad tile + target mapping + role (SAP Fiori › 02 · SAP Fiori Launchpad & Security)

  • Fallback: report /UI5/UI5_REPOSITORY_LOAD (SE38) uploads a zipped dist/, and can download or delete an app. Use it when the deploy service cannot be reached; prefer the CLI because it is repeatable in CI.
  • Undeploy: fiori undeploy --config ui5-deploy.yaml or the report's delete function.

HTML5 Application Repository via MTA

On SAP BTP Cloud Foundry, UI5 apps are not deployed as running applications. They are zipped and stored in the HTML5 Application Repository (service html5-apps-repo, plan app-host for upload, app-runtime for reading) and served by the managed app router of SAP Build Work Zone. The multi-target application (MTA) describes the zip module and the content deployer.

# mta.yaml (excerpt, generated by "fiori add deploy-config cf"; names are examples)
_schema-version: "3.2"
ID: sales-dashboard
version: 1.0.0
modules:
- name: sales-dashboard-content            # deployer: pushes the zip into the repository
type: com.sap.application.content
path: .
requires:
- name: sales-dashboard-repo-host
parameters:
content-target: true
build-parameters:
build-result: resources
requires:
- name: salesdashboard
artifacts:
- salesdashboard.zip
target-path: resources/
- name: salesdashboard                     # the UI5 app itself
type: html5
path: .
build-parameters:
build-result: dist
builder: custom
commands:
- npm install
- npm run build:cf                   # ui5 build + ui5-task-zipper
supported-platforms: []
resources:
- name: sales-dashboard-repo-host
type: org.cloudfoundry.managed-service
parameters:
service: html5-apps-repo
service-plan: app-host
// webapp/manifest.json – needed so Work Zone can find the app
"sap.cloud": { "public": true, "service": "salesdashboard.service" }

// webapp/xs-app.json – routes of the managed app router
{
"welcomeFile": "/index.html",
"authenticationMethod": "route",
"routes": [
{ "source": "^/sap/(.*)$", "target": "/sap/$1", "destination": "S4H_SALES",
"authenticationType": "xsuaa", "csrfProtection": false },
{ "source": "^(.*)$", "target": "$1", "service": "html5-apps-repo-rt", "authenticationType": "xsuaa" }
]
}
npm run build              # mbt build → mta_archives/sales-dashboard_1.0.0.mtar
cf login -a https://api.cf.<region>.hana.ondemand.com
cf deploy mta_archives/sales-dashboard_1.0.0.mtar
cf html5-list              # list deployed HTML5 apps (needs the CF HTML5 Applications plug-in)
  • The destination S4H_SALES (plus the Cloud Connector for on-premise systems) is created in the BTP cockpit, not in the app. MTA, app router, XSUAA and destinations are explained on BTP Development › Developing on BTP – Tools, MTA & Fiori and BTP Foundations › BTP Security Deep Dive; adding the app to a site on SAP Build › SAP Build Work Zone & SAP Build Code.
  • Interview trap: "Is the UI5 app a Cloud Foundry application?" – No. Only the deployer task runs briefly; the app is static content in the HTML5 repository. A standalone app router is needed only if you do not use Work Zone's managed one.

Part 7 – TypeScript with UI5

TypeScript adds static types to JavaScript. For UI5 this means code completion for every control and API, typed event parameters and errors at build time instead of in the manager's browser. UI5 itself still only loads AMD modules (sap.ui.define), so TypeScript is transpiled during ui5 serve and ui5 build. SAP publishes the official type definitions and samples; the Fiori application generator can create TypeScript projects.

TypeScript in UI5: ES class with @namespace, type check with the UI5 types, Babel transpile with ui5-tooling-transpile into sap.ui.define code

Piece

Package

Role

Type definitions

@sapui5/types or @openui5/types (match the framework and version)

Describe every UI5 module, class and event; referenced in tsconfig.json

Transpiler

ui5-tooling-transpile (task + middleware) using babel-preset-transform-ui5 / babel-plugin-transform-modules-ui5

ES import → sap.ui.define, class X extends Y → Y.extend("full.Name", …)

Control interfaces

@ui5/ts-interface-generator

Generates *.gen.d.ts with the getters, setters and event methods UI5 creates at runtime

Type check

typescript (tsc --noEmit)

Run in CI; transpiling alone does not check types

npm i -D typescript @sapui5/types ui5-tooling-transpile
# ui5.yaml
builder:
customTasks:
- name: ui5-tooling-transpile-task
afterTask: replaceVersion
server:
customMiddleware:
- name: ui5-tooling-transpile-middleware
afterMiddleware: compression
// tsconfig.json (key settings)
{
"compilerOptions": {
"target": "es2023",
"module": "es2022",
"moduleResolution": "bundler",
"strict": true,
"rootDir": "./webapp",
"types": ["@sapui5/types"],
"paths": { "sales/dashboard/*": ["./webapp/*"] }
},
"include": ["./webapp/**/*"]
}

A typed controller for the dashboard

import Controller from "sap/ui/core/mvc/Controller";
import MessageToast from "sap/m/MessageToast";
import type { Button$PressEvent } from "sap/m/Button";
import type Context from "sap/ui/model/odata/v4/Context";
import type ODataModel from "sap/ui/model/odata/v4/ODataModel";

/**
* @namespace sales.dashboard.controller
*/
export default class Dashboard extends Controller {
public async onApprove(event: Button$PressEvent): Promise<void> {
const ctx = event.getSource().getBindingContext() as Context;
const model = this.getView()!.getModel() as ODataModel;
const action = model.bindContext("com.sap.gateway.srvd.zui_salesorder.v0001.approve(...)", ctx);
await action.invoke();                         // V4: execute() in older releases
MessageToast.show(`Order ${ctx.getProperty("SalesOrderID")} approved`);
}
}
  • @namespace is mandatory for classes that UI5 instantiates by name (component, controllers, controls): the Babel plugin builds the full class name sales.dashboard.controller.Dashboard from it. Without it the view cannot find its controller.
  • Use export default class with one class per file and ES imports only; never globals or sap.ui.getCore().
  • Typed events such as Button$PressEvent and Table$SelectionChangeEvent exist in recent type versions; older code casts getSource(). The action path (…v0001.approve(...)) is the bound action's qualified name in your service metadata (see $metadata). ODataContextBinding#invoke() exists since UI5 1.123 and replaces execute(), which is deprecated since 1.123.
  • Migrating an existing JS app: rename files one at a time to .ts; JS and TS can coexist because everything is transpiled to the same module format.

Part 8 – Custom controls in depth

A custom control is worth it when no standard control, composition of controls or fragment does the job and the behaviour is reused. The dashboard needs an AmountBadge: the net amount in red with a warning icon when it exceeds the manager's approval limit, green otherwise, clickable and accessible. The minimal pattern is on SAPUI5 › 04 · Data, Binding & Navigation; here is the full anatomy.

Custom control anatomy: metadata declares properties, aggregations, associations and events; UI5 generates the API; the apiVersion 2 renderer writes the DOM

Metadata entry

Declares

Generated for you

properties

Typed values (string, int, float, boolean, enums, object) with defaultValue

getX, setX, binding, type validation

aggregations

Owned children; multiple, type, visibility: "hidden" for internal children

getX, addX, insertX, removeX, destroyX, bindAggregation

associations

References by ID (e.g. ariaLabelledBy)

addX, removeX, getX (IDs)

events

Events with typed parameters; allowPreventDefault

attachX, detachX, fireX

defaultAggregation

Aggregation used when XML children have no aggregation tag

–

interfaces, library

Implemented interfaces, owning library

–

// webapp/control/AmountBadge.js
sap.ui.define([
"sap/ui/core/Control",
"sap/ui/core/Icon",
"sap/ui/core/format/NumberFormat"
], (Control, Icon, NumberFormat) => {
"use strict";

return Control.extend("sales.dashboard.control.AmountBadge", {
metadata: {
properties: {
amount:   { type: "float", defaultValue: 0 },
currency: { type: "string", defaultValue: "" },
limit:    { type: "float", defaultValue: 10000 }
},
aggregations: {
_icon: { type: "sap.ui.core.Icon", multiple: false, visibility: "hidden" }
},
associations: {
ariaLabelledBy: { type: "sap.ui.core.Control", multiple: true, singularName: "ariaLabelledBy" }
},
events: {
press: { parameters: { overLimit: { type: "boolean" } } }
}
},

init() {                                        // once per instance, like a constructor
this.setAggregation("_icon", new Icon({ src: "sap-icon://warning", decorative: true }));
},

isOverLimit() {
return this.getAmount() > this.getLimit();
},

onclick() { this.firePress({ overLimit: this.isOverLimit() }); },
onsapenter() { this.onclick(); },               // keyboard: Enter
onsapspace() { this.onclick(); },               // keyboard: Space

renderer: {
apiVersion: 2,                                // DOM patching, no string concatenation
render(oRm, oControl) {
const bOver = oControl.isOverLimit();
const sText = NumberFormat.getCurrencyInstance()
.format(oControl.getAmount(), oControl.getCurrency());
oRm.openStart("div", oControl);             // writes id and data-sap-ui
oRm.class("soAmountBadge");
oRm.class(bOver ? "soOverLimit" : "soWithinLimit");
oRm.attr("tabindex", "0");
oRm.accessibilityState(oControl, { role: "button" });
oRm.openEnd();
if (bOver) {
oRm.renderControl(oControl.getAggregation("_icon"));
}
oRm.text(sText);                            // escaped automatically
oRm.close("div");
}
}
});
});
<!-- Dashboard.view.xml -->
<mvc:View xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" xmlns:so="sales.dashboard.control"
controllerName="sales.dashboard.controller.Dashboard">
<Table items="{/SalesOrder}">
<columns><Column><Text text="{i18n>netAmount}"/></Column></columns>
<items>
<ColumnListItem>
<so:AmountBadge amount="{NetAmount}" currency="{CurrencyCode}" limit="{view>/approvalLimit}"
press=".onBadgePress"/>
</ColumnListItem>
</items>
</Table>
</mvc:View>

Renderer rules (apiVersion 2)

  • Use only the semantic API: openStart/voidStart, openEnd/voidEnd, close, attr, class, style, text, renderControl, accessibilityState, icon. The old string API (write, writeEscaped, writeControlData) is deprecated and must not be mixed in.
  • The renderer must be a pure function of the control's state: no DOM access, no data loading, no side effects. With apiVersion 2 the RenderManager reuses and patches existing DOM elements, so the root element must always be the same tag with the control's ID.
  • apiVersion: 4 adds a further promise: the control's output does not depend on its parent, so the RenderManager can skip re-rendering it when only the parent re-renders. It requires the apiVersion 2 contract and no onBeforeRendering / onAfterRendering delegates (see the sap.ui.core.RenderManager API reference).

Other kinds of custom control

Kind

How

When

Extend an existing control

Button.extend("sales.dashboard.control.ApproveButton", { metadata: {…}, renderer: "sap.m.ButtonRenderer" })

Small change of behaviour; reuse the parent renderer

Composite control

Hidden aggregations hold standard controls (like _icon above); the renderer calls renderControl for them

Combine standard controls into one reusable unit

Notepad control

Defined inline in a controller

Avoid: not reusable, hard to test

The same control in TypeScript

import Control from "sap/ui/core/Control";
import RenderManager from "sap/ui/core/RenderManager";
import type { MetadataOptions } from "sap/ui/core/Element";

/**
* @namespace sales.dashboard.control
*/
export default class AmountBadge extends Control {
// the interface generator prints these three lines; paste them unchanged
constructor(idOrSettings?: string | $AmountBadgeSettings);
constructor(id?: string, settings?: $AmountBadgeSettings);
constructor(id?: string, settings?: $AmountBadgeSettings) { super(id, settings); }

static readonly metadata: MetadataOptions = {
properties: {
amount: { type: "float", defaultValue: 0 },
currency: { type: "string", defaultValue: "" },
limit: { type: "float", defaultValue: 10000 }
},
events: { press: { parameters: { overLimit: { type: "boolean" } } } }
};

static renderer = {
apiVersion: 2,
render(rm: RenderManager, control: AmountBadge): void {
rm.openStart("div", control);
rm.class(control.getAmount() > control.getLimit() ? "soOverLimit" : "soWithinLimit");
rm.openEnd();
rm.text(`${control.getAmount()} ${control.getCurrency()}`);
rm.close("div");
}
};
}
  • getAmount() does not exist for the TypeScript compiler until npx @ui5/ts-interface-generator --watch has written AmountBadge.gen.d.ts next to the control; commit or regenerate it in CI.
  • Styling: put the CSS in css/style.css (declared in sap.ui5/resources/css) and use theme parameters (CSS variables such as var(--sapNegativeColor)) instead of fixed colours, so the badge works in Horizon dark and high-contrast themes.

Part 9 – Fragments, reuse components and libraries

Three reuse levels exist above a single control. Fragments (basic loading on SAPUI5 › 04) share a piece of UI inside one app; reuse components share a complete UI part with its own logic, models and texts; libraries share controls and components across many apps.

Decision: fragment for a piece of UI, custom control for new rendering, reuse component for a UI part with logic and data, library for many apps

Fragments beyond the basics

  • Controller choice: this.loadFragment({ name, controller }) – pass a small handler object instead of this when the same dialog is used from several views (e.g. an "Approve with note" dialog).
  • Static fragments with a prefix: <core:Fragment id="approvalFrag" fragmentName="…" type="XML"/> → IDs become view--approvalFrag--noteInput; read them with this.byId(Fragment.createId("approvalFrag", "noteInput")).
  • Extension points (<core:ExtensionPoint name="…"/>) in a view let customers or adaptation projects insert fragments without changing the original app (SAP Fiori › 05 · Adaptation & Extensibility of SAP Fiori Apps).

Reuse component

// dashboard manifest.json – declare the usage
"sap.ui5": {
"dependencies": {
"components": { "zsales.reuse.credit": { "lazy": true } }
},
"componentUsages": {
"creditPanel": {
"name": "zsales.reuse.credit",
"settings": {},
"componentData": {},
"lazy": true
}
}
}
<!-- in the object view: the container creates the component asynchronously -->
<core:ComponentContainer id="creditContainer" usage="creditPanel" async="true" propagateModel="false"/>

// or in code, passing the customer in as component data
const oCredit = await this.getOwnerComponent().createComponent({
usage: "creditPanel",
componentData: { customerId: sCustomerId }
});
this.byId("creditContainer").setComponent(oCredit);
  • A reuse component has "type": "component" in sap.app, its own manifest, i18n and models, and is deployed like an app (its own BSP application or HTML5 repo entry). The launchpad finds it through the application index, so no hard-coded URL is needed.
  • Keep the interface small: pass data in through settings / componentData or properties, and send results back through events of the component, not through shared global models.

UI5 library

// src/zsales/reuse/library.js (UI5 1.118+; older code uses sap.ui.getCore().initLibrary)
sap.ui.define(["sap/ui/core/Lib"], (Lib) => {
"use strict";
return Lib.init({
name: "zsales.reuse",
version: "${version}",
dependencies: ["sap.ui.core", "sap.m"],
controls: ["zsales.reuse.AmountBadge"],
apiVersion: 2
});
});
  • Project type: library in ui5.yaml, sources under src/, tests under test/, plus a .library descriptor (and manifest.json, required for libraries from UI5 CLI v5). The build creates library-preload.js and compiles the library's themes.
  • Apps declare it in sap.ui5/dependencies/libs ("zsales.reuse": { "lazy": true } if not needed at start). On ABAP it is deployed like an app; on BTP the library must be deployed to the HTML5 repository and referenced by the app, so it is resolved from there at runtime.
  • Cost: a library has its own versioning and release cycle. For two apps a reuse component or a shared folder copied by a build step may be enough.

Part 10 – UI5 versions, long-term maintenance and UI5 2.x

SAPUI5 is versioned as major.minor.patch (e.g. 1.136.4). New minor versions bring features; patches bring fixes. The version overview (ui5.sap.com/versionoverview.html) gives every minor version a maintenance category and dates. In November 2026: 1.136 has long-term maintenance until Q4/2032, 1.120 long-term support until Q4/2030, 1.148 long-term support until Q3/2027; the newest version, 1.154, has mid-term support until Q3/2027; most other versions get standard support for a short time only. About a year after its end of maintenance a version reaches its end of cloud provisioning and is removed from the CDN.

Where the app runs

Who decides the UI5 version

What you control

S/4HANA / ABAP launchpad

The SAP_UI software component of the front-end server

minUI5Version in the manifest; upgrade the system to get a newer UI5

SAP Build Work Zone

The site's UI5 version (SAP-managed, regularly updated)

Test against the version the site uses; some settings allow a fixed version

Standalone (index.html)

The bootstrap URL, e.g. https://ui5.sap.com/1.136.0/resources/sap-ui-core.js

Pin a maintained version instead of the unversioned "latest" URL

Local development

framework.version in ui5.yaml

Keep it equal to production

UI5 2.x migration essentials

UI5 2.x is the next major version. It removes all APIs deprecated with or before 1.136, so the work is done in 1.x: an app that runs on the latest 1.x without deprecated APIs is ready. SAP's guidance is to target 1.136 or later and use the UI5 linter to find the remaining issues (details of the linter on SAPUI5 › 06). In November 2026 the version overview still lists only 1.x versions for SAPUI5, so 2.x readiness is preparation work, not yet a migration date.

UI5 2.x readiness: deprecated globals, jQuery.sap, Core and Configuration APIs, sync factories, old view types and libraries with their modern replacements, plus five migration steps

Area

Remove

Use instead

Loading

data-sap-ui-async="false", sync jQuery.sap.require, sync XHR

async bootstrap, sap.ui.define, sap.ui.require

Globals

new sap.m.Button(), sap.ui.getCore()

module imports, Element.getElementById, sap/ui/core/Lib, sap/base/i18n/Localization, sap/ui/core/Theming

Factories

sap.ui.xmlview, sap.ui.xmlfragment, sap.ui.component, sap.ui.controller

XMLView.create, loadFragment / Fragment.load, Component.create, Controller.create

Views

JS, JSON, HTML views

XML views, typed views

Messages

sap.ui.getCore().getMessageManager()

sap/ui/core/Messaging

Manifest

descriptor 1.x routing names viewName, viewPath, viewLevel

descriptor 2.0 (UI5 1.136+): name, path, level; component metadata in manifest.json

Libraries / themes

sap.ui.commons, sap.ui.ux3, sap_bluecrystal, sap_belize

sap.m, sap.f, sap.uxap; sap_horizon (and sap_fiori_3 while it exists)

Tooling

UI5 CLI < v4

UI5 CLI v4+ (specVersion: "4.0") – needed to build against UI5 2.x

  • Component flags: declare "sap.ui.core.IAsyncContentCreation" in the component and use "async": true routing; the linter rule async-component-flags checks this.
  • Interview line: "We prepare for UI5 2 by staying on the latest long-term maintenance 1.x, running the UI5 linter in CI with zero findings, testing with async loading and a strict CSP, and replacing deprecated APIs as part of normal work, not as a big-bang project."

Part 11 – Interview questions

Q1. What is the UI5 CLI, and what is ui5.yaml for?

The UI5 CLI (@ui5/cli, formerly UI5 Tooling) is the Node.js tool to serve, build and configure UI5 projects. ui5.yaml declares the project type and name, the UI5 framework (OpenUI5 or SAPUI5, version, libraries), build settings and custom tasks, server settings and custom middleware. ui5 serve runs a middleware chain in memory; ui5 build runs a task pipeline into dist/.

Q2. What is the difference between middleware and a build task?

Middleware handles HTTP requests of the development server (proxy, transpile, mock data) and exists only locally. A task transforms resources during the build (minify, preload, transpile, zip, deploy) and its result is shipped. Both can be custom extensions positioned with before… / after….

Q3. What does Component-preload.js contain, and why is it important?

All modules, XML views, fragments and i18n files of the component in one file, created by generateComponentPreload. It turns dozens of requests into one cacheable request. Missing preloads (for example deploying webapp/ instead of dist/) are a classic cause of slow apps.

Q4. Default build vs self-contained build?

The default build contains only the app; UI5 comes from the launchpad or CDN – right for ABAP and Work Zone apps. ui5 build self-contained also bundles the needed framework modules into resources/sap-ui-custom.js and rewrites index.html, so the app runs on any static web server without a CDN.

Q5. Walk through deploying a UI5 app to S/4HANA.

fiori add deploy-config creates ui5-deploy.yaml with the deploy-to-abap task (system, BSP name, package, transport; credentials from environment variables). npm run deploy builds and uploads through /UI5/ABAP_REPOSITORY_SRV; the BSP application is recorded in the transport and the app index is updated. Then catalog, target mapping and role make it visible. Fallback: /UI5/UI5_REPOSITORY_LOAD.

Q6. How does a UI5 app get to SAP BTP, and where does it run?

An MTA contains an html5 module (built and zipped) and a com.sap.application.content deployer bound to html5-apps-repo (app-host). mbt build and cf deploy store the zip in the HTML5 Application Repository. The managed app router of SAP Build Work Zone serves it; xs-app.json routes OData calls to a destination. The app is static content, not a running CF application.

Q7. How does TypeScript work with UI5 if the runtime only understands sap.ui.define?

You write ES classes with imports against @sapui5/types; ui5-tooling-transpile (Babel with the UI5 transform plugin) converts imports to sap.ui.define and classes to .extend() calls, using the @namespace JSDoc for the full class name. tsc --noEmit checks types separately. For custom controls @ui5/ts-interface-generator creates the declarations of the runtime-generated methods.

Q8. Explain the parts of a custom control and the apiVersion 2 renderer.

metadata declares properties, aggregations (also hidden ones for composite controls), associations and events; UI5 generates getters, setters, binding and fireX methods. init creates internal children. The renderer uses the semantic RenderManager API (openStart, class, attr, text, close); with apiVersion: 2 the framework patches the existing DOM instead of replacing HTML strings, which is faster and keeps focus. Event handlers such as onclick and onsapenter handle mouse and keyboard.

Q9. Fragment, reuse component or library – how do you decide?

A fragment for a piece of UI inside one app (it has no controller or models of its own). A reuse component for a UI part with its own logic, models and texts used by several apps (componentUsages + ComponentContainer). A library for many controls or components shared across many apps, with its own release cycle. Choose the lightest option.

Q10. What changes with UI5 2.x, and how do you prepare an app?

UI5 2.x removes APIs deprecated with or before 1.136: globals, jQuery.sap.*, sap.ui.getCore() helpers, synchronous loading and factories, JS/JSON/HTML views, old libraries and themes. Preparation: move to the latest long-term maintenance 1.x (1.136+), run the UI5 linter (with --fix), switch the manifest to descriptor 2.0, use UI5 CLI v4, test with async loading and strict CSP.

Q11. Scenario: the dashboard works locally but in the launchpad the OData calls fail with 404.

Locally the fiori-tools-proxy forwarded /sap/...; in production there is no proxy. Check that the dataSources URI is relative and correct for the target system, that the service is published (/IWFND/V4_ADMIN for V4) and, on BTP, that xs-app.json has a route to the right destination. Use the browser Network tab and the gateway error log.

Q12. Scenario: after a deployment users still see the old version of the dashboard.

Browser or server caching. On ABAP, check that the app index was recalculated (/UI5/APP_INDEX_CALCULATE after manual uploads) and that the cache buster info was generated; ask users for a hard reload only as a workaround. On BTP, check that the new .mtar really deployed (cf html5-list) and that applicationVersion was increased.

🏠 Start Here · ◀ 04 · Data & Navigation · 06 · Testing & Performance ▶ · Sections: CORE ABAP | OOPS ABAP | ABAP on HANA | Clean Core | RAP | ABAP Points | SAP Fiori | SAPUI5 | Mobile Development (MDK) | BTP Foundations | BTP Development | CAP | SAP Build | ABAP on BTP | Integration Suite | SAP Business AI | SAP BASIS | Security | SAP SDLC

Functional: FICO ABAP | TRM ABAP | VIM | SAP BIS | SD ABAP | MM ABAP | PP ABAP | QM ABAP | PM ABAP | PS ABAP | EWM | TM ABAP | GTM ABAP | EHS ABAP | HR ABAP | BW | SAP Datasphere | SAP Business Data Cloud | SAP MDG | SAP Analytics Cloud | SAP Ariba | SAP CX | SAP IBP