ABAP CDS - 字符串函數


下表顯示了ABAP CDS中CDS視圖中字符串的潛在SQL函數,以及對參數的要求。函數的含義可以在字符串的SQL函數下找到。

 

函數 參數類型 返回類型
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

 

以下可以指定為參數:

  • suitable類型的文字。文本可以以域名作為前綴。
  • 當前CDS視圖的數據源數據源的適當字段。
  • 用於標識數據源數據源的適當字段的路徑表達式。
  • 以下預定義的函數和表達式(如果它們返回匹配的類型):
  • 其他預定義的SQL函數
  • 算術表達式
  • Type modifications using CAST

arg、arg1、arg2和arg3的有效參數類型為char、clnt、lang、numc、cuky、unit、dats、tims和sstring。

在指定了顯式長度len的函數中,當CDS視圖被激活時,結果的實際長度被定義為至少和len一樣長。

在除lpad和rpad之外的所有函數中,所有參數的尾隨空格在實際處理之前被刪除,結果的尾隨空格在返回操作之前被刪除。在lpad和rpad中,參數src的尾隨空格被保留。

注釋

系統代碼頁utf-16的代理區域中的字符由cds字符串函數作為兩個字符處理。在確定長度時必須遵守這一點,並且這些字符不能被錯誤地拆分。

例子

以下CDS視圖將選擇列表中字符串的預定義SQL函數應用於數據庫表demo_表達式的列。程序演示光盤的SQL函數字符串使用select訪問視圖。

@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 }

 

SQL函數的字符串

下表顯示了abap cds和open sql支持的字符串的SQL函數。最后兩列指示函數的使用位置。

SQL 函數 結果 ABAP CDS Open SQL
CONCAT(arg1, arg2) Chaining of character strings in arg1 and arg2. Trailing blanks in arg1arg2, 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 argarg 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 argarg 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 lenpos and len must be specified so that the substring is within in arg.

關於潛在操作數和數據類型的描述可以在ABAPCDS和OpenSQL的相應文檔中找到。

 

參考文章

   ABAP CDS - String Functions

   SQL Functions for Strings

本文原始地址:https://www.cnblogs.com/yjyongil/p/10495142.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM