If you are an experienced Fiori developer, you may already know this. If you are starting with mobile application development for SAP or you are a back-end developer who needs to make Fiori applications, I advise you to keep reading.
In this new scenario presented by S4 / HANA, there is the possibility of making Fiori applications without the need to insert any line of code in the Front-End. And this is achieved thanks to CDS annotations.
What are Fiori CDS annotations?
I’m going to define it for you in a not very technical but easy to understand way: they are small lines of code in the back-end that define what functionality and what design our application will have.
In today’s article, we are going to see examples of basic annotations to build our List Report. As you can see in this blog, I like to structure trainings by series or programs, so this will be the first of many articles related to CDS annotations, starting from the most basic to more complex examples.
Shaping our List Report
In creating the main table of a Fiori List Report App, I consider it essential to know the following annotations:
The UI.lineItem annotation is used to represent the information we retrieved from the CDS view in our table. In other words, it will be in charge of indicating which fields are going to represent a column of our table.
The main property of this annotation is UI.lineItem.position. This property indicates the column position in our table, starting with 10, 20, 30…. The UI.lineItem annotation has many properties that allow us to configure the table practically to our liking.
Another property that we can see in the image is UI.lineItem.criticality, which is used for fields that indicate a state, and that allows the text of that column to be colored using a numeric value. The value 0 corresponds to the Neutral color, the value 1 to the Negative color (red), the value 2 to the Critical color (orange) and the value 3 to the Positive color (green).
Another interesting property is UI.lineItem.exclude. This property tells our oData annotation whether this field should be excluded or not. Its possible values are: true or false, being true by default.
Lastly, we have the UI.lineItem.type property. This property, as its name makes us guess, indicates the type of value that our column will represent. Within this property there are several possibilities, but for now, we will stay with that the default type is the Standard type, which corresponds to a column with a text that represents information. Later, in future articles, we will see the different possibilities with examples for each of the column types.
There are many other properties for this type of annotation, which we can find in the SAP reference documentation. However, I believe that these are the most basic and fundamental to be able to represent the information of the CDS view in our List Report.
The Ui.selectionField annotation allows us to indicate which fields we are going to use to filter our List Report.
As in the UI.lineItem annotation, we must indicate what position our selection field occupies. In this case, the position corresponds to the order in which the fields will appear in the header of our List Report.
As we can see in the example code, we have indicated position 10 for the Material field and position 20 for the Description field, which causes the selection fields to be represented as in the image.
In addition to the selection fields, we have the possibility of adding a search field that allows combining codes and descriptions to perform complex searches.
To achieve this, we must first add the following annotation to the beginning of our CDS view:
Once we have indicated to the CDS view that we are going to allow the search, we will be able to see immediately in our application that we can already visualize the search field in the header.
Now we only need to indicate which fields we are going to allow filtering through the search engine. To do this, we make use of the Search.defaultSearchElement annotation.
In this way, we have indicated that the search engine allows filtering by the Description field. Furthermore, we have indicated that the precision level will be 0.9. This level of precision indicates how exact the results have to be according to what we have written in the search engine.
Basic List Report
The power of CDS annotations lies in the ability to perform data query reports without the need to implement any line of SAPUI5 code. As we have seen, we can have an application with a list similar to an ALV based on a main CDS view that retrieves information and a few basic annotations about our CDS. In the next article of this series we will see the basic annotations to represent the information of our Object Page, detail page of each element of our list.