Skip to content

ABAP Keyword Documentation →  ABAP Dictionary →  ABAP CDS in ABAP Dictionary →  ABAP CDS - Views →  ABAP CDS - DDL Statements →  ABAP CDS - DEFINE VIEW →  ABAP CDS - SELECT →  ABAP CDS - SELECT, Predefined Functions 

ABAP CDS - sql_functions

Other versions: 7.31 | 7.40 | 7.54


... func( arg1[, arg2]... ) ...


Calls predefined SQL functions in a SELECT statement of a CDS view in ABAP CDS. For passed arguments arg1, arg2, ..., a predefined SQL function returns a character-like or numeric result. The possible functions are:

Numeric Functions

Function Valid Argument Types Meaning Result Type
ABS(arg) INT1,INT2,INT4,DEC,CURR, QUAN, FLTP Absolute amount of arg Data type of arg
CEIL(arg) INT1,INT2,INT4,DEC,CURR, QUAN, FLTP Smallest integer number not less than the value of arg. INT4
DIV(arg1, arg2) INT1,INT2,INT4,DEC,CURR, QUAN without decimal places Integer part of the division of arg1 by arg2The sign is assigned after the amounts are divided; positive if the arguments have the same sign, and negative if the arguments have different signs. Exception: arg2 has the value 0. Data type arg1: hereDEC,CURR andQUAN are implemented after INT4.
DIVISION(arg1, arg2, dec) INT1,INT2,INT4,DEC, CURR, QUAN Division of arg1 by arg2 Das Ergebnis wird auf dec Nachkommastellen gerundet. dec muss ein positives ganzzahligesZahlenliteral inklusive 0 sein, das nicht größerals der Maximalwert von 6 und der Länge von arg2 plus die Anzahl der Nachkommastellen von arg1 plus 1 ist. DEC mit decNachkommastellen. Die Länge des Ergebnisses ist die Länge von arg1weniger die Nachkommastellen von arg1 plus die Nachkommastellen von arg2 plus dec. Dieser Wert darf nicht größer 31 sein.
FLOOR(arg) DEC,CURR, QUAN with decimal places Largest integer number not greater than the value of arg DEC without decimal places
MOD(arg1, arg2) INT1,INT2, INT4 Integer remainder of the division of arg1 by arg2 INT4
ROUND(arg, pos) INT1,INT2,INT4,DEC, CURR, QUAN Gerundeter Wert von arg. If pos is greaterthan 0, position pos is rounded to the right of the decimal separator.Ansonsten wird zur Position abs(pos)+1 links vom Dezimaltrennzeichen gerundet,wobei der Wert 0 entsteht, wenn nicht genügend Stellen vorhanden sind. pos muss ein Literal oder ein Feld einer Datenquelle vom TypINT1,INT2, INT4 sein. Data type arg: hereINT1 andINT2 are implemented after INT4.

String Functions

Function Valid Argument Types Meaning Result Type
CONCAT(arg1, arg2) CHAR,CLNT,LANG,NUMC,CUKY,UNIT,DATS,TIMS, SSTRING Chaining of character strings in arg1 and arg2. Trailing blanks are ignored. SSTRING, if an argument has the typeSSTRING, otherwise CHAR with the length of the result.
LPAD(arg, len, src) CHAR,CLNT,LANG,NUMC,CUKY,UNIT,DATS,TIMS, SSTRING String of the length len with the content of argin which leading blanks are replaced by the characters from the argument src.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. Wenn src leer und lengrößer als die Länge von arg ist, bleibt arg unverändert. len muss ein positivesZahlenliteral größer 0 und kleiner gleich 1333 sein. src muss ein Zeichenliteral sein. CHAR with length len
REPLACE(arg1, arg2, arg3) CHAR,CLNT,LANG,NUMC,CUKY,UNIT,DATS,TIMS, SSTRING Character string arg1, in which all instances of arg2are replaced by the content from arg3. The replacement of letters is case-sensitive. SSTRING, if arg1 or arg3 has the typeSSTRING, otherwise CHAR with the length of the result.
SUBSTRING(arg, pos, len) CHAR,CLNT,CUKY,DATS,LANG,NUMC, TIMS, UNIT Teilfeld von arg ab der Position posin der Länge len. pos und len müssen positiveZahlenliterale ungleich Null sein. CHAR or NUMC with a length of at least len

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.

The following can be specified as the arguments arg:

  • Suitable fields of a data source data_source of the current CDS view.

If an argument contains the null value, the result is always the null value. If the value range of a result type is overwritten, an exception is raised.


Die folgende CDS-View wendet eingebaute SQL-Funktionen in der SELECT-Liste auf Spalten der Datenbanktabelle DEMO_EXPRESSIONS an. Das Programm DEMO_CDS_SQL_FUNCTIONS greift mit SELECT auf die View zu.

@AbapCatalog.sqlViewName: 'DEMO_CDS_SQLFUNC'
  define view demo_cds_sql_functions
   as select from demo_expressions
   { abs(       num1                ) as abs_num1,
     ceil(      fltp1               ) as ceil_fltp1,
     floor(     dec1                ) as floor_dec1,
     div(       num1, num2          ) as div_num1_num2,
     mod(       num1, num2          ) as mod_num1_num2,
     division(  dec2, dec3, 3       ) as dvision_dec2_dec3,
     round(     dec3, 2             ) as round_dec3,
     concat(    char1, char2        ) as concat_char1_char2,
     lpad(      char1, 10, 'x'      ) as lpad_char1,
     replace(   char2, 'GHI', 'XXX' ) as replace_char2,
     substring( char2, 2, 3         ) as substring_char2 }