Use OData Metadata to dynamically create the columns
Use OData Metadata to dynamically create the columns
Overview
Prerequisites
Prerequisites
- This tutorial is designed for SAP HANA on premise and SAP HANA, express edition. It is not designed for SAP HANA Cloud.
- Proficiency: Intermediate
- Tutorials: Consume a Basic OData Service
Steps
In the previous tutorial, you hard-coded the columns to be displayed from your OData service. However, OData services expose all their meta data and we can use this feature to build the columns dynamically. You can test this by running the web module and calling the OData service and adding $metadata

You can see the service exposes the names of the fields and other properties such as the length.
Return to the controller of odataBasic from the previous tutorial and replace the following lines:

With the following code:
function fnLoadMetadata() {
try {
oTable.setModel(bpModel);
oTable.setEntitySet("BusinessPartners");
var oMeta = bpModel.getServiceMetadata();
var headerFields = "";
for (var i = 0; i < oMeta.dataServices.schema[0].entityType[0].property.length; i++) {
var property = oMeta.dataServices.schema[0].entityType[0].property[i];
headerFields += property.name + ",";
}
oTable.setInitiallyVisibleFields(headerFields);
} catch (e) {
console.log(e.toString());
oDataFailed();
}
}
bpModel.attachMetadataLoaded(bpModel, function () {
fnLoadMetadata();
});
fnLoadMetadata();You can see the new function that retrieves the metadata from the service, loops at the results and concatenates the names of the fields separated by a comma. The fields are then attached to the bpModel component.
Save the files you have modified and run the web module:

Resources
Discussion
Share feedback on this tutorial or join the conversation in SAP Community.