SAP Guide: Your First SAPUI5 App

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

Checked on 2026-11-13 against OpenUI5 1.154.0, UI5 Tooling (@ui5/cli) 4.0.73, CAP Node.js 10.2 (@sap/cds 10.2.2, @sap/cds-dk 10.2.1) and Node.js 24.21.

What you build

This is a teaching model built with CAP. It is not SAP S/4HANA or SAP SuccessFactors and does not reproduce their screens.

You build a small browser app for expense claims with UI5, the JavaScript library behind most SAP web screens. The app has one screen: a page with a search field and a table of claims. The table reads its rows from a CAP service over OData V4, and every text on the screen comes from a language file, in English and in German. You write the files by hand, so you see what each of them is for: the project file of UI5 Tooling, the start page, the component, the manifest, the XML view, the controller and the texts. Two small servers run on your machine: CAP serves the data and UI5 Tooling serves the app.

The app in a browser after the text Ho was typed into the search field: the table title reads Claims (1) and the only row is Hotel Berlin, Approved, 189.00 EUR

Before you start

  • No account is needed. UI5 Tooling and OpenUI5 come from the public npm registry under the Apache License 2.0, and the app loads UI5 from your own machine, not from a content delivery network. UI5 Tooling downloads the OpenUI5 libraries that ui5.yaml names into a cache folder in your home directory the first time it runs. The CAP packages carry the SAP Developer License Agreement, version 3.2, which you accept by installing them, as in Your First CAP Service.

  • Install Node.js 22.12 or newer. node -v prints the version.

  • Use a code editor such as Visual Studio Code, a terminal and a browser. You need two terminal windows: one keeps the CAP service running, the other runs the commands and UI5 Tooling.

  • Read SAPUI5 and OpenUI5 Basics first, or at least know what a view, a controller and a model are, and read CAP Getting Started for the service part.

  • The first phase builds the same three small files as the guide Your First CAP Service, with four claims instead of one, so you can do this guide on its own. If you did that guide, you know the commands already. The CAP command line tools (@sap/cds-dk) must be installed, as that guide describes.

  • The names are the model’s own: the entity Claims, the status codes N (New), A (Approved) and R (Rejected), the titles and the amounts are made up for this guide. No name comes from an SAP page.

  • The figures are drawings of the editor, the terminal and the browser, not screenshots. A highlighted box with a number marks the file, the command or the address of the step with the same number.

Steps

Create the service

  1. Create the CAP project and install its dependencies. The option --nodejs chooses the JavaScript runtime of CAP:

    cds init claims-ui5 --nodejs
    cd claims-ui5
    npm install

    cds init ends with Successfully initialized CAP project, and npm install with found 0 vulnerabilities. Open the folder in your editor (in Visual Studio Code, code .).

  2. Create the file db/schema.cds. It describes one entity, Claims, with a title, a status and an amount. cuid and managed are ready-made building blocks of CAP that add the key ID and the fields createdAt, createdBy, modifiedAt and modifiedBy:

    using { cuid, managed } from '@sap/cds/common';
    namespace sap.guide.claims;
    
    entity Claims : cuid, managed {
      title  : String(80);
      status : String(1) default 'N';
      amount : Decimal(9,2);
    }
  3. Create the file srv/claim-service.cds. The service ClaimService offers Claims as a projection on the entity, which means unchanged. CAP serves it as an OData V4 service at /odata/v4/claim, derived from the service name:

    using { sap.guide.claims as db } from '../db/schema';
    
    service ClaimService {
      entity Claims as projection on db.Claims;
    }
  4. Create the folder db/data and in it the file sap.guide.claims-Claims.csv with four claims. CAP loads every CSV file in db/data into the database when the server starts. The file name is the namespace, a dash and the entity name:

    ID,title,status,amount
    11111111-1111-1111-1111-111111111111,Train ticket,N,45.50
    22222222-2222-2222-2222-222222222222,Hotel Berlin,A,189.00
    33333333-3333-3333-3333-333333333333,Team lunch,N,62.40
    44444444-4444-4444-4444-444444444444,Conference fee,R,1200.00
    Visual Studio Code with the CAP project claims-ui5: the explorer lists db/schema.cds, the CSV file in db/data and srv/claim-service.cds, the editor shows claim-service.cds with the service ClaimService that exposes Claims as a projection on db.Claims; callout 2 marks schema.cds, callout 3 the service file and callout 4 the CSV file
  5. In the first terminal, in the project folder, start the service in watch mode and leave it running:

    cds watch

    The log lists the three model files, connects to a database that lives only in memory (sqlite { url: ':memory:' }), fills it from your CSV file and ends with server listening on { url: 'http://localhost:4004' }. The line serving ClaimService names the path /odata/v4/claim.

    Terminal after cds watch: the log lists srv/claim-service.cds, db/schema.cds and the common.cds of CAP, connects to an in-memory SQLite database, initializes it from db/data/sap.guide.claims-Claims.csv, serves ClaimService at /odata/v4/claim and ends with server listening on http://localhost:4004; callout 5 marks the command

    The figure leaves out the banner that cds watch prints before the first line.

  6. In the second terminal, ask the service for the title and amount of every claim, sorted by title, with a count. The quotation marks keep your shell from reading the $ and the &:

    curl 'http://localhost:4004/odata/v4/claim/Claims?$select=title,amount&$orderby=title&$count=true'

    The answer is one line of JSON. It names the count, 4, and holds the four claims in the order Conference fee, Hotel Berlin, Team lunch, Train ticket. The key ID is part of every row, and the amount is a string in quotation marks, such as "45.50". The app reads exactly this answer.

    {"@odata.context":"$metadata#Claims","@odata.count":4,"value":[{"title":"Conference fee","amount":"1200.00","ID":"44444444-4444-4444-4444-444444444444"},{"title":"Hotel Berlin","amount":"189.00","ID":"22222222-2222-2222-2222-222222222222"},{"title":"Team lunch","amount":"62.40","ID":"33333333-3333-3333-3333-333333333333"},{"title":"Train ticket","amount":"45.50","ID":"11111111-1111-1111-1111-111111111111"}]}

Create the UI5 project

The app is its own npm project in a folder ui, next to db and srv. It has its own package.json because UI5 Tooling reads the dependencies of the project from it, and the dependencies of the app have nothing to do with those of the service.

  1. Create the folder ui and in it the file ui/package.json. It names one development dependency, UI5 Tooling, and a script start. "type": "module" lets UI5 Tooling load the small JavaScript file of step 9. Then install it from the ui folder and ask for the version:

    {
      "name": "claims-ui",
      "version": "1.0.0",
      "private": true,
      "type": "module",
      "devDependencies": {
        "@ui5/cli": "4.0.73"
      },
      "scripts": {
        "start": "ui5 serve --port 8080"
      }
    }
    cd ui
    npm install
    npx ui5 --version

    npm install prints a few warnings about deprecated packages and a summary of known vulnerabilities. They come from the packages of the UI5 command line tool, which only runs on your machine while you develop; the app itself never loads them. ui5 --version prints 4.0.73 followed by the location of the tool.

  2. Create the file ui/ui5.yaml, the project file of UI5 Tooling. The first part describes the project: the file format specVersion, the project name (it is also the id of the app), the type application and the framework. The framework section names the edition OpenUI5, the version 1.154.0 and the libraries the app needs: sap.ui.core is the base, sap.m has the controls for phones and desktops, and themelib_sap_horizon is the Horizon look. UI5 Tooling downloads these libraries from npm and serves them at /resources, so the app never needs the libraries in package.json. The part after server: and the second document, after the line of three dashes, add a small server extension that step 9 explains:

    specVersion: "4.0"
    metadata:
      name: sap.guide.claims
    type: application
    framework:
      name: OpenUI5
      version: "1.154.0"
      libraries:
        - name: sap.m
        - name: sap.ui.core
        - name: themelib_sap_horizon
    server:
      customMiddleware:
        - name: odata-proxy
          afterMiddleware: compression
          configuration:
            prefix: /odata
            target: http://localhost:4004
    ---
    specVersion: "4.0"
    kind: extension
    type: server-middleware
    metadata:
      name: odata-proxy
    middleware:
      path: lib/odata-proxy.js
  3. Create the folder ui/lib and in it the file odata-proxy.js. The browser loads the app from http://localhost:8080, but the service lives at http://localhost:4004, which is a different origin. A browser lets a page call another origin only when that origin allows it (this is called CORS), and the service of this guide does not allow it for the requests that UI5 sends (the first row of the table in "What can go wrong" shows what that looks like). The way out is to let the browser talk to one origin only. This file is a small server extension for UI5 Tooling, about twenty lines of Node.js that you can read in one go: it takes every request whose path starts with /odata (the prefix of ui5.yaml) and hands it on to the CAP service (the target). Every other request, for the page and for the libraries, goes on to UI5 Tooling as usual:

    import http from "node:http";
    
    // Passes every request whose path starts with the prefix on to the CAP server,
    // so the browser only ever talks to the origin that served the app.
    export default function ({ options }) {
      const target = new URL(options.configuration.target);
      const prefix = options.configuration.prefix;
      return (req, res, next) => {
        if (!req.url.startsWith(prefix)) {
          return next();
        }
        const proxied = http.request(
          {
            host: target.hostname,
            port: target.port,
            path: req.url,
            method: req.method,
            headers: req.headers
          },
          (answer) => {
            res.writeHead(answer.statusCode, answer.headers);
            answer.pipe(res);
          }
        );
        proxied.on("error", next);
        req.pipe(proxied);
      };
    }
  4. Create the folder ui/webapp and in it the start page index.html. The script tag loads resources/sap-ui-core.js, the core of UI5 that UI5 Tooling serves, and its data- attributes set the Horizon theme, the asynchronous loading and the folder that belongs to the namespace sap.guide.claims. ComponentSupport then builds the component from the div with data-sap-ui-component. The height settings on html, body and the div (and data-height) give the page the full height of the browser window, which the page of the app needs to show anything:

    <!DOCTYPE html>
    <html style="height: 100%">
    <head>
      <meta charset="utf-8">
      <title>Expense Claims</title>
      <script id="sap-ui-bootstrap"
        src="resources/sap-ui-core.js"
        data-sap-ui-theme="sap_horizon"
        data-sap-ui-compat-version="edge"
        data-sap-ui-resource-roots='{ "sap.guide.claims": "./" }'
        data-sap-ui-on-init="module:sap/ui/core/ComponentSupport"
        data-sap-ui-async="true"></script>
    </head>
    <body class="sapUiBody" style="height: 100%">
      <div data-sap-ui-component style="height: 100%"
        data-name="sap.guide.claims" data-id="container" data-height="100%"
        data-settings='{ "id": "sap.guide.claims" }'></div>
    </body>
    </html>
    Visual Studio Code with the folder ui in the project: the explorer lists ui/lib/odata-proxy.js, ui/webapp with Component.js, index.html and manifest.json, ui/package.json and ui/ui5.yaml; the editor shows ui5.yaml with the OpenUI5 version 1.154.0, the libraries sap.m, sap.ui.core and themelib_sap_horizon and the middleware odata-proxy that forwards /odata to http://localhost:4004; callout 8 marks ui5.yaml, callout 9 the proxy file and callout 10 index.html

Describe the app

  1. Create the file ui/webapp/Component.js. A UI5 app is a component: a class that the page creates. This one extends UIComponent and says two things: its settings are in a file manifest.json, and it creates its content asynchronously. It needs no more code. The wrapper sap.ui.define loads the modules that the class needs, here UIComponent:

    sap.ui.define([
      "sap/ui/core/UIComponent"
    ], (UIComponent) => {
      "use strict";
    
      return UIComponent.extend("sap.guide.claims.Component", {
        metadata: {
          manifest: "json",
          interfaces: ["sap.ui.core.IAsyncContentCreation"]
        }
      });
    });

    Source: Components

  2. Create the file ui/webapp/manifest.json, the descriptor of the app. sap.app holds the id, the title (a key from the language file, written with two braces) and the data source claimService: the address of the OData service, with a relative path that the proxy of step 9 answers. sap.ui5 names the root view, the libraries and the models. A model is the way a view reaches data. i18n is a resource model that reads the language files and lists the languages the app supports (en and de, English as the fallback). The model with the empty name is the default model: an OData V4 model on the data source. operationMode: "Server" means that filtering and sorting are done by the service, not in the browser, and autoExpandSelect makes UI5 ask only for the fields the view shows:

    {
      "_version": "1.65.0",
      "sap.app": {
        "id": "sap.guide.claims",
        "type": "application",
        "title": "{{appTitle}}",
        "applicationVersion": { "version": "1.0.0" },
        "dataSources": {
          "claimService": {
            "uri": "/odata/v4/claim/",
            "type": "OData",
            "settings": { "odataVersion": "4.0" }
          }
        }
      },
      "sap.ui5": {
        "rootView": {
          "viewName": "sap.guide.claims.view.Claims",
          "type": "XML",
          "id": "claimsView"
        },
        "dependencies": {
          "minUI5Version": "1.154.0",
          "libs": { "sap.m": {}, "sap.ui.core": {} }
        },
        "models": {
          "i18n": {
            "type": "sap.ui.model.resource.ResourceModel",
            "settings": {
              "bundleName": "sap.guide.claims.i18n.i18n",
              "supportedLocales": ["en", "de"],
              "fallbackLocale": "en"
            }
          },
          "": {
            "dataSource": "claimService",
            "settings": { "operationMode": "Server", "autoExpandSelect": true }
          }
        }
      }
    }
    Visual Studio Code with manifest.json open, shortened to its sap.ui5 part: the root view sap.guide.claims.view.Claims, the library dependencies sap.m and sap.ui.core, the i18n model with the supported locales en and de and the default model on the data source claimService with the operation mode Server; callout 11 marks Component.js and callout 12 marks manifest.json in the explorer

    The figure shows the second half of the file, from sap.ui5 on.

Write the view, the controller and the texts

  1. Create the folder ui/webapp/i18n and in it the two language files. Each line is a key, an equals sign and the text. The two files have the same keys. tableTitleCount holds the placeholder {0}, which the controller fills with the number of rows. The files are named i18n_en.properties and i18n_de.properties because the manifest lists the languages en and de:

    appTitle=Expense Claims
    pageTitle=Expense Claims
    searchPlaceholder=Search by title
    tableTitle=Claims
    tableTitleCount=Claims ({0})
    colTitle=Title
    colStatus=Status
    colAmount=Amount
    statusN=New
    statusA=Approved
    statusR=Rejected
    appTitle=Spesenabrechnungen
    pageTitle=Spesenabrechnungen
    searchPlaceholder=Nach Titel suchen
    tableTitle=Abrechnungen
    tableTitleCount=Abrechnungen ({0})
    colTitle=Titel
    colStatus=Status
    colAmount=Betrag
    statusN=Neu
    statusA=Genehmigt
    statusR=Abgelehnt

    Source: Resource Model

  2. Create the folder ui/webapp/view and in it the file Claims.view.xml, the screen. A UI5 view in XML is a tree of controls: a Page with a SearchField in its header and a Table. The texts are bindings to the language files, {i18n>pageTitle} means the key pageTitle of the model i18n. The table items are bound to the path /Claims of the default model, which is the entity set of the service, sorted by title. UI5 repeats the ColumnListItem once per row, and inside it {title} is the title of that row. The status goes through a formatter of the controller, and the amount through the type sap.ui.model.odata.type.Decimal, which turns the string "45.50" into a number that the browser formats for the language of the user:

    <mvc:View
      controllerName="sap.guide.claims.controller.Claims"
      height="100%"
      xmlns="sap.m"
      xmlns:mvc="sap.ui.core.mvc">
      <Page id="page" title="{i18n>pageTitle}">
        <headerContent>
          <SearchField
            id="search"
            width="16rem"
            placeholder="{i18n>searchPlaceholder}"
            search=".onSearch" />
        </headerContent>
        <Table
          id="claimTable"
          updateFinished=".onUpdateFinished"
          items="{
            path: '/Claims',
            sorter: { path: 'title' }
          }">
          <headerToolbar>
            <Toolbar>
              <Title id="tableTitle" text="{i18n>tableTitle}" />
            </Toolbar>
          </headerToolbar>
          <columns>
            <Column><Text text="{i18n>colTitle}" /></Column>
            <Column><Text text="{i18n>colStatus}" /></Column>
            <Column hAlign="End"><Text text="{i18n>colAmount}" /></Column>
          </columns>
          <items>
            <ColumnListItem>
              <cells>
                <ObjectIdentifier title="{title}" />
                <ObjectStatus text="{
                  path: 'status',
                  formatter: '.formatStatus'
                }" />
                <ObjectNumber
                  number="{
                    path: 'amount',
                    type: 'sap.ui.model.odata.type.Decimal',
                    constraints: { precision: 9, scale: 2 }
                  }"
                  unit="EUR" />
              </cells>
            </ColumnListItem>
          </items>
        </Table>
      </Page>
    </mvc:View>

    Source: Views and Data Binding

  3. Create the folder ui/webapp/controller and in it the file Claims.controller.js. The controller holds the code of the view, and its name is the controllerName of the view. formatStatus turns the status code of a row into the word from the language file: N becomes the text of statusN. onUpdateFinished runs when the table has its rows and writes the number of rows into the title of the table. onSearch runs when the user searches and sets a filter on the rows of the table: the service gets the filter and answers with the matching rows only.

    sap.ui.define([
      "sap/ui/core/mvc/Controller",
      "sap/ui/model/Filter",
      "sap/ui/model/FilterOperator"
    ], (Controller, Filter, FilterOperator) => {
      "use strict";
    
      return Controller.extend("sap.guide.claims.controller.Claims", {
        // The bundle of the i18n model: the texts in the user's language.
        getBundle() {
          return this.getView().getModel("i18n").getResourceBundle();
        },
    
        // Turns the status code of the service into a word from the i18n file.
        formatStatus(code) {
          return this.getBundle().getText("status" + code);
        },
    
        // Runs when the table has read its rows: show how many there are.
        onUpdateFinished(event) {
          const total = event.getParameter("total");
          const text = this.getBundle().getText("tableTitleCount", [total]);
          this.byId("tableTitle").setText(text);
        },
    
        // Runs when the user searches: ask the service for the matching rows only.
        onSearch(event) {
          const query = event.getParameter("query");
          const filters = [];
          if (query) {
            filters.push(new Filter("title", FilterOperator.Contains, query));
          }
          this.byId("claimTable").getBinding("items").filter(filters);
        }
      });
    });

    Source: Controller

    Visual Studio Code with Claims.view.xml open, shortened to its first 30 lines: the view names its controller, the page with the search field in the header and the table bound to /Claims sorted by title with a toolbar title and three columns; callout 13 marks the i18n file i18n_en.properties, callout 14 marks the view file and callout 15 marks the controller file in the explorer

    The figure shows the first 30 lines of the view.

Run the app

  1. In the second terminal, from the project folder, start UI5 Tooling. The script start of ui/package.json runs ui5 serve --port 8080. Leave both terminals running:

    cd ui
    npm start

    The output names the script, the OpenUI5 version (1.154.0) and the address:

    > claims-ui@1.0.0 start
    > ui5 serve --port 8080
    
    info graph:helpers:ui5Framework Using OpenUI5 version: 1.154.0
    Server started
    URL: http://localhost:8080
    Terminal in the folder ui after npm start: the script runs ui5 serve with port 8080, UI5 Tooling reports that it uses OpenUI5 version 1.154.0 and that the server started at http://localhost:8080; callout 16 marks the command
  2. Open http://localhost:8080/index.html?sap-ui-language=en in the browser. The parameter sap-ui-language sets the language of the page, so you see the English texts whatever your browser uses. The page title is Expense Claims, the table is titled Claims (4) and lists the four claims sorted by title, with the status words and the amounts followed by EUR.

    Browser at localhost:8080/index.html with the language parameter en, marked by callout 17: the app Expense Claims shows a search field in the page header and the table Claims (4) with the columns Title, Status and Amount and the rows Conference fee, Hotel Berlin, Team lunch and Train ticket, sorted by title, with the status words Rejected, Approved, New and New and the amounts with EUR
  3. Type Ho into the search field and press Enter. The table shrinks to one row, Hotel Berlin, and its title reads Claims (1). The filtering happens in the service: the request that UI5 sent, read from the browser, asks for the claims whose title contains Ho. UI5 sends its requests in a batch (a POST to /odata/v4/claim/$batch), and the request inside it reads:

    GET Claims?$orderby=title&$select=ID,amount,status,title&$filter=contains(title,'Ho')&$skip=0&$top=100

    The field only asks for the fields the view shows, as autoExpandSelect of step 12 promised.

Check the result

  • Both terminals show no line that starts with [ERROR], and the one of UI5 Tooling ends with URL: http://localhost:8080.

  • The page shows the title Expense Claims, the table Claims (4) with four rows and the search field.

  • A search for Ho leaves the row Hotel Berlin and the title Claims (1). An empty search shows the four rows again.

  • The lab project holds two small checks that you can run from the project folder (not the ui folder) with npm test: they read the service and compare the keys of the view and the controller with the two language files.

Variations

  • Open http://localhost:8080/index.html?sap-ui-language=de. The same app now reads i18n_de.properties: the page title is Spesenabrechnungen, the table is Abrechnungen (4), the columns are Titel, Status and Betrag, the status words are Abgelehnt, Genehmigt and Neu, and the amounts are written the German way, for example 1.200,00 EUR. You did not format anything in code: the Decimal type uses the format of the language.

  • Search for ho in lower case. The table shows Claims (0) and the text No data, because the service matched only the upper and lower case that you typed: Hotel Berlin contains Ho, not ho.

What can go wrong

Symptom Cause Fix

The table says No data. The console reads Could not load metadata: 0 error, and the network list shows an OPTIONS request for $metadata that is answered with 200 followed by a GET that fails. This is what you get when the uri in manifest.json is the address of the service itself, http://localhost:4004/odata/v4/claim/.

The page and the service are different origins. In development CAP answers with an access-control-allow-origin header, but its answer to the check that the browser makes before a request with OData headers does not list those headers, so the browser stops the request.

Use the relative path /odata/v4/claim/ in the manifest and the proxy of step 9.

The table says No data, and curl http://localhost:8080/odata/v4/claim/$metadata answers HTTP 500 with an ECONNREFUSED error in the text.

The CAP service is not running, so the proxy of UI5 Tooling finds nothing at port 4004.

Start cds watch in the project folder and reload the page.

The page shows the title and the search field but no table, and the console has no error.

The page, the component and the view have no height, so the content of the page is 0 pixels high.

Check that html, body and the div of index.html have height: 100%, that the div has data-height="100%" and that the root element of the view has height="100%".

A white page. The console reads Unsupported operation mode: undefined.

The default model in manifest.json has no operationMode.

Add "operationMode": "Server" to the settings of the model with the empty name.

The page title shows pageTitel instead of a text, and the console reads could not find any translatable text for key 'pageTitel' in bundle file(s): './i18n/i18n_en.properties'.

The key in the view is misspelled: UI5 shows the key itself when the file does not have it.

Correct the key in the view or add it to both language files.

ui5 serve stops with Duplicate framework dependency definition(s) found for project sap.guide.claims.

OpenUI5 libraries such as @openui5/sap.m were added to ui/package.json as well as ui5.yaml.

Remove them from package.json. The libraries are named only in ui5.yaml.

Clean up

Press Ctrl+C in both terminals. The database lived only in memory, so there is nothing to delete. UI5 Tooling keeps the downloaded OpenUI5 libraries in a folder in your home directory (~/.ui5), where other UI5 projects reuse them. The folder claims-ui5 is yours to keep.

Where to go next