版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/huanglin6/article/details/82627757
The following table shows the potential SQL functions for strings in a CDS view in ABAP CDS, plus the requirements made on the arguments… The meaning of the functions can be found under SQL Functions for Strings.

Function Valid Argument Types Result Type
CONCAT(arg1, arg2) See below SSTRING if an argument has the type SSTRING, else CHAR with the length of the result.
CONCAT_WITH_SPACE(arg1, arg2, spaces ) arg1, arg2: see below

spaces: positive numeric literal greater than 0 and less than or equal to 1331 SSTRING if an argument has the type SSTRING, else CHAR with the length of the result.
INSTR(arg, sub) arg: see below

sub: non-empty numeric literal INT4
LEFT(arg, len) arg: see below

len: positive numeric literal greater than 0 and less than or equal to 1333 SSTRING if arg has the type SSTRING, else CHAR with length len
LENGTH(arg) See below INT4
LPAD(arg, len, src) arg: see below

len: positive numeric literal greater than 0 and less than or equal to 1333

src: character Literal SSTRING if arg has the type SSTRING, else CHAR with length len
LTRIM(arg, char) arg: see below

char: Character literal with length 1 SSTRING if arg has the type SSTRING, else CHAR with the length of arg.
REPLACE(arg1, arg2, arg3) See below SSTRING if arg1 or arg3 has the type SSTRING, else CHAR with the maximum possible length of the result.
RIGHT(arg,len) arg: see below

len: positive numeric literal greater than 0 and less than or equal to 1333 SSTRING if arg has the type SSTRING, else CHAR with length len
RPAD(arg, len, src) arg: see below

len: positive numeric literal greater than 0 and less than or equal to 1333

src: character literal SSTRING if arg has the type SSTRING, else CHAR with length len
RTRIM(arg, char) arg: see below

char: Character literal with length 1 SSTRING if arg has the type SSTRING, else CHAR with the length of arg.
SUBSTRING(arg, pos, len) arg: see below

pos and len: positive numeric literal not equal to zero SSTRING, if arg has the type SSTRING, else CHAR or NUMC with a length of at least len
The following table shows the SQL functions for strings supported by ABAP CDS and Open SQL. The last two columns indicate where a function can be used.

SQL Function Result ABAP CDS Open SQL
CONCAT(arg1, arg2) Chaining of character strings in arg1 and arg2. Trailing blanks in arg1, arg2, and in the result are ignored. The maximum length of the result is 1333. x x
CONCAT_WITH_SPACE(arg1, arg2, spaces ) Concatenation of strings in arg1 and arg2 as with CONCAT. The number of blanks specified in spaces is inserted between arg1 and arg2. The maximum length of the result is 1333. x -
INSTR(arg, sub) Position of the first occurrence of the string from sub in arg (case-sensitive). arg respects leading blanks and ignores trailing blanks. sub respects all blanks. sub must contain at least one character. If no occurrences are found, the result is 0. x -
LEFT(arg, len) String of the length len with the len left characters of arg (ignoring the trailing blanks). The value of len cannot be greater than the length of arg. x -
LENGTH(arg) Number of characters in arg ignoring trailing blanks. x x
LPAD(arg, len, src) String of the length len with the right-justified content of arg without trailing blanks and in which leading blanks produced by the expanded string are replaced by the characters from the argument src (respecting all blanks). Trailing blanks from arg are preserved. If more characters are required than exist in src, the content of src is used repeatedly. If len is less than the length of arg, it is truncated on the right. If src is empty and len is greater than the length of arg, arg remains unchanged. x x
LTRIM(arg, char) String with the content of arg in which all trailing blanks are removed and all leading characters that match the character in char. A blank in char is significant. x x
REPLACE(arg1, arg2, arg3) Character string arg1, in which all instances of arg2 are replaced by the content from arg3. The replacement of letters is case-sensitive. Trailing blanks are ignored in all arguments. The maximum length of the result is 1333. x x
RIGHT( arg, len ) String of the length len with the len right characters of arg (ignoring the trailing blanks). The value of len cannot be greater than the length of arg. x x
RPAD(arg, len, src) String of the length len with the left-justified content of arg without trailing blanks and in which trailing blanks produced by the expanded string are replaced by the characters from the argument src (respecting all blanks). Trailing blanks from arg are preserved. If more characters are required than exist in src, the content of src is used repeatedly. If len is less than the length of arg, it is truncated on the right. If src is empty and len is greater than the length of arg, arg remains unchanged. x -
RTRIM(arg, char) String with the content of arg in which all trailing blanks are removed and all trailing characters that match the character in char. A blank in char is significant. x x
SUBSTRING(arg, pos, len) Substring of arg from the position pos in the length len. pos and len must be specified so that the substring is within in arg. x x
The following can be specified as the arguments arg:

Literals of a suitable type. The literal can be prefixed with the name of a domain.
Suitable fields of a data source data_source of the current CDS view.
Path expressions that identify a suitable field of a data source data_source.
Input parameters from the parameter list parameter_list.
The following predefined functions and expressions (if they return a matching type):
Other predefined SQL functions
Arithmetic expressions
Type modifications using CAST
The valid argument types for arg, arg1, arg2, and arg3 are CHAR, CLNT, LANG, NUMC, CUKY, UNIT, DATS, TIMS, and SSTRING.

In functions where an explicit length len is specified, the actual length of the result is defined when the CDS view is activated and is at least as long as len.

In all functions with the exception of LPAD and RPAD, the trailing blanks of all arguments are removed before the actual processing and the trailing blanks of the result are removed before the return operation. In LPAD and RPAD, the trailing blanks of the argument src are preserved.

Note

The characters in the surrogate area of the system code page UTF-16 are handled as two characters by the CDS string functions. This must be respected when the length is determined and these characters must not be split by mistake.

Example

The following CDS view applies predefined SQL functions for strings in the SELECT list to columns of the database table DEMO_EXPRESSIONS. The program DEMO_CDS_SQL_FUNCTIONS_STRING uses SELECT to access the view.

@AbapCatalog.sqlViewName: ‘DEMO_CDS_STRFUNC’ 
@AccessControl.authorizationCheck: #NOT_REQUIRED 
  define view demo_cds_sql_functions_string 
   as select from demo_expressions 
   { length(            char1               ) as r_length, 
     instr(             char1, ‘CD’         ) as r_instr, 
     concat(            char1, char2        ) as r_concat, 
     concat_with_space( char1, char2, 10    ) as r_concat_with_space, 
     left(              char1, 3            ) as r_left, 
     right(             char2, 3            ) as r_right, 
     lpad(              char1, 10, ‘x’      ) as r_lpad, 
     rpad(              char2, 10, ‘y’      ) as r_rpad, 
     ltrim(             char1, ‘A’          ) as r_ltrim, 
     rtrim(             char1, ‘E’          ) as r_rtrim, 
     replace(           char2, ‘GHI’, ‘XXX’ ) as r_replace, 
     substring(         char2, 2, 3         ) as r_substring }
————————————————
版权声明:本文为CSDN博主「SAP-Joker」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/huanglin6/article/details/82627757

【转载】ABAP CDS 函数相关推荐

  1. ABAP CDS注解详解

    注解 系统常量 $session.client $session.system_date $session.system_language $session.user SAP ABAP CDS vie ...

  2. CDS测试框架介绍:如何为ABAP CDS Entities写测试

    动机 现在大家都知道单元测试对我们代码的好处.并且我们都承认它是开发过程中不可或缺的一部分.但是在把代码切换到数据库的模式下的时候,我们被粗暴地打回了软件测试的黑暗年代...我们现在面临着逻辑下推到A ...

  3. 使用 Excel 读取 SAP ABAP CDS View 通过 ODBC 暴露出来的数据

    在阅读本文前,请务必先按照在 Excel 内使用 ODBC 消费 SAP ABAP CDS view 介绍的步骤,将 SAP BTP 平台 ABAP 环境下指定的 CDS view,通过 Open D ...

  4. 在 Excel 内使用 ODBC 消费 SAP ABAP CDS view

    Consuming CDS View Entities Using ODBC-Based Client Tools 本文介绍通过基于 ODBC(Open Database Connectivity) ...

  5. SAP ABAP CDS view和 HANA CDS view的区别,CDS consumption view 和 BO view 的区别

    这两种技术都是SAP提出的"Code pushdown"理念的具体实现.SAP ABAP CDS view位于ABAP应用服务器层,使用OPEN SQL,支持的数据库不限HANA, ...

  6. SAP ABAP CDS view里的注解在ABAP后台是如何被解析的?

    我们在ABAP Development Tool里编写SAP CDS view,为视图维护这些以@开头的注解,同Java Spring里广泛应用的annotation一样,都是一种为developme ...

  7. ABAP CDS View

    一.前言 核心数据服务(CDS)是用于定义和使用语义丰富(semantically-rich)的数据模型的一套架构,属于SAP HANA的一部分,但也可以在ABAP平台上使用,因此分为HANA CDS ...

  8. ABAP CDS(Core Data Service)的创建和使用

    1. 新建CDS EClipse创建一个ABAP CDS PROJECT 选择Data Definition 设置属性 2. 实现CDS 实现代码 3. CDS的使用 在ABAP中调用CDS查询 SE ...

  9. SAP ABAP CDS view Association 引入的缘由

    ABAP CDS view 支持三种 join 方式: Inner Join Left Outer join Right outer join 我们使用 ABAP Development Tool 的 ...

最新文章

  1. 大龄读博那几年,与君共勉
  2. 中的挂起是什么意思_数字博物馆是什么意思?数字博物馆用到了哪些技术?
  3. androidstudio build tools安装_如何导入Android Studio(AS)项目
  4. C++基础05-类构造函数与析构函数
  5. 作者:黎建辉(1973-),男,中国科学院计算机网络信息中心研究员、博士生导师...
  6. POJ3163 King of Fighters 状压DP/费用流
  7. 程序员编程艺术第二十六章:基于给定的文档生成倒排索引(含源码下载)
  8. php fpm listen.owner,nginx 与 php-fpm socket 所有者权限问题
  9. JS 替换字符串中指定字符
  10. 数据库课程设计:会议预约管理系统(Java+MySQL)
  11. Python Numpy random.zipf() Zipf分布
  12. Ember 从0到1
  13. 抓取整个网站图片的爬虫
  14. 茨威格为什么自杀(1942)?
  15. k8s 三种部署方式
  16. Carson带你学Android:源码解析自定义View Draw过程
  17. 矩阵相关操作和矩阵快速幂
  18. K3.BOS插件开发记录
  19. Swagger接口测试工具。
  20. python随机数产生100个整数(0-100),统计出现次数最多的数字.

热门文章

  1. 亚马逊风控规则,亚马逊测评如何避免风控
  2. js屏蔽手机的物理返回键
  3. Python中flask_sqlalchemy的使用
  4. Python解析页面国家码
  5. win10彻底卸载JDK
  6. DM数据库常用系统视图及数据字典查询部分汇总
  7. C++动态开辟数组空间
  8. 服务器系统安装蓝牙驱动,安装蓝牙设备 - Windows drivers | Microsoft Docs
  9. matplotlib隐藏坐标轴
  10. MacBook Pro(13 英寸,2011 年末)A1278 安装Winows11无声音问题解决(WIN10和WIN11同样的解决方法)