
Creating an attribute view
The first object we'll be creating is called an attribute view. This is the basic building-block for nearly all SAP HANA developments.
An attribute view takes the characteristic (text) information from one or more tables, and presents it to the user. It allows several operations to be carried out on data such as the following:
- Information can be filtered on specific values
- Tables can be joined together
- Certain fields can be hidden from the user if they are not appropriate to the current development
Note
Attribute views have one major restriction: they cannot work with numeric information. You cannot, for example, use a
SALARY
orREVENUE
field in an attribute view. To work with numeric information, we'll use an analytic view, which we'll be looking at in Chapter 4, Painting with Numbers – An Analytic View.
In our attribute view, we'll be using the data from our CUSTOMER
table. This table has four fields: MANDT
, CUSTID
, SECTOR
, and COUNTRY
. We'll only be using three of these fields in our development, so our attribute view will serve to hide the field we don't need—MANDT
.
From the Quick Launch panel, select Attribute View, then Create, to view the Attribute view creation dialog:

We need to give our view a Name (only uppercase letters, numbers and the underscore character are allowed) and a Description (which automatically takes the value of the Name field). Additionally, we need to specify in which Package this object is to be created. In the preceding screenshot we can see that the Package we created in the previous section was selected.
The View Type field allows for creation of attribute or analytic views. We'll be looking at analytic views in the next chapter, so leave Attribute View selected for now.
To save time in creating several similar views, or views on the same base table, we can create our views by copying an existing view. To do this, just check the Copy From checkbox, then select the source view using the Browse button. This is a function we'll be using in a later development.
Finally, we need to choose the type of attribute view we are creating:
- Standard: The basic attribute view, exposing different fields of one or more base tables.
- Time: A specific attribute view used to hold time information, including the link between a specific date and a month, for example. By default, SAP HANA has no notion of time, so it does not know that the date 30 November 2012 is in the eleventh month, or even that it is in 2012. An attribute view of time information is used to provide this basic information to your developments, by running a program which creates the calendar information and stores it.
- Derived: As we saw, we can create an attribute view by copying an existing object. Creating a derived view is very similar. A derived view acts like a pointer to a source view; if we create view B derived from view A, then if we make a change to view A, view B will also be impacted. This is different to the notion of create by copy where if view B was created as a copy of view A, and we modified view A later, nothing would change in view B.
The view we are creating here is a Standard view, so leave this option selected. The dialog allows selection of tables to add to the view via the Next button, but we'll create our view first, and add the base tables later as this allows us to take our time to examine the view.
Click on Finish when you are ready.
At this point we are presented with the attribute view creation screen:

The preceding screenshot shows the different aspects of the attribute view. On the left-hand side of the screen is the Scenario. If we follow the diagram from bottom to top (in the direction of the arrow), data will flow from the base tables (in the Data Foundation) into the view, represented by the Semantics block. The Semantics block represents the visible part, the result of the view.
The right-hand side of the screen is split into three panels. At the top, we have some basic Properties of the view. At the bottom, there is a panel called Column, which will contain the different columns of the view once we have created some, and on the right-hand side, a panel containing any Hierarchies used in the view. We'll be looking at hierarchies in detail in Chapter 8, On Another Level – Hierarchies in SAP HANA.
As you can see in the screenshot, the view right now contains no data at all, since no tables have as yet been selected. Adding a table to the view is done by drag-and-drop, from the Catalog node in the Navigator panel, to the Data Foundation box in the view, or by clicking on the green plus sign which appears when you hover the mouse over the Data Foundation box, and then typing the name of the table to add in the filter of the Find dialog which appears, as you can see in the following screenshot:

When you start typing the name of a table in the filter box at the top of the dialog, the Studio will search for and list all tables whose names match what you type, making finding tables much easier. Just click on a table name to select it, and then click on OK to add it to the view.
Please add the CUSTOMER
table from the BOOK
schema to the view now. As soon as the table has been added, we can see the list of its fields in the middle of the screen in the Details panel.
At this point we just add to the view the fields needed from the table, by right-clicking on each one, and selecting Add to Output from the menu. We only need to add the CUSTID
, SECTOR
, and COUNTRY
fields to our view. Once this is done, your view should look just like the following screenshot:

Before we can use our view, we need to define which field or fields will be the key fields. This is exactly the same principle as for a database table; a view needs to have at least one key field, or else you won't be able to use it.
Marking a field as a key field is simple; in the view definition window, click on the Semantics block. You will be presented with the grid of fields in the view. In this grid, the first column is Type
. At the moment, all the fields in the view have a blue icon in the Type
column, indicating that they are regular fields, as we can see in the following screenshot:

To define a field as a key field, double-click on the blue icon next to the field, and select Key Attribute from the menu which appears. This will change the icon, showing (with a little imagination) a key and a green star.
In our view, the key field is the CUSTID
, so please change this attribute to a key attribute now. Once this has been done, we will obtain the final version of our view, which should look like the following screenshot:

The definition of our first attribute view is finished. Yay! Let's take a look at the contents of the view now. A view is basically like a table; you can take a look at its contents just like you would for a table, using the data preview function we saw in the previous chapter. Before we can do this however, we need to activate the view.
Activation is a concept readers familiar with SAP's ERP or BW software will have come across often. It basically means compilation of the object we have just created visually, turning it into the underlying SQL statements. Activation allows the SAP HANA system to be sure that each object is coherent when the user asks for an object's contents. When an object is created in the Studio (like the view we have just built), only its definition is stored in the database. It does not actually exist as a usable object until it has been activated.
To activate our view, simply click on the round, green, button with the right-facing arrow at the top-right of the view definition panel. The appropriate button is highlighted in the following screenshot:

SAP HANA will check that your view is coherent, and then create the runtime version. This system has another advantage—once an object's runtime version exists, none of the changes we make to the object will be visible until that object is activated once more. There can be two versions of an object in the system at the same time, one active and one inactive.
Activation will take a couple of seconds, and you will see in the Job Log panel the results of the activation, as we can see in the following screenshot:

Once your view has been activated, it is ready for use. You will see it listed in the Content node of the Navigator panel, as you can see in the following screenshot:

You can now request a Data Preview of the view, in the same way we looked at the contents of the tables earlier. The data in the view should look like this (depending on the order you choose the output fields, the columns in the grid might be arranged differently).
