Using Data Types 

Objectives

After completing this lesson, you will be able to:

  • Define data types
  • Discover different data types
  • Explain the benefits of data types

Definition of Data Types

Data types let you define the type of data you will store in a variable and, therefore, the type of data you expect whenever you update the data in that variable.

For example, if you have a variable that stores the color the user wants for the background, then the data type of the variable would be of type color. You will get an error if you try to store a value not of type color (for example, "#435647") in that variable.

If you have a variable that stores the name of a new To Do item, then the data type of the variable would be of type text, representing the name of the To Do item.

When you define a new variable, you can define the type of the variable on the right side.

Type of Variables

Note that data types are used not just for variables but also to define schemas–or the data types and organization of larger sets of data–for data resources. There are fewer data types available for data resource schemas.

Different Data Types

Here are the currently supported data types divided into four groups:

  • Simple Types
  • Text Types with Specific Format
  • Reference Types
  • Complex Types

Examples of Simple Types

TypeExample
Number123
BooleanTrue
StringTree

Text Types with Specific Format

Text TypeSpecific Format
Email addressworkshop@sap.com
Date/time (ISO 8601)2023-05-14T07:08:05.671Z
Date text (ISO 8601)2023-01-01
URLhttps://www.sap.com
Web URL (http/https)https://www.sap.com
Image URLhttps://www.sap.com
Icon name

Generally, the UI will provide a selection component to select an icon, though you can define an icon with a formula like this:

{set: "fontAwesome", name: "star"}

Color code#000000
UUID4d7dfe35-9cd3-4eba-8051-4b91858abb35
Integer text123
Numeric text123.1
Percentage text100%
MIME content typetext/plain
Local file system path

Depends on device. Here’s example on Windows:

blob:https://mytenant.preview.eu10.apps.build.cloud.sap/2361fe23-4817-4303-a6c5-8c69d2656df1

Any textAny text

Reference Types

Reference TypeSpecific Format
Icon

This is a JSON representation of an icon, including the icon set and icon.

{"set":"fiori","name":"windows-doors"}

Complex Types

Complex TypeSpecific Format
ObjectAn object is a wrapper that includes a set of properties, each of which can have a data type itself.
ListA set of values (or objects) of the same data type.
Any valueAny type of value

Importance of Data Types

Why is it important to define variables with the right data type?

With the correct data type, SAP Build Apps will check whether you are assigning the correct data for that data type. Generally, SAP Build Apps does not prevent you from storing a value that does not conform to the data type, but it will warn you that something is wrong.

For example, if you have a variable of type Number, you could still assign it "Apple" and that value will display. But SAP Build Apps will warn you.

It is possible to reset the variable data logic by selecting the "Reset data variable logic" button.

The data types are especially important in two areas: Property Editor and Formula Editor.

Property Editor

When setting values for a variable, the property editor will give you an interface designed for that type. Let’s consider that you have a variable of type Color.

A Variable: Color Code

In the example value, you will get a user interface, especially for defining color.

The UI for a Variable: Color Code 1

The same would be true if you were setting its value in a flow function in the logic canvas.

The UI for a Variable: Color Code 2

Formula Editor

Similarly, the formula editor takes note of the data type and warns you if the result of the formula conforms to the data type of the current property.

Let’s say you have a button and want to use a formula to set the color of the button text.

Changing the Color of a Button

If the formula does not conform to the data type, the formula editor will display a warning, and the formula will display in red. Also, note that the formula editor at the top shows what data type it expects.

Example in the Formula Editor

Note that the Save button is still enabled, so you are not prevented from using the formula. Since the data type says to expect a color, you are warned, but SAP Build Apps does not want to tie your hands in case there is a reason you want to set the color variable to a plain string.

Log in to track your progress & complete quizzes