很多同学对于CDS view感觉无从下手,本篇博客将介绍CDS View的基础语法,并附有示例。
用途:
创建一个CDS View
语法:
@AbapCatalog.sqlViewName: 'ZDEMO_CDS_SQL'
define view ZDEMO_CDS_DDL
as select from sbook
{
carrid,
connid
}
解释:
运行效果:
用途:
如果结果集中有重复的条目,DISTINCt可排除结果集中的重复条目。
语法:
@AbapCatalog.sqlViewName: 'ZDEMO_CDS_SQL'
define view ZDEMO_CDS_DDL
as select distinct from sbook
{
carrid,
connid
}
解释:
运行效果:
用途:
限定筛选条件
语法:
@AbapCatalog.sqlViewName: 'ZDEMO_CDS_SQL'
define view ZDEMO_CDS_DDL
as select from sbook
{
carrid,
connid
}
where carrid = 'AA'
运行效果:
用途:
指定CDS View中哪些字段是Key字段
语法:
@AbapCatalog.sqlViewName: 'ZDEMO_CDS_SQL'
@AbapCatalog.preserveKey: true
define view ZDEMO_CDS_DDL
as select from sbook
{
key carrid,
key connid,
fldate,
bookid,
customid,
custtype
}
解释:
运行效果:
用途:
CDS中自带的一些运算函数
语法:
@AbapCatalog.sqlViewName: 'ZDEMO_CDS_SQL'
@AbapCatalog.preserveKey: true
define view ZDEMO_CDS_DDL
as select from sbook
{
key carrid,
key connid,
concat( carrid, connid ) as flightno,
order_date,
concat( concat (substring(order_date,5,2),'-'),
substring(order_date,1,4) ) as ordermonth
}
解释:
运行效果:
用途:
实现分支运算
语法:
@AbapCatalog.sqlViewName: 'ZDEMO_CDS_SQL'
@AbapCatalog.preserveKey: true
define view ZDEMO_CDS_DDL
as select from sbook
{
key carrid,
key connid,
case carrid
when 'AA' then 'American Airlines'
when 'AB' then 'Air Berlin'
when 'UA' then 'United Airlines'
else 'Other Airlines'
end as airline_name,
class,
case
when class = 'F' then 'First Class'
when class = 'Y' then 'Business Class'
else 'others'
end as class_level
}
解释:
运行效果:
用途:
强制类型转换
语法:
@AbapCatalog.sqlViewName: 'ZDEMO_CDS_SQL'
@AbapCatalog.preserveKey: true
define view ZDEMO_CDS_DDL
as select from sbook
{
key carrid,
key connid,
forcurkey,
forcuram as origin_amount,
case smoker
when 'X' then cast ( forcuram as abap.fltp ) * 1.3
else cast ( forcuram as abap.fltp ) * 0.9
end as final_amount
}
解释:
运行效果:
用途:
常用用户处理NULL的状况,为NULL语设定默认值
语法:
@AbapCatalog.sqlViewName: 'ZDEMO_CDS_SQL'
@AbapCatalog.preserveKey: true
define view ZDEMO_CDS_DDL
as select from sbook
{
key carrid,
key connid,
coalesce( smoker, 'unassigned') as somker_status
}
解释:
在本文中,我们介绍了SAP CDS View的最基本的运算语法,有关运算过程中遇到的问题,可以进一步根据ABAP 中的帮助文档,查看相关的用法。
原文链接:https://blog.csdn.net/nkGavinGuo/article/details/105855961?utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2aggregatepagefirst_rank_v2~rank_aggregation-1-105855961.pc_agg_rank_aggregation&utm_term=cds+view&spm=1000.2123.3001.4430