ABAP News for Release 7.50 – Annotations in ABAP CDS
ABAP CDS in TechEd Keynote
Bjoern Goerke has shown ABAP CDS in his keynote for TechEd Barcelona, yes, ABAP!
Interestingly, he did not talk much about all the DDL language elements of ABAP CDS. In fact, he used quite a simple CDS view:
The select statement of the view wraps the access to database table zbg_marsdata. Some of the modeling capapbilities of CDS shine through with the association _MarsSite that joins Z_MarsRoverMissions with Z_MarsSites. But this was of marginal importance for the presentation.
What he did talk about were annotations!
The DDL source code consists mainly of annotations and not of SQL! What’s that all about?
With annotations, you can semantically enrich your data model. And as you see, this is abundantly done above. Let’s have a look behind the curtain.
What are Annotations?
From the compiler’s point of view, annotations are simply something that can be written at given positions and have to follow a prescribed syntax. As shown in an example of the documentation, you can write something like
@v_annot4:{ annot0, annot1:’abc’, annot2:123 }
into the DDL source of a CDS view. The source is syntactically correct and can be activated. Of course, such an annotation has no meaning as long as nobody evaluates it. During activation of a DDL source, its annotations are saved in system tables and there are system classes available to evaluate them.
Some annotations are evaluated directly during activation and by the ABAP runtime environment.
Annotations before ABAP 7.50
Before ABAP 7.50, only a handful annotations played a role. Those were the annotations that are evaluated during activation and by the ABAP runtime environment. We call those annotations ABAP annotations. They are documented as part of the ABAP CDS documentation, as e.g. the ABAP view annotations. An important example is @ClientDependent, that defines the client handling when Open SQL is used to access a CDS entity. Other examples are the EndUserText annotations that denote translatable texts.
Annotations with ABAP 7.50
The usage of annotations is not restricted to the ABAP Dictionary’s own needs and the ABAP runtime environment (e.g.. Open SQL). As said above, you can enter for annotations what you want, as long as you stay within the syntax rules. Of course, there must be someone who evaluates it. And that’s what software components of SAP do with ABAP 7.50! Software components of SAP such as ODATA, UI, and Analytics prescribe sets of annotations that can be used to achieve a defined behavior and the frameworks themselves provide frameworks that evaluate these framework specific annotations and act accordingly. With other words, it’s not the ABAP runtime environment alone any more that evaluates DDL source codes! Accordingly the documentation of these annotations is not part of the ABAP CDS reference documentation (so don’t send your error messages there …) but delivered by the respective software components. There is a landing page where all SAP annotations are listed and where you find links to the detailed framework documentation.
As you see in the screen shot of Bjoern’s session above, he uses lots of framework specific annotations as @Search… , @UI…. While the syntax coloring and code completion of ADT recognizes them, the ABAP runtime environment (e.g. Open SQL) does not care at all. You have to work with the respective frameworks in order to see the effects! Of course Bjoern did exactly that.
Here is an example for a documentation that describes what you have to do in order to expose a CDS View as OData Service:
Exposing CDS View as OData Service
Have fun!
Note
Please note that SAP currently does not recommend to create customer annotations, At the moment you should work with SAP annotations (ABAP annotations and framework specific annotations) only.
PS: Sorry for the blurred screen shots, but they are taken from the TechEd video.
Good one.
From my point of view, annotations are just a textual representation of metadata. As you wrote it's up to a consumer to interpret this and since everybody (partners, customers) are able to specify their own (if I got you right), custom annotations in (stacked) CDS-views could in future be used as artifacts for customer specific frameworks. I like that idea.
Two questions however immediately pop into my mind:
Apart from these questions, I'm not happy at all with the set of SAP annotations and how they are being used in a common CDS-view. I blogged about that here. However, I did not get any response dealing with my concerns by someone who has more experience with that (some SAPian). Is there any volunteer around?
Cheers,
Oliver
That's why I have added
😏
A possible solution - and as far as I know, HANA CDS does that - would be to define the allowed annotations as transportable repository objects. There is already a spec for a definition syntax that could be used in DDL source codes for annotation definitions. Then only defined annotations could be used in CDS entities. In the annotation documentation you even see that syntax but, alas, it cannot be used in ABAP CDS currently. Then the ABAP runtime could even carry out basic checks for all annotations, not only the ABAP annotations ... (that's my personal view of the things).
I guess that for that, the same as above could help.
not I (remember, I'm only the ABAP language docu writer ...) ...
If custom annotations are not ... intended due to the limitations mentioned, you might want to revise
I like the idea with the transportable annotations. However, even then a detailed change notification would be useful.
Is the API which is called on activation published?
no, that's the situation.
No, that's DDIC-internal.
[quote] no, that's the situation. [/quote]
Expected that, therefore wrote "might". From a documentation point of view I'm fine with that. Guess you wanted to express that there's (currently) no checking of the annotation's value.
Really Good one..Most helpful.