Syntax

... annotation[.annotation1[.annotation2]][:value]  ...

Effect

Annotation that can be specified at predefined positions within a CDS source code, to enhance a definition of the ABAP CDS with meta data. An annotation consists of a single or multiple-part name and an optional specified value.

Names

An annotation has a single-part name

... annotation ...

or a multiple-part name

... annotation.annotation1.annotation2...,

in which single names are separated by a period . (full stop). The individual names annotation, annotation1, annotation2, ... can contain letters, digits, and underscores and must start with a letter. The name of an annotation must be unique in the context of the annotation.

  • A set of predefined annotations with predefined names is available; these can be specified for specific contexts of a definition, expect specific values, and can be analyzed by the runtime environment. These annotations are documented for the respective context.
  • All other names define self-defined annotations, to which any value can be assigned and which must be analyzed by the application itself.

Specified Value

A value value can be specified after a colon :. However, an annotation does not have to contain a value. The following can be specified for value:

  • Literals
Character literals or numeric literals embedded in inverted commas
  • Truth values true and false
These values can be embedded in inverted commas optionally.
  • Enumeration values #value
Specific predefined annotations expect preset values; these are specified directly and without inverted commas after the # character.
  • Value lists [ value1, value2, ...]
Comma-separated lists of values can be specified in square brackets; for such values, the same applies as for value. This is used for structuring an annotation, by assigning different values to it. Direct nesting of square brackets is syntactically possible; however, this is currently ignored during the analysis of the annotations.
  • Annotation lists { annotation1[:value1], annotation2[:value2], ...}
Curly brackets can be used to specify comma-separated lists of annotations. The internal annotations have the same syntax as the external annotation. Specifying an annotation list after an annotation produces a nested annotation and has the same effect as specifying individual names as follows:
annotation.annotation1[:value1]
annotation.annotation2[:value2]
...

Evaluation

The evaluation of annotations differs between predefined and self-defined annotations:

  • Predefined annotations with predefined names specify the technical and semantic properties of CDS objects that are analyzed by the runtime environment.
  • Self-defined annotations with self-defined names must be analyzed by the application itself using a suitable API. Currently, no global API for analyzing self-defined annotations is supplied. Instead, a direct access to the database tables containing the meta data is possible.

Contexts for Annotations

Annotations can be specified for the following contexts.

  • DDL:
  • DCL:

The predefined annotations that are possible for a context are documented here.

Example

The following CDS source code for defining a CDS view contains predefined and self-defined annotations at the allowed positions, that is for the entire view and for an element of the SELECT list. The predefined annotations include AbapCatalog.sqlViewName and ClientDependent for the entire view, and EndUserText.label and EndUserText.quickInfo for the element of the SELECT list. The remaining annotations are self-defined.

@AbapCatalog.sqlViewName: 'DEMO_VIEW_ANNOT'
@ClientDependent: false

@v_annot0
@v_annot1:'abc'
@v_annot2:123
@v_annot3:[ 'abc', 123 ]
@v_annot4:{ annot0, annot1:'abc', annot2:123 }
@v_annot5.annot0
@v_annot5.annot1:'abc'
@v_annot5.annot2:123
@v_annot6:[ 'abc', 123,
            [ 'abc', 123 ],
            { annot0, annot1:'abc', annot2:123 } ]
@v_annot7:{ annot0,
            annot1:[ 'abc', 123 ],
            annot2:{ annot0, annot1:'abc', annot2:123 } }

define view demo_cds_view_annotations
  as select from demo_expressions
    { @f_annot0
      key id as key_field
      @<f_annot1:'abc'
      @<f_annot2:123,    
      @EndUserText:{ label:'Some field', quickInfo:'Some info' }
      @f_annot1:[ 'abc', 123 ]
      num1 as some_field
      @<f_annot2:{ annot0, annot1:'abc', annot2:123 }
    }

The program DEMO_CDS_DDL_ANNOTATIONS accesses the corresponding meta data in database tables DDHEADANNO and DDFIELDANNO and displays these. It should be noted that the notations for v_annot4 and v_annot5 are the same, and that the nested square bracket in the annotation v_annot6 is ignored. Compared with the table for the entire view, the table for the SELECT list additionally contains the name of the element for which an annotation was created.

ABAP CDS - Annotations 注解的更多相关文章

  1. HANA CDS与ABAP CDS

    如果你在网络或者SCN上面搜索CDS,即SAP的Core Data Services,你会很容易地找到类似“Core Data Services(CDS)是一个在SAP HANA中用于定义和消费富语义 ...

  2. 教程:基于访问控制的ABAP CDS视图权限

    Hi! 对每一个CDS视图,我们都可以通过DCL(Data Control Language)定义访问控制.在这篇文章中,我会介绍ABAP CDS视图中非常重要的一面:权限管理. 本文的阐述基于我正在 ...

  3. ABAP CDS Table Function介绍与示例

    Core data services(以下简称CDS)可以指两样东西,一个是HANA CDS,一个是ABAP CDS. 如我们所知,HANA CDS只支持HANA数据库,ABAP CDS理论上支持多种 ...

  4. Create Fiori List App Report with ABAP CDS view – PART 2

    In the Part 1 blog, we have discussed below topics CDS annotations for Fiori List Report. How to cre ...

  5. Create Fiori List App Report with ABAP CDS view – PART 1

    From Create Fiori List App Report with ABAP CDS view – PART 1 In this blog, I am going to show How C ...

  6. ABAP CDS - Syntax

    The syntax of the DDL and of the DCL of the ABAP CDS comprises elements of the general DDL and DCL o ...

  7. ABAP CDS - DEFINE VIEW, view_annot

    Syntax ... @annotation ... Effect Specifies Annotation annotation in the definition of a CDS view of ...

  8. ABAP CDS - Language Elements

    The following sections summarize the language elements of the DDL and DCL of the ABAP CDS, arranged ...

  9. Android注解使用之使用Support Annotations注解优化代码

    前言: 前面学习总结了Java注解的使用,博客地址详见Java学习之注解Annotation实现原理,从本质上了解到什么注解,以及注解怎么使用?不要看见使用注解就想到反射会影响性能之类,今天我们就来学 ...

随机推荐

  1. FFMPEG第一次学习

    习惯用OneNote笔记,直接复制了,链接和一些命令放在最下面了 里面的库文件是我下的雷神的课件文件,我传到了自己github,链接也放最后了 转载自:https://blog.csdn.net/le ...

  2. APL 和 Web APL 的概述

    APL APl ( Application ProgrammingInterface,应用程序编程接口) 是一些预先定义的函数,目的是提供应用程序 与开发人员基于某软件或硬件得以访问一组例程的能力,而 ...

  3. 原生实现C#和Lua相互调用-Unity3D可用

    引言     本篇简单介绍如何在C#中执行Lua脚本,传递数据到Lua中使用,以及Lua中调用C#导出的方法等.在Unity中开发测试,并打IL2CPP的Android包在模拟器上运行通过.Lua版本 ...

  4. 观察者模式与Google Guava EventBus实现

    概述 观察者模式又被称为发布-订阅(Publish/Subscribe)模式,属于行为型模式的一种. 它定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个主题对象.这个主题对象在状态变化时,会 ...

  5. Flatbuffers学习

    flatbuffers简介 FlatBuffers 是一个(二进制 buffer)序列化开源库,由 Google 开源现在它支持C++, C#, C, Go, Java, Kotlin, JavaSc ...

  6. 为什么Redis要比Memcached更火?

    关注「开源Linux」,选择"设为星标" 回复「学习」,有我为您特别筛选的学习资料~ 前言 我们都知道,Redis和Memcached都是内存数据库,它们的访问速度非常之快.但我们 ...

  7. JavaScript 数据结构与算法1(数组与栈)

    学习数据结构的 git 代码地址: https://gitee.com/zhangning187/js-data-structure-study 1.数组 几乎所有的语言都原生支持数组类型,因为数组是 ...

  8. SpringBoot从0到0.7——序言

    SpringBoot从0到0.7-- 序言 最近做java代码审计发现很多地方看不懂,所以就开始学框架,自己做网站来了解网站的运行原理.函数.接口.参数等等,通过学习SpringBoot框架来从点到面 ...

  9. 这 BUG,绝了

    上周只上了三天班,但我也丝毫不敢懈怠,BUG 更是一个也没少写. 看着满屏幕的 ERROR,我陷入沉思.为什么我写的代如此烂,无法像大牛们写的那般优雅? 越想越自卑,越想越抑郁.我觉得这样不行,一定得 ...

  10. 如何形象简单地理解java中只有值传递,而没有引用传递?

    首先,java中只有值传递,没有引用传递.可以说是"传递的引用(地址)",而不能说是"按引用传递". 按值传递意味着当将一个参数传递给一个函数时,函数接收的是原 ...