Many SAP practitioners reported that the videos on open SAP could not be accessed due to network reasons, so I will add Chinese subtitles to these videos on my personal micro signal “Wang Zixi” and publish them. Please pay attention.
The topic of this module is the in-depth explanation of SAP OData and annotations.
The following are the Chinese subtitles of the video explanation of this unit, which are manually translated by Jerry.
====
Welcome to unit 3 of open SAP Fiori elements. This module introduces OData and annotations
I’m Stefan Engelhardt, the development architect of SAP Fiori elements
In unit 2, Marcel has briefly introduced OData Every Fiori elements application needs an OData service
Fiori elements has no special requirements for the background technology stack of OData service, because the OData protocol itself is an abstraction of the background implementation details
Now we will introduce the core concepts of OData service in depth. Start with the meta description of the data model
Each OData service has meta description information of its data model. On the right side of the screen is an example
We usually call it OData metadata for short. Add $metadata after OData URL to view its metadata
The hyperlink at the bottom left of the screen is the full URL of the OData metadata
Metadata defines the business model and its attributes
On the right of the figure below is an example of OData V4, which defines a person model
Including user name, firstname and other fields
Attributes in metadata also have further definitions
These further definitions contain the data types of attributes, such as EDM String, whether null value and maximum field length are allowed to be stored
Fields that describe the relationship between an entity and other entities are called navigation fields
The navigation field of the model indicates the cardinality relationship between the model and its navigation target model, that is, “one to one” or “one to many”
For example, the navigation attribute named trips in the screen points to the target model trip, and the type is collection, indicating that the two models of person and trip are one to many
In addition, metadata can also contain definitions of complex types, actions, singletons, and so on
Marcel introduced in the previous module that OData supports the operation of adding, deleting, modifying and querying
Let’s look at some examples
Here we can see the HTTP request and response to an OData service
The first scenario is to read all people The type of people is person, which is defined in metadata
The HTTP response contains the corresponding data set. The first record in the results list is Russell Whyte
We can also query a specific person record by specifying a key
Add the key value Russell Whyte to the curly brackets. In the response, you can see that the request only returns one piece of corresponding data
Let’s look at some more complex queries
Use $top to return only the first two records. Using $select, only the firstname and LastName fields are read
Filter the result set again if you have at least one trip record and the cost is more than 3000
As you can see, we can construct complex query statements very flexibly
Now show me how to create a person record
Use HTTP post request to maintain person data in the request body
The response returns an HTTP 201 status code, indicating that the data was created successfully
In order to improve Fiori user experience, SAP defines a standardized processing mechanism that supports the draft version of documents
With the draft mechanism, users’ editing of documents can be interrupted and continued at any time
Only after the user completes editing, the document data will be stored in the corresponding database table
In SAP Fiori elements application, whenever users add or change information in editing mode, the data of draft version will be saved automatically
This automatically saved request response may contain some prompt messages. For example, the sold to Party of salesarea is not maintained
When the data of the sold to party changes, the HTTP response contains all the data of the party for display on the UI
Such as address and contact information. Make draft interactive
Note that the draft mechanism should provide out of the box support through the framework
If the whole draft processing mechanism is re implemented at the application level, the workload is quite huge
Marcel introduced the odcel. These annotations provide more descriptive information about the model in terms of behavior and consumption patterns
Now I’ll explain how OData annotations work and give examples
Annotations are additional metadata of OData in XML format
Annotations are defined in the glossary maintained by OData and SAP
Annotations are abstract definitions, so they are relatively stable and will not change frequently. They can be parsed by consumers including SAP ui5
SAP Fiori elements parses annotations and generates corresponding UI pages
Take a specific example: the total price field in travel app
In the OData measures vocabulary, there is an isocurrency annotation
The totalprice type in OData metadata is annotated and points to the target field currencycode
Therefore, the framework code can understand that totalprice is a monetary amount, and the currencycode field contains the monetary unit
Fiori elements displays the currency unit on the right side of the amount field
This annotation is also used to display the corresponding decimal according to the monetary unit and ensure that the display of the amount can also be correctly aligned in the table
Annotations, of course, can also define more complex UI elements
For example, these UIs can be through UI Table defined by lineitem
Via UI Form defined by fieldgroup through UI Chart defined by chart, etc
In addition, annotations can describe the application in terms of behavior
An example is to provide functions such as addition, deletion, modification and query in the application
For example, through annotation, you can specify that the travel model can be edited, so Fiori elements draws the Edit button on the UI
The display or hiding logic of other buttons in the toolbar is the same
Another scenario is the definition of the so-called side effect
For example, when the product unit price at the item level of the table line changes, the UI needs to re read the total price information of the latest order header level from the background
The SAP system background can provide annotations based on ABAP CDs or cap CDs
Alternatively, annotations defined in local files can be used. For the UI, it doesn’t care whether the annotations come from the background server or local files
The annotations in CDs view are translated into XML format by the background server
The latter is parsed by Fiori elements framework
Annotations in XML format can be used by any type of background server
These background servers can be SAP’s traditional ABAP programming model, SAP BW and non SAP servers. The right side of the figure below is an example of ABAP CDs annotation
Your preference for development tools may affect your choice of annotation types
In SAP Fiori tools, the wizard creation steps provided can help us create correct annotations
Both XML and cap CDs annotations can be supported by SAP Fiori tools
If you use ABAP development tool, you can maintain annotations directly in ABAP CDs
Lifecycle management and functional availability also affect the selection of annotation types
The annotation provided by the local file of the UI project has the same life cycle as the application. The life cycle of CDs annotation is consistent with the implementation of OData service
If we are developing on a lower version of ABAP server, some annotations may not be supported. If in doubt, consult the documentation
Let’s summarize the content of this unit
We introduced the core part of OData concept, OData metadata, OData request, and draft mechanism
We also learned what OData annotation is and how it affects Fiori elements application
Now you can look forward to the next module. At that time, we will introduce how to build the development environment of Fiori elements application. Thanks for watching this video. See you next time
More Jerry’s original articles are: “Wang Zixi”: