Show TOC

Meta Model for OData V4Locate this document in the navigation structure

Each OData V4 model offers access via getMetaModel to a corresponding metadata model sap.ui.model.odata.v4.ODataMetaModel, which is read-only and offers access to OData V4 metadata in a streamlined JSON format (see links under Related Information for more details). Only one-time bindings are supported by this model because the metadata is immutable.

Synchronous vs. Asynchronous Access

Access to metadata is basically asynchronous (e.g. requestObject) to allow for dynamic loading of metadata. There is also a corresponding method for synchronous access (e.g. getObject) which returns undefined if metadata is not yet available. It should only be used in situations where metadata has already been loaded asynchronously before. Loading happens individually for each document, i.e. each $metadata document is loaded and processed as a whole and is available thereafter. Includes and references to other $metadata documents are not supported, only the service root's initial $metadata document can be used.

Path Syntax

The requestObject API documentation in the Demo Kit explains how metadata is accessed and the supported path syntax in great detail. The basic idea is that every path described in the specification OData Version 4.0 Part 3: Common Schema Definition Language, 14.2.1 Attribute TargetInformation published on non-SAP site is a valid absolute path within the metadata model if a leading slash is added; for example "/" + "MySchema.MyEntityContainer/MyEntitySet/MyComplexProperty/MyNavigationProperty".


The main API for both programmatic access from JavaScript and declarative access from XML templating is sap.ui.model.odata.v4.ODataMetaModel#getObject. It works together with sap.ui.model.odata.v4.ODataMetaModel#resolve (for <template:with>) and sap.ui.model.odata.v4.ODataMetaModel#bindList (for <template:repeat>) in order to provide convenient access to annotations, inline as well as external targeting.

The OData meta model knows how to follow "14.2.1 Attribute Target" described in specification "OData Version 4.0 Part 3: Common Schema Definition Language" as well as "14.5.2 Expression edm:AnnotationPath", "14.5.11 Expression edm:NavigationPropertyPath", "14.5.12 Expression edm:Path", and "14.5.13 Expression edm:PropertyPath".

XML Templating still works the same as for V2, with some slight changes as outlined below:
  • Metadata paths need to refer to the V4 metadata JSON structure.

  • Note the difference between "/TEAMS@Org.OData.Capabilities.V1.TopSupported" and "/TEAMS/" (look closely at the slash!) as explained in the requestObject API documentation in the Demo Kit (see link under Related Information).

  • sap.ui.model.odata.AnnotationHelper cannot be used for OData V4. Instead, the ability to follow a path has been built into the V4 OData meta model itself. See field>Value/$ in the code example below.

  • Use sap.ui.model.odata.v4.ODataMetaModel#requestObject instead of sap.ui.model.odata.ODataMetaModel#loaded to load metadata initially. Prepare for future load-on-demand by specifiying the right entity set or type that you require, e.g. oMetaModel.requestObject("/BusinessPartnerList/") for the example shown below.

Example of an OData V4 XML template:

<template:with path="meta>/BusinessPartnerList/" var="entityType">
  <template:with path="entityType>" var="lineItem">
    <Table headerText="Business Partners"
      items="{path:'/BusinessPartnerList', length: 5}">
        <template:repeat list="{lineItem>}" var="field">
            <template:if test="{field>Label}">
                <Label design="{:= ${field>$EnumMember}
                  === '' ? 'Bold' : 'Standard'}"
                <Text text="{field>Value/$}"/>
            <template:repeat list="{lineItem>}" var="field">
              <template:with path="field>Value/$Path" var="target">
                <template:if test="{target>}">
                    <template:if test="{= ${target>$EnumMember}
                      === '' }">
                      <Text text="{= '{' + ${target>} + '} {'
                        + ${target>$Path} + '}' }" />
                    <Text text="{= '{' + ${target>} + '}' }" />