Cds View Entities 标志

Cds View Entities

社区
likweitan
cds-view-entities

协助开发 CDS(Core Data Services)视图实体,包括数据建模、注解、关联、组合、访问控制、聚合表达式、内置函数和输入参数。用户询问 CDS 视图、CDS 视图实体、CDS 注解、CDS 关联、CDS 组合、CDS 访问控制、CDS 元数据扩展、ABAP 数据建模、define view entity、define root view entity、语义注解、UI 注解,或如何为 RAP 或分析场景构建 CDS 数据模型时使用。触发请求包括“创建 CDS 视图”“定义视图实体”“添加关联”“CDS 注解”“访问控制”“组合”“CDS 层级结构”“CDS 聚合”“CDS 函数”或“数据模型”。

Add to TypingMind

概览

发布者likweitan
代码仓库abap-skills
技能名称cds-view-entities
星标数
64
复刻数
15
附带文件
1
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 1 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 likweitan 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Cds View Entities AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/likweitan/abap-skills/tree/main/skills/cds-view-entities
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/likweitan/abap-skills.git /tmp/abap-skills
mkdir -p .claude/skills
cp -r /tmp/abap-skills/skills/cds-view-entities .claude/skills/cds-view-entities
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Cds View Entities,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Cds View Entities。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Cds View Entities 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

CDS View Entities

Guide for building semantic data models using ABAP CDS (Core Data Services) view entities in ABAP Cloud.

Clean core context: selecting from a released SAP CDS view (I_*) is Level A. Direct read access to an SAP database table is Level C (ATC priority 2); direct write access is Level D (ATC priority 1). Where no released CDS view exists, build a wrapper CDS view on top of the non-released SAP view or table and release it for ABAP Cloud — the wrapper is Level B if the wrapped object is a classic API, otherwise Level C. Use CDS extends and CDS metadata extensions rather than modifying SAP CDS views. See the abap-cloud skill for level details.

Workflow

  1. Determine the user's goal:

    • Creating a new data model (standalone or for RAP)
    • Defining relationships between entities (associations, compositions)
    • Adding annotations for UI, semantics, or analytics
    • Implementing access controls
    • Using expressions, functions, or parameters in CDS
  2. Identify the context:

    • Standalone CDS view vs. RAP BO data model
    • Root entity vs. child entity vs. projection view
    • Transactional (RAP) vs. analytical vs. read-only consumption
  3. Apply best practices:

    • Use CDS view entities (v2 syntax define view entity) — not legacy CDS views (define view)
    • Follow naming conventions (e.g., ZR_* for interface/BO views, ZC_* for consumption/projection views, ZI_* for reuse views)
    • Add appropriate annotations for metadata consumers (UI, OData, analytics)

CDS View Entity Syntax

Basic View Entity

cds
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Sales Order'
define view entity ZI_SalesOrder
  as select from zsalesorder
{
  key order_id       as OrderId,
      customer_id    as CustomerId,
      order_date     as OrderDate,
      net_amount     as NetAmount,
      currency_code  as CurrencyCode,
      status         as Status,
      created_by     as CreatedBy,
      created_at     as CreatedAt,
      last_changed_at as LastChangedAt
}

Root View Entity (for RAP)

cds
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Sales Order Root'
define root view entity ZR_SalesOrder
  as select from zsalesorder
  composition [0..*] of ZR_SalesOrderItem as _Item
{
  key order_uuid         as OrderUUID,
      order_id           as OrderId,
      customer_id        as CustomerId,
      order_date         as OrderDate,
      @Semantics.amount.currencyCode: 'CurrencyCode'
      net_amount         as NetAmount,
      currency_code      as CurrencyCode,
      status             as Status,

      @Semantics.user.createdBy: true
      created_by         as CreatedBy,
      @Semantics.systemDateTime.createdAt: true
      created_at         as CreatedAt,
      @Semantics.user.localInstanceLastChangedBy: true
      last_changed_by    as LastChangedBy,
      @Semantics.systemDateTime.localInstanceLastChangedAt: true
      last_changed_at    as LastChangedAt,
      @Semantics.systemDateTime.lastChangedAt: true
      last_changed_at    as LastChangedAt,

      _Item
}

Child View Entity

cds
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Sales Order Item'
define view entity ZR_SalesOrderItem
  as select from zsalesorder_item
  association to parent ZR_SalesOrder as _Order
    on $projection.OrderUUID = _Order.OrderUUID
{
  key item_uuid       as ItemUUID,
      order_uuid      as OrderUUID,
      product_id      as ProductId,
      quantity         as Quantity,
      @Semantics.amount.currencyCode: 'CurrencyCode'
      unit_price       as UnitPrice,
      currency_code    as CurrencyCode,

      @Semantics.user.createdBy: true
      created_by       as CreatedBy,
      @Semantics.systemDateTime.localInstanceLastChangedAt: true
      last_changed_at  as LastChangedAt,

      _Order
}

Projection View (Consumption Layer)

cds
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Sales Order Projection'
@Metadata.allowExtensions: true
define view entity ZC_SalesOrder
  as projection on ZR_SalesOrder
{
  key OrderUUID,
      OrderId,
      CustomerId,
      OrderDate,
      NetAmount,
      CurrencyCode,
      Status,
      CreatedBy,
      CreatedAt,
      LastChangedBy,
      LastChangedAt,

      _Item : redirected to composition child ZC_SalesOrderItem
}

Associations & Compositions

Association Types

TypeSyntaxUse Case
Regular associationassociation [0..1] to ZI_Customer as _Customer on ...Independent entities (e.g., master data lookup)
Compositioncomposition [0..*] of ZR_Child as _ChildParent-child with lifecycle dependency (RAP BO trees)
To-parent associationassociation to parent ZR_Parent as _Parent on ...Child → parent back-reference in compositions

Association Syntax

cds
define view entity ZI_SalesOrder
  as select from zsalesorder
  association [0..1] to ZI_Customer as _Customer
    on $projection.CustomerId = _Customer.CustomerId
  association [0..*] to ZI_SalesOrderItem as _Item
    on $projection.OrderId = _Item.OrderId
{
  key order_id    as OrderId,
      customer_id as CustomerId,

      // Expose associations — required for consumption via ABAP SQL or OData
      _Customer,
      _Item
}

Using Associations in ABAP SQL

abap
" Path expression — triggers LEFT OUTER JOIN by default
SELECT FROM zi_salesorder
  FIELDS OrderId,
         \_Customer-CustomerName,
         \_Item-ProductId
  WHERE OrderId = @lv_order_id
  INTO TABLE @DATA(lt_result).

" Filtering associations
SELECT FROM zi_salesorder
  FIELDS OrderId, \_Item[ ProductId = 'PROD01' ]-Quantity
  WHERE OrderId = @lv_order_id
  INTO TABLE @DATA(lt_filtered).

Expressions & Built-in Functions

Cast Expressions

cds
cast( amount as abap.dec(15,2) ) as ConvertedAmount,
cast( status as abap.char(10) )  as StatusText,

Case Expressions

cds
// Simple CASE
case status
  when 'N' then 'New'
  when 'A' then 'Approved'
  when 'R' then 'Rejected'
  else 'Unknown'
end as StatusText,

// Searched CASE
case when net_amount > 10000 then 'High'
     when net_amount > 1000  then 'Medium'
     else 'Low'
end as PriorityCategory,

Arithmetic Expressions

cds
quantity * unit_price as TotalPrice,
net_amount + tax_amount as GrossAmount,

String Functions

cds
concat( first_name, concat( ' ', last_name ) ) as FullName,
substring( postal_code, 1, 2 )                 as Region,
length( description )                          as DescLength,
upper( country_code )                          as CountryUpper,

Date & Time Functions

cds
dats_days_between( start_date, end_date ) as DurationDays,
dats_add_days( order_date, 30 )           as DueDate,
tstmp_current_utctimestamp()              as CurrentTimestamp,

Aggregate Expressions

cds
define view entity ZI_OrderSummary
  as select from zsalesorder
{
  key customer_id as CustomerId,
      count(*)                      as OrderCount,
      sum( net_amount )             as TotalAmount,
      avg( net_amount as abap.dec(15,2) ) as AvgAmount,
      min( order_date )             as FirstOrderDate,
      max( order_date )             as LastOrderDate
}
group by customer_id

Input Parameters

cds
define view entity ZI_SalesOrderByDate
  with parameters
    p_date : abap.dats
  as select from zsalesorder
{
  key order_id   as OrderId,
      order_date as OrderDate,
      net_amount as NetAmount
}
where order_date >= $parameters.p_date

Using in ABAP SQL:

abap
SELECT FROM zi_salesorderbydate( p_date = @lv_date )
  FIELDS OrderId, OrderDate, NetAmount
  INTO TABLE @DATA(lt_orders).

Session Variables

cds
$session.user           as CurrentUser,
$session.client         as CurrentClient,
$session.system_date    as SystemDate,
$session.system_language as SystemLanguage,

Joins

cds
define view entity ZI_OrderWithCustomer
  as select from zsalesorder as so
  inner join zcustomer as cust
    on so.customer_id = cust.customer_id
{
  key so.order_id      as OrderId,
      cust.customer_name as CustomerName,
      so.net_amount     as NetAmount
}
Join TypeKeywordBehavior
Innerinner joinOnly matching rows
Left Outerleft outer joinAll from left + matching right
Right Outerright outer joinAll from right + matching left
Crosscross joinCartesian product

Note: Prefer associations over joins when possible — associations are lazily resolved and support path expressions.

Key Annotations

Semantics Annotations (for managed fields in RAP)

cds
@Semantics.user.createdBy: true
created_by as CreatedBy,

@Semantics.systemDateTime.createdAt: true
created_at as CreatedAt,

@Semantics.user.localInstanceLastChangedBy: true
last_changed_by as LastChangedBy,

@Semantics.systemDateTime.localInstanceLastChangedAt: true
local_last_changed_at as LocalLastChangedAt,

@Semantics.systemDateTime.lastChangedAt: true
last_changed_at as LastChangedAt,

Amount & Currency / Quantity & Unit

cds
@Semantics.amount.currencyCode: 'CurrencyCode'
net_amount as NetAmount,

currency_code as CurrencyCode,

@Semantics.quantity.unitOfMeasure: 'QuantityUnit'
quantity as Quantity,

quantity_unit as QuantityUnit,

UI Annotations (in CDS or Metadata Extensions)

cds
@UI.headerInfo: {
  typeName: 'Sales Order',
  typeNamePlural: 'Sales Orders',
  title: { type: #STANDARD, value: 'OrderId' }
}

@UI.lineItem: [{ position: 10 }]
@UI.identification: [{ position: 10 }]
@UI.selectionField: [{ position: 10 }]
order_id as OrderId,

Metadata Extensions (recommended for UI annotations)

cds
@Metadata.layer: #CUSTOMER
annotate view ZC_SalesOrder with
{
  @UI.facet: [{
    id: 'GeneralInfo',
    type: #IDENTIFICATION_REFERENCE,
    label: 'General Information',
    position: 10
  }]

  @UI.lineItem: [{ position: 10, importance: #HIGH }]
  @UI.identification: [{ position: 10 }]
  OrderId;

  @UI.lineItem: [{ position: 20 }]
  @UI.identification: [{ position: 20 }]
  @UI.selectionField: [{ position: 10 }]
  CustomerId;

  @UI.lineItem: [{ position: 30 }]
  @UI.identification: [{ position: 30 }]
  NetAmount;
}

CDS Access Control

cds
@EndUserText.label: 'Access Control for Sales Order'
@MappingRole: true
define role ZR_SalesOrder
{
  grant select on ZR_SalesOrder
  where ( CustomerId ) = aspect pfcg_auth ( Z_SO_AUTH, CUSTOMER_ID, ACTVT = '03' );
}

Access Control Patterns

PatternDescription
pfcg_authStandard authorization object check
inheritInherit restrictions from associated entity
aspect userRestrict by current user
true / falseUnrestricted / no access
cds
// Inherit from parent entity
define role ZR_SalesOrderItem {
  grant select on ZR_SalesOrderItem
  where inheriting conditions from entity ZR_SalesOrder
    association _Order;
}

// User-based restriction
define role ZR_MyOrders {
  grant select on ZR_SalesOrder
  where CreatedBy = aspect user;
}

CDS Table Entities

cds
define table entity ztab_salesorder {
  key client    : abap.clnt;
  key order_uuid: sysuuid_x16;
      order_id  : abap.numc(10);
      customer  : abap.char(10);
      amount    : abap.dec(15,2);
      currency  : abap.cuky(5);
}

CDS table entities can serve as alternatives to classic DDIC database tables and can be used as persistent table in RAP BDEFs.

Data Model Patterns for RAP

Typical Composition Tree

ZR_Root (define root view entity)
├── composition [0..*] of ZR_Child1 as _Child1
└── composition [0..*] of ZR_Child2 as _Child2
    └── composition [0..*] of ZR_GrandChild as _GrandChild

ZR_Child1 (association to parent ZR_Root as _Root)
ZR_Child2 (association to parent ZR_Root as _Root)
  └── composition [0..*] of ZR_GrandChild as _GrandChild
ZR_GrandChild (association to parent ZR_Child2 as _Parent)

Admin Field Pattern (Managed RAP BO)

Every entity in a managed RAP BO should include admin fields:

FieldTypeAnnotationPurpose
CreatedBysyuname@Semantics.user.createdBy: trueWho created
CreatedAtutclong@Semantics.systemDateTime.createdAt: trueWhen created
LastChangedBysyuname@Semantics.user.localInstanceLastChangedBy: trueWho last changed
LocalLastChangedAtutclong@Semantics.systemDateTime.localInstanceLastChangedAt: trueETag for optimistic concurrency
LastChangedAtutclong@Semantics.systemDateTime.lastChangedAt: trueTotal ETag for draft

Output Format

  • Provide complete CDS source code when creating new views
  • Include all relevant annotations
  • Follow naming conventions (ZR_* for interface, ZC_* for consumption, ZI_* for reuse)
  • Always expose associations used in consumption
  • Include access control definitions when security is relevant

References

Clean Core Level Notes for CDS

ScenarioLevelNotes
SELECT from a released SAP CDS view (I_*)ATarget state
Custom CDS view over your own tablesAAllowed within the same software component
SELECT from a classic (nominated) SAP CDS viewBAcceptable in classic ABAP development
Wrapper CDS view over a non-released SAP CDS viewB/CB if the wrapped view is a classic API, otherwise C
Direct read access to an SAP database tableCATC priority 2 — use a released CDS view or classic API
Direct write access to an SAP database tableDATC priority 1 — use released or classic APIs
CDS extend / metadata extension on an SAP CDS viewA/BPreferred over modification
Custom field via a released extension includeAPreferred technique
Custom field via a non-released extension includeBMonitor for a released include
Custom field via a classic appendCMonitor when an extension include becomes available

Wrapper CDS view guidance

  • If a suitable SAP CDS view exists but is not released, create a custom CDS view on top of it and release it for ABAP Cloud development
  • CDS views referenced by the SAP view (association targets, value help views) may need their own wrappers
  • If no suitable SAP CDS view exists at all, create the custom CDS view directly on the database table
  • Retire the wrapper once SAP releases an equivalent CDS view

CDS views are classified in the Cloudification Repository under object type STOB.

Related Skills

  • abap-sql-amdp: Use for advanced ABAP SQL queries and AMDP procedures
  • rap: Use for building RAP business objects based on CDS data models
  • authorization-iam: Use for implementing CDS access control (DCL)
  • odata: Use for exposing CDS views as OData services
  • abap-cloud: Use for clean core level classification and wrapper CDS view patterns
  • abap-cloud-migration: Use for replacing direct table access with released CDS views

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Cds View Entities AI 技能有什么作用?

协助开发 CDS(Core Data Services)视图实体,包括数据建模、注解、关联、组合、访问控制、聚合表达式、内置函数和输入参数。用户询问 CDS 视图、CDS 视图实体、CDS 注解、CDS 关联、CDS 组合、CDS 访问控制、CDS 元数据扩展、ABAP 数据建模、define view entity、define root view entity、语义注解、UI 注解,或如何为 RAP 或分析场景构建 CDS 数据模型时使用。触发请求包括“创建 CDS 视图”“定义视图实体”“添加关联”“CDS 注解”“访问控制”“组合”“CDS 层级结构”“CDS 聚合”“CDS 函数”或“数据模型”。

为什么在 TypingMind 中使用 Cds View Entities?

因为您只需安装一次,就能搭配任何模型使用。Cds View Entities 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Cds View Entities?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/likweitan/abap-skills/tree/main/skills/cds-view-entities。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Cds View Entities?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Cds View Entities 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Cds View Entities 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Cds View Entities AI 技能免费吗?

是的。likweitan 已在 GitHub 上根据 MIT 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇