Create a Data Model and Expose It as a Service
- How to create a project from scratch
- How to create a data model for your application
- How to expose the data using a service so that you’ll be able to use it in your apps
- How to add sample data
- How to preview the service definition
- How to view the data before creating apps
Prerequisites
- You have access to SAP Business Application Studio and created a Low-Code-Based Full-Stack Cloud Application dev space, as described in Set Up SAP Business Application Studio for Low-Code Development in the Trial Environment.
- Step 1
-
Enter the Dev Space you created in Set Up SAP Business Application Studio for Low-Code Development in the Trial Environment.
-
If no project exists in a dev space the Create Project dialog box opens. Enter the Project Name, for example,
CapitalExpenditures
, and click Create.If a project already exists in your dev space, you can create an additional project by selecting Project -> Create in the Home tab.
-
Wait for the homepage of SAP Business Application Studio for low-code development to load with the new project.
Wait for the “We have finished installing all tools and templates for you, enjoy your work!” notification.
Loading SAP Business Application Studio for low-code development may take some time, especially if it’s the first time in a day.
Close the notification icon at the bottom of the screen (optional).
-
- Step 2
From the homepage, click the + of the Data Models tile to add a data model to your project.
Provide an Entity Name for the entity, for example,
Capex
.Click the + to add a property to the
Capex
entity.Select the following:
Step Parameter Value A Property Name description B Property Type String (default) C Key Leave unchecked (default) D Null Yes (default) E Arrayed Leave unchecked (default) F Max Length Leave empty G Default Value Leave empty (default) Add the following property (click +). When done with adding the properties choose Create.
Step Parameter Value A Property Name total_cost
B Property Type Integer C Key Leave unchecked (default) D Null Yes (default) E Arrayed Leave unchecked (default) F Default Value Leave empty (default) The
Capex
entity appears in the Data Model Editor tab with a default ID property.To add another data model to your project click the
Add Entity
button in the Data Model Editor tab.A new entity appears in the Data Model Editor tab.
To edit the entity, click the entity’s header and choose the Edit Entity icon.
Provide an Entity Name for the entity, for example, Contractors.
Change the Property Name of the ID property to contractor, and its Property Type to Integer.
Add the following property to the Contractors entity, and choose Update.
Step Parameter Value A Property Name name B Property Type String (default) C Key Leave unchecked (default) D Null Yes (default) E Arrayed Leave unchecked (default) F Max Length Leave empty G Default Value Leave empty (default) The Contractors entity appears in the Data Model Editor.
- Step 3
With relationships you can connect your entities. To do so, select the
Capex
entity, choose the Add Relationship icon, and select the Contractors entity to add a relationship to the Contractors entity.Select the following, and choose Create.
Step Parameter Value A Relationship Type Association (default) B Multiplicity To-One (default) C Key Property No (default) D Property Name contractor E Target Entity CapitalExpenditures.Contractors (default) F Backlink Property Leave empty (default) You can re-arrange the entities on the canvas by clicking the Auto Layout icon to improve the data model visualization. In addition, you can also manually drag the entities over the canvas.
- Step 4
-
Access the Home tab.
-
Click the + of the Services tile to add a service through which data from the data model can be accessed.
-
Define the following for your new service, and choose Create.
Step Parameter Value A Name Capex
B Namespace CapitalExpendituresService
(default)C Type CapitalExpenditures.Capex
D <all properties> Leave checked (default) E ID Leave checked (default) F description Leave checked (default) G total_cost
Leave checked (default) H contractor Leave checked (default) The
Capex
service appears in the Service Editor tab. -
To add another new service to your project click the
Add Entity
button in the Service Editor tab, define the following, and choose Create.Step Parameter Value A Name Contractors B Namespace CapitalExpendituresService
(default)C Type CapitalExpenditures.Contractors
D <all properties> Leave checked (default) E contractor Leave checked (default) F name Leave checked (default) The Contractors service is added to the Service Editor, with association to the
Capex
service. -
Select the
Capex
service (which gets highlighted with a blue rectangle indication), and check the Draft Editing property.A draft is an interim version of a business entity that has not yet been explicitly saved as an active version. This allows users to pause, for example when being interrupted, and continue later on. For more information visit SAP Fiori Design Guidelines - Draft Handling.
-
You can re-arrange the entities on the canvas by clicking the Auto Layout icon to improve the service visualization. In addition, you can also manually drag the entities over the canvas.
-
Access the Home tab. You can see that both the services are added to the Services tile.
-
- Step 5
It is a common practice in software development to test run any change to an app as soon as possible. Prior to having the services defined, you were not able to test the app. Since now you have defined the services, you can test them.
Choose the Preview option from the homepage, and select Run CapitalExpenditures-1.
Troubleshooting:
CapitalExpenditures
is the name you have previously chosen for your project. If you have chosen a different name, this name will be displayed, for example, Run DifferentName-1.The project preview page appears in a new tab with the links which allow you to test the service definition, access data exposed by the service, and more.
In the preview page on the right side under Services choose the metadata link to view the service’s XML. Close the XML file.
Also in the preview page on the right side under Services select the button view as code next to
Capex
or Contractors to view the data from the respective service.Here, the value appears as an empty list since the data model is empty.
- Step 6
To test that the service works well, that is, returns data when it is available in the data model, let’s add sample data to your project. Sample data is a powerful tool as it allows you to (1) develop an app with no connectivity to a data source; (2) Debug your app.
Go back to the browser tab with SAP Business Application Studio for low-code development, and click the + of the Sample Data tile.
Select Contractors, select Create, and press Add.
In the sample data editor add 4 rows.
Update the sample data as follows:
Access the Home tab, and click the + of the Sample Data tile.
Select
Capex
, select Create, and press Add.In the sample data editor add 3 rows, and update the DESCRIPTION and CONTRACTOR columns as follows:
Access the Home tab. You can see that the sample data is added to the Sample Data tile.
Go back to the project preview browser tab, and select the button view as code next to
Capex
or Contractors. You can view the sample data you have added.
When the app is running, how does it access the data?